aboutsummaryrefslogtreecommitdiffstats
path: root/misc/python
diff options
context:
space:
mode:
Diffstat (limited to 'misc/python')
-rw-r--r--misc/python/src/core.cpp4
-rw-r--r--misc/python/src/hash.cpp44
-rw-r--r--misc/python/src/mac.cpp59
3 files changed, 107 insertions, 0 deletions
diff --git a/misc/python/src/core.cpp b/misc/python/src/core.cpp
index 5669a5b83..3ede4f51c 100644
--- a/misc/python/src/core.cpp
+++ b/misc/python/src/core.cpp
@@ -10,6 +10,8 @@ using namespace Botan;
namespace python = boost::python;
extern void export_block_ciphers();
+extern void export_hash_functions();
+extern void export_macs();
extern void export_filters();
extern void export_pk();
extern void export_x509();
@@ -30,6 +32,8 @@ BOOST_PYTHON_MODULE(_botan)
.value("decryption", DECRYPTION);
export_block_ciphers();
+ export_hash_functions();
+ export_macs();
export_filters();
export_pk();
export_x509();
diff --git a/misc/python/src/hash.cpp b/misc/python/src/hash.cpp
new file mode 100644
index 000000000..3e1afd79c
--- /dev/null
+++ b/misc/python/src/hash.cpp
@@ -0,0 +1,44 @@
+/*************************************************
+* 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_HashFunction
+ {
+ public:
+ u32bit output_length() const { return hash->OUTPUT_LENGTH; }
+ std::string name() const { return hash->name(); }
+ void clear() throw() { hash->clear(); }
+
+ void update(const std::string& in) { hash->update(in); }
+
+ std::string final()
+ {
+ SecureVector<byte> result = hash->final();
+ return std::string((const char*)result.begin(), result.size());
+ }
+
+ Py_HashFunction(const std::string& name)
+ {
+ hash = get_hash(name);
+ }
+ ~Py_HashFunction() { delete hash; }
+ private:
+ HashFunction* hash;
+ };
+
+void export_hash_functions()
+ {
+ python::class_<Py_HashFunction>("HashFunction", python::init<std::string>())
+ .add_property("output_length", &Py_HashFunction::output_length)
+ .add_property("name", &Py_HashFunction::name)
+ .def("clear", &Py_HashFunction::clear)
+ .def("update", &Py_HashFunction::update)
+ .def("final", &Py_HashFunction::final);
+ }
diff --git a/misc/python/src/mac.cpp b/misc/python/src/mac.cpp
new file mode 100644
index 000000000..0a8f1d418
--- /dev/null
+++ b/misc/python/src/mac.cpp
@@ -0,0 +1,59 @@
+/*************************************************
+* 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_MAC
+ {
+ public:
+ u32bit output_length() const { return mac->OUTPUT_LENGTH; }
+ u32bit keylength_min() const { return mac->MINIMUM_KEYLENGTH; }
+ u32bit keylength_max() const { return mac->MAXIMUM_KEYLENGTH; }
+ u32bit keylength_mod() const { return mac->KEYLENGTH_MULTIPLE; }
+ std::string name() const { return mac->name(); }
+ void clear() throw() { mac->clear(); }
+
+ void set_key(const OctetString& key) { mac->set_key(key); }
+
+ bool valid_keylength(u32bit kl) const
+ {
+ return mac->valid_keylength(kl);
+ }
+
+ void update(const std::string& in) { mac->update(in); }
+
+ std::string final()
+ {
+ SecureVector<byte> result = mac->final();
+ return std::string((const char*)result.begin(), result.size());
+ }
+
+ Py_MAC(const std::string& name)
+ {
+ mac = get_mac(name);
+ }
+ ~Py_MAC() { delete mac; }
+ private:
+ MessageAuthenticationCode* mac;
+ };
+
+void export_macs()
+ {
+ python::class_<Py_MAC>("MAC", python::init<std::string>())
+ .add_property("output_length", &Py_MAC::output_length)
+ .add_property("keylength_min", &Py_MAC::keylength_min)
+ .add_property("keylength_max", &Py_MAC::keylength_max)
+ .add_property("keylength_mod", &Py_MAC::keylength_mod)
+ .add_property("name", &Py_MAC::name)
+ .def("valid_keylength", &Py_MAC::valid_keylength)
+ .def("set_key", &Py_MAC::set_key)
+ .def("clear", &Py_MAC::clear)
+ .def("update", &Py_MAC::update)
+ .def("final", &Py_MAC::final);
+ }