aboutsummaryrefslogtreecommitdiffstats
path: root/misc/python
diff options
context:
space:
mode:
Diffstat (limited to 'misc/python')
-rw-r--r--misc/python/botan/__init__.py9
-rw-r--r--misc/python/src/core.cpp4
-rw-r--r--misc/python/src/filter.cpp26
-rwxr-xr-xmisc/python/test.py9
4 files changed, 39 insertions, 9 deletions
diff --git a/misc/python/botan/__init__.py b/misc/python/botan/__init__.py
index 781426921..d92e70fcb 100644
--- a/misc/python/botan/__init__.py
+++ b/misc/python/botan/__init__.py
@@ -2,8 +2,13 @@ from _botan import *
init = LibraryInitializer()
-def Filter(name):
- return make_filter(name)
+def Filter(name, key = None, iv = None, dir = None):
+ if key != None and iv != None and dir != None:
+ return make_filter(name, key, iv, dir)
+ elif key != None and dir != None:
+ return make_filter(name, key, dir)
+ else:
+ return make_filter(name)
def Pipe(*filters):
pipe = PipeObj();
diff --git a/misc/python/src/core.cpp b/misc/python/src/core.cpp
index acb46c82e..806df8d89 100644
--- a/misc/python/src/core.cpp
+++ b/misc/python/src/core.cpp
@@ -34,6 +34,10 @@ BOOST_PYTHON_MODULE(_botan)
.def(python::init< python::optional<std::string> >())
.def(python::init< u32bit >());
+ python::enum_<Cipher_Dir>("cipher_dir")
+ .value("encryption", ENCRYPTION)
+ .value("decryption", DECRYPTION);
+
export_filters();
export_pipe();
export_x509();
diff --git a/misc/python/src/filter.cpp b/misc/python/src/filter.cpp
index b0f141e58..aac0fce1e 100644
--- a/misc/python/src/filter.cpp
+++ b/misc/python/src/filter.cpp
@@ -10,6 +10,13 @@ using namespace boost::python;
#include <botan/lookup.h>
using namespace Botan;
+Filter* return_or_raise(Filter* f, const std::string& name)
+ {
+ if(f)
+ return f;
+ throw Invalid_Argument("Filter " + name + " not found");
+ }
+
Filter* make_filter1(const std::string& name)
{
if(have_hash(name))
@@ -24,17 +31,24 @@ Filter* make_filter1(const std::string& name)
// FIXME: add new wrapper for Keyed_Filter here
Filter* make_filter2(const std::string& name,
- const SymmetricKey& key)
+ const SymmetricKey& key,
+ Cipher_Dir direction)
{
- printf("Trying to make a filter of type %s (key %s)\n", name.c_str(),
- key.as_string().c_str());
- return 0;
+ return return_or_raise(get_cipher(name, key, direction), name);
+ }
+
+Filter* make_filter3(const std::string& name,
+ const SymmetricKey& key,
+ const InitializationVector& iv,
+ Cipher_Dir direction)
+ {
+ return return_or_raise(get_cipher(name, key, iv, direction), name);
}
void export_filters()
{
class_<Filter, std::auto_ptr<Filter>, boost::noncopyable>
- ("Filter", no_init)
+ ("FilterObj", no_init)
.def("write", &Filter::write)
.def("start_msg", &Filter::start_msg)
.def("end_msg", &Filter::end_msg);
@@ -43,6 +57,8 @@ void export_filters()
return_value_policy<manage_new_object>());
def("make_filter", make_filter2,
return_value_policy<manage_new_object>());
+ def("make_filter", make_filter3,
+ return_value_policy<manage_new_object>());
}
void append_filter(Pipe& pipe, std::auto_ptr<Filter> filter)
diff --git a/misc/python/test.py b/misc/python/test.py
index aa30ab5d6..24c7f6eab 100755
--- a/misc/python/test.py
+++ b/misc/python/test.py
@@ -3,8 +3,13 @@
import sys, botan
def do_hash(input):
- pipe = botan.Pipe(botan.Filter("Hex_Encoder"),
- botan.Filter("Hex_Decoder"))
+ cipher_key = botan.SymmetricKey("AABB")
+
+ pipe = botan.Pipe(botan.Filter("Blowfish/CBC/PKCS7",
+ key = botan.SymmetricKey("AABB"),
+ iv = botan.InitializationVector("AABBCCDDEEFF0011"),
+ dir = botan.cipher_dir.encryption),
+ botan.Filter("Hex_Encoder"))
pipe.start_msg()
pipe.write(input)