aboutsummaryrefslogtreecommitdiffstats
path: root/misc/python
diff options
context:
space:
mode:
Diffstat (limited to 'misc/python')
-rw-r--r--misc/python/botan/__init__.py6
-rw-r--r--misc/python/src/core.cpp15
-rwxr-xr-xmisc/python/test.py25
3 files changed, 18 insertions, 28 deletions
diff --git a/misc/python/botan/__init__.py b/misc/python/botan/__init__.py
index 569360ffe..29ccaca9c 100644
--- a/misc/python/botan/__init__.py
+++ b/misc/python/botan/__init__.py
@@ -2,6 +2,12 @@ from _botan import *
init = LibraryInitializer()
+class SymmetricKey(OctetString):
+ pass
+
+class InitializationVector(OctetString):
+ pass
+
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)
diff --git a/misc/python/src/core.cpp b/misc/python/src/core.cpp
index fa35bd07b..07252e720 100644
--- a/misc/python/src/core.cpp
+++ b/misc/python/src/core.cpp
@@ -20,18 +20,9 @@ BOOST_PYTHON_MODULE(_botan)
python::class_<OctetString>("OctetString")
.def(python::init< python::optional<std::string> >())
- .def("as_string", &OctetString::as_string)
- .def("length", &OctetString::length)
- .def(python::self ^= python::self);
-
- python::class_<SymmetricKey, python::bases<OctetString> >("SymmetricKey")
- .def(python::init< python::optional<std::string> >())
- .def(python::init< u32bit >());
-
- python::class_<InitializationVector, python::bases<OctetString> >
- ("InitializationVector")
- .def(python::init< python::optional<std::string> >())
- .def(python::init< u32bit >());
+ .def(python::init< u32bit >())
+ .def("__str__", &OctetString::as_string)
+ .add_property("length", &OctetString::length);
python::enum_<Cipher_Dir>("cipher_dir")
.value("encryption", ENCRYPTION)
diff --git a/misc/python/test.py b/misc/python/test.py
index 416797099..9896777d4 100755
--- a/misc/python/test.py
+++ b/misc/python/test.py
@@ -2,22 +2,15 @@
import sys, botan
-class PyFilter(botan.FilterObj):
- def start_msg(self):
- print "PyFilter start_msg"
- self.send_str('initial')
-
- def end_msg(self):
- print "PyFilter end_msg"
-
- def write(self, data):
- print "PyFilter write called with", data
- self.send_str(data.replace('h', 'r'))
-
def encrypt(input):
- filter = PyFilter()
+ cipher_key = botan.SymmetricKey("AABB")
+ print cipher_key.length
+ cipher_key = botan.SymmetricKey("AABBCCDD")
+ print cipher_key.length
+
+ cipher = botan.Filter("ARC4", key = cipher_key)
- pipe = botan.Pipe(filter)
+ pipe = botan.Pipe(cipher, botan.Filter("Hex_Encoder"))
pipe.start_msg()
pipe.write(input)
@@ -30,7 +23,7 @@ def encrypt(input):
def decrypt(input):
pipe = botan.Pipe(botan.Filter("Hex_Decoder"),
botan.Filter("ARC4",
- key = botan.SymmetricKey("AABB")))
+ key = botan.SymmetricKey("AABBCCDD")))
pipe.process_msg(input)
return pipe.read_all()
@@ -38,7 +31,7 @@ def decrypt(input):
def main():
ciphertext = encrypt("hi chappy")
print ciphertext
- #print decrypt(ciphertext)
+ print decrypt(ciphertext)
if __name__ == "__main__":
sys.exit(main())