aboutsummaryrefslogtreecommitdiffstats
path: root/src/wrap/python/core.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-10-09 18:48:11 +0000
committerlloyd <[email protected]>2009-10-09 18:48:11 +0000
commitebfa4f1f5d07857b1c000f36c8f8cea0984db121 (patch)
treec390ac5204d1e1238ede6c2d6e5437e6a0992fb0 /src/wrap/python/core.cpp
parent43d6a9673f7bbf962ef6075e4268caa44f03a798 (diff)
Fix python install target. Add CryptoBox wrapper plus an example
Diffstat (limited to 'src/wrap/python/core.cpp')
-rw-r--r--src/wrap/python/core.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/wrap/python/core.cpp b/src/wrap/python/core.cpp
index 1992e3d61..59df863de 100644
--- a/src/wrap/python/core.cpp
+++ b/src/wrap/python/core.cpp
@@ -6,6 +6,7 @@
#include <botan/init.h>
#include <botan/pipe.h>
#include <botan/lookup.h>
+#include <botan/cryptobox.h>
using namespace Botan;
#include "python_botan.h"
@@ -33,6 +34,7 @@ class Python_RandomNumberGenerator
void add_entropy(const std::string& in)
{ rng->add_entropy(reinterpret_cast<const byte*>(in.c_str()), in.length()); }
+ RandomNumberGenerator& get_underlying_rng() { return *rng; }
private:
RandomNumberGenerator* rng;
};
@@ -163,6 +165,25 @@ class Py_MAC
MessageAuthenticationCode* mac;
};
+std::string cryptobox_encrypt(const std::string& in,
+ const std::string& passphrase,
+ Python_RandomNumberGenerator& rng)
+ {
+ const byte* in_bytes = reinterpret_cast<const byte*>(in.data());
+
+ return CryptoBox::encrypt(in_bytes, in.size(),
+ passphrase, rng.get_underlying_rng());
+ }
+
+std::string cryptobox_decrypt(const std::string& in,
+ const std::string& passphrase)
+ {
+ const byte* in_bytes = reinterpret_cast<const byte*>(in.data());
+
+ return CryptoBox::decrypt(in_bytes, in.size(),
+ passphrase);
+ }
+
BOOST_PYTHON_MODULE(_botan)
{
python::class_<LibraryInitializer>("LibraryInitializer")
@@ -197,6 +218,9 @@ BOOST_PYTHON_MODULE(_botan)
.def("name", &Py_MAC::name)
.def("output_length", &Py_MAC::output_length);
+ python::def("cryptobox_encrypt", cryptobox_encrypt);
+ python::def("cryptobox_decrypt", cryptobox_decrypt);
+
export_filters();
export_pk();
export_x509();