aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-08-23 09:08:45 +0000
committerlloyd <[email protected]>2006-08-23 09:08:45 +0000
commit183d2c6fa6cb7440a5953e30f254f10ab1e2347e (patch)
treef55cc67d07e8e0009611f6ad3dab4d90775e2992
parentc834dffb49deca70b130803ded521b4b6cf40c9c (diff)
Just export OctetString, and define the alternate names for that type
in the Python portion of the module
-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())