summaryrefslogtreecommitdiffstats
path: root/botan/wrappers/boost-python/src/stream.cpp
diff options
context:
space:
mode:
authorKeith Isdale <keith.isdale@nokia.com>2010-07-26 14:56:53 +1000
committerKeith Isdale <keith.isdale@nokia.com>2010-07-26 14:56:53 +1000
commit9f034793bcfc51c2b7c1dd14db806f7258f9a9eb (patch)
tree63bd0f50ce5b77828ad8205eafd7b9412810499e /botan/wrappers/boost-python/src/stream.cpp
parent619d92cfef29e653bfdf852e83888e50cfc4348f (diff)
parent65271649dbc90f3af1184ad1b23bdb64c0c07d07 (diff)
Merge branch 'master' of git://git-nokia.trolltech.com.au/qtsoftware/research/qtuitest
Diffstat (limited to 'botan/wrappers/boost-python/src/stream.cpp')
-rw-r--r--botan/wrappers/boost-python/src/stream.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/botan/wrappers/boost-python/src/stream.cpp b/botan/wrappers/boost-python/src/stream.cpp
new file mode 100644
index 0000000..f94bd7f
--- /dev/null
+++ b/botan/wrappers/boost-python/src/stream.cpp
@@ -0,0 +1,54 @@
+/*************************************************
+* Boost.Python module definition *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/botan.h>
+using namespace Botan;
+
+#include "python_botan.h"
+
+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);
+ }