diff options
author | lloyd <[email protected]> | 2006-08-31 18:12:39 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2006-08-31 18:12:39 +0000 |
commit | 928d989fd9823ccfac6ef83dc1abe668f38fa42d (patch) | |
tree | c820196107914411cc851cbcf8da593b0d1bf766 /misc | |
parent | a9f2e06a1e1ed20d36e80db5a31c7ba366db8308 (diff) |
Export stream ciphers
Diffstat (limited to 'misc')
-rw-r--r-- | misc/python/src/core.cpp | 2 | ||||
-rw-r--r-- | misc/python/src/stream.cpp | 55 |
2 files changed, 57 insertions, 0 deletions
diff --git a/misc/python/src/core.cpp b/misc/python/src/core.cpp index 3ede4f51c..0f30f470e 100644 --- a/misc/python/src/core.cpp +++ b/misc/python/src/core.cpp @@ -10,6 +10,7 @@ using namespace Botan; 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(); @@ -32,6 +33,7 @@ BOOST_PYTHON_MODULE(_botan) .value("decryption", DECRYPTION); export_block_ciphers(); + export_stream_ciphers(); export_hash_functions(); export_macs(); export_filters(); diff --git a/misc/python/src/stream.cpp b/misc/python/src/stream.cpp new file mode 100644 index 000000000..35e9e7c13 --- /dev/null +++ b/misc/python/src/stream.cpp @@ -0,0 +1,55 @@ +/************************************************* +* Boost.Python module definition * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#include <botan/botan.h> +using namespace Botan; + +#include <boost/python.hpp> +namespace python = boost::python; + +class Py_StreamCipher + { + public: + u32bit keylength_min() const { return cipher->MINIMUM_KEYLENGTH; } + u32bit keylength_max() const { return cipher->MAXIMUM_KEYLENGTH; } + u32bit keylength_mod() const { return cipher->KEYLENGTH_MULTIPLE; } + + void set_key(const OctetString& key) { cipher->set_key(key); } + bool valid_keylength(u32bit kl) const + { + return cipher->valid_keylength(kl); + } + + std::string name() const { return cipher->name(); } + void clear() throw() { cipher->clear(); } + + std::string crypt(const std::string& in) const + { + SecureVector<byte> out(in.size()); + cipher->encrypt((const byte*)in.data(), out.begin(), in.size()); + return std::string((const char*)out.begin(), out.size()); + } + + Py_StreamCipher(const std::string& name) + { + cipher = get_stream_cipher(name); + } + ~Py_StreamCipher() { delete cipher; } + private: + StreamCipher* cipher; + }; + +void export_stream_ciphers() + { + python::class_<Py_StreamCipher>("StreamCipher", python::init<std::string>()) + .add_property("keylength_min", &Py_StreamCipher::keylength_min) + .add_property("keylength_max", &Py_StreamCipher::keylength_max) + .add_property("keylength_mod", &Py_StreamCipher::keylength_mod) + .add_property("name", &Py_StreamCipher::name) + .def("clear", &Py_StreamCipher::clear) + .def("valid_keylength", &Py_StreamCipher::valid_keylength) + .def("set_key", &Py_StreamCipher::set_key) + .def("crypt", &Py_StreamCipher::crypt); + } |