diff options
author | lloyd <[email protected]> | 2009-10-09 18:48:11 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2009-10-09 18:48:11 +0000 |
commit | ebfa4f1f5d07857b1c000f36c8f8cea0984db121 (patch) | |
tree | c390ac5204d1e1238ede6c2d6e5437e6a0992fb0 /src | |
parent | 43d6a9673f7bbf962ef6075e4268caa44f03a798 (diff) |
Fix python install target. Add CryptoBox wrapper plus an example
Diffstat (limited to 'src')
-rw-r--r-- | src/build-data/makefile/python.in | 2 | ||||
-rw-r--r-- | src/wrap/python/core.cpp | 24 |
2 files changed, 25 insertions, 1 deletions
diff --git a/src/build-data/makefile/python.in b/src/build-data/makefile/python.in index ee95f8d78..9658c70ce 100644 --- a/src/build-data/makefile/python.in +++ b/src/build-data/makefile/python.in @@ -2,7 +2,7 @@ CXX = g++ PYTHON_ROOT = /usr/lib/python%{python_version}/config PYTHON_INC = -I/usr/include/python%{python_version} -PYTHON_SITE_PACKAGE_DIR = /tmp/usr/lib/python%{python_version}/site-packages/ +PYTHON_SITE_PACKAGE_DIR = /usr/lib/python%{python_version}/site-packages/ PYTHON_FLAGS = -Isrc/wrap/python -Os -fPIC -ftemplate-depth-255 -Wall -Wno-unused $(PYTHON_INC) 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(); |