aboutsummaryrefslogtreecommitdiffstats
path: root/wrappers/boost-python/src/core.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'wrappers/boost-python/src/core.cpp')
-rw-r--r--wrappers/boost-python/src/core.cpp44
1 files changed, 37 insertions, 7 deletions
diff --git a/wrappers/boost-python/src/core.cpp b/wrappers/boost-python/src/core.cpp
index 3bca5330f..7ef2a9970 100644
--- a/wrappers/boost-python/src/core.cpp
+++ b/wrappers/boost-python/src/core.cpp
@@ -9,19 +9,49 @@ using namespace Botan;
#include <boost/python.hpp>
namespace python = boost::python;
-extern void export_block_ciphers();
-extern void export_stream_ciphers();
-extern void export_hash_functions();
-extern void export_macs();
-extern void export_filters();
-extern void export_pk();
-extern void export_x509();
+#include "python_botan.h"
+
+class Python_RandomNumberGenerator
+ {
+ public:
+ Python_RandomNumberGenerator()
+ { rng = RandomNumberGenerator::make_rng(); }
+ ~Python_RandomNumberGenerator() { delete rng; }
+
+ std::string name() const { return rng->name(); }
+
+ void reseed() { rng->reseed(); }
+
+ int gen_random_byte() { return rng->next_byte(); }
+
+ std::string gen_random(int n)
+ {
+ std::string s(n, 0);
+ rng->randomize(reinterpret_cast<byte*>(&s[0]), n);
+ return s;
+ }
+
+ void add_entropy(const std::string& in)
+ { rng->add_entropy(reinterpret_cast<const byte*>(in.c_str()), in.length()); }
+
+ private:
+ RandomNumberGenerator* rng;
+ };
BOOST_PYTHON_MODULE(_botan)
{
python::class_<LibraryInitializer>("LibraryInitializer")
.def(python::init< python::optional<std::string> >());
+ python::class_<Python_RandomNumberGenerator>("RandomNumberGenerator")
+ .def(python::init<>())
+ .def("__str__", &Python_RandomNumberGenerator::name)
+ .def("name", &Python_RandomNumberGenerator::name)
+ .def("reseed", &Python_RandomNumberGenerator::reseed)
+ .def("add_entropy", &Python_RandomNumberGenerator::add_entropy)
+ .def("gen_random_byte", &Python_RandomNumberGenerator::gen_random_byte)
+ .def("gen_random", &Python_RandomNumberGenerator::gen_random);
+
python::class_<OctetString>("OctetString")
.def(python::init< python::optional<std::string> >())
//.def(python::init< u32bit >())