aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--misc/python/botan/__init__.py2
-rw-r--r--misc/python/src/filter.cpp17
-rwxr-xr-xmisc/python/test.py26
3 files changed, 35 insertions, 10 deletions
diff --git a/misc/python/botan/__init__.py b/misc/python/botan/__init__.py
index d92e70fcb..02565099c 100644
--- a/misc/python/botan/__init__.py
+++ b/misc/python/botan/__init__.py
@@ -7,6 +7,8 @@ def Filter(name, key = None, iv = None, dir = None):
return make_filter(name, key, iv, dir)
elif key != None and dir != None:
return make_filter(name, key, dir)
+ elif key != None:
+ return make_filter(name, key)
else:
return make_filter(name)
diff --git a/misc/python/src/filter.cpp b/misc/python/src/filter.cpp
index aac0fce1e..fe28cb3c4 100644
--- a/misc/python/src/filter.cpp
+++ b/misc/python/src/filter.cpp
@@ -29,15 +29,26 @@ Filter* make_filter1(const std::string& name)
throw Invalid_Argument("Filter " + name + " not found");
}
-// FIXME: add new wrapper for Keyed_Filter here
Filter* make_filter2(const std::string& name,
+ const SymmetricKey& key)
+ {
+ if(have_mac(name))
+ return new MAC_Filter(name, key);
+ else if(have_stream_cipher(name))
+ return new StreamCipher_Filter(name, key);
+
+ throw Invalid_Argument("Filter " + name + " not found");
+ }
+
+// FIXME: add new wrapper for Keyed_Filter here
+Filter* make_filter3(const std::string& name,
const SymmetricKey& key,
Cipher_Dir direction)
{
return return_or_raise(get_cipher(name, key, direction), name);
}
-Filter* make_filter3(const std::string& name,
+Filter* make_filter4(const std::string& name,
const SymmetricKey& key,
const InitializationVector& iv,
Cipher_Dir direction)
@@ -59,6 +70,8 @@ void export_filters()
return_value_policy<manage_new_object>());
def("make_filter", make_filter3,
return_value_policy<manage_new_object>());
+ def("make_filter", make_filter4,
+ 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 24c7f6eab..1aff5894f 100755
--- a/misc/python/test.py
+++ b/misc/python/test.py
@@ -2,13 +2,9 @@
import sys, botan
-def do_hash(input):
- 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),
+def encrypt(input):
+ pipe = botan.Pipe(botan.Filter("ARC4",
+ key = botan.SymmetricKey("AABB")),
botan.Filter("Hex_Encoder"))
pipe.start_msg()
@@ -17,8 +13,22 @@ def do_hash(input):
return pipe.read_all_as_string()
+def decrypt(input):
+ pipe = botan.Pipe(botan.Filter("Hex_Decoder"),
+
+ botan.Filter("ARC4",
+ key = botan.SymmetricKey("AABB")))
+
+ pipe.start_msg()
+ pipe.write(input)
+ pipe.end_msg()
+
+ return pipe.read_all_as_string()
+
def main():
- print do_hash("hi chappy")
+ ciphertext = encrypt("hi chappy")
+ print ciphertext
+ print decrypt(ciphertext)
if __name__ == "__main__":
sys.exit(main())