From 997e6c97b8ace857d00f9fd57f621ba9323c75df Mon Sep 17 00:00:00 2001 From: lloyd Date: Fri, 9 Oct 2009 18:06:06 +0000 Subject: Add more or less functional integration with Boost.Python. Use --use-boost-python to enable creating a second makefile, Makefile.python, which has targets for building and installing the Python module. --- src/wrap/python/python_botan.h | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/wrap/python/python_botan.h (limited to 'src/wrap/python/python_botan.h') diff --git a/src/wrap/python/python_botan.h b/src/wrap/python/python_botan.h new file mode 100644 index 000000000..18c51dbb1 --- /dev/null +++ b/src/wrap/python/python_botan.h @@ -0,0 +1,51 @@ + +#ifndef BOTAN_BOOST_PYTHON_COMMON_H__ +#define BOTAN_BOOST_PYTHON_COMMON_H__ + +#include +#include +#include +using namespace Botan; + +#include +namespace python = boost::python; + +extern void export_filters(); +extern void export_pk(); +extern void export_x509(); + +class Bad_Size : public Exception + { + public: + Bad_Size(u32bit got, u32bit expected) : + Exception("Bad size detected in Python/C++ conversion layer: got " + + to_string(got) + " bytes, expected " + to_string(expected)) + {} + }; + +inline std::string make_string(const byte input[], u32bit length) + { + return std::string((const char*)input, length); + } + +inline std::string make_string(const MemoryRegion& in) + { + return make_string(in.begin(), in.size()); + } + +inline void string2binary(const std::string& from, byte to[], u32bit expected) + { + if(from.size() != expected) + throw Bad_Size(from.size(), expected); + std::memcpy(to, from.data(), expected); + } + +template +inline python::object get_owner(T* me) + { + return python::object( + python::handle<>( + python::borrowed(python::detail::wrapper_base_::get_owner(*me)))); + } + +#endif -- cgit v1.2.3