aboutsummaryrefslogtreecommitdiffstats
path: root/wrappers/swig/tests
diff options
context:
space:
mode:
Diffstat (limited to 'wrappers/swig/tests')
-rw-r--r--wrappers/swig/tests/block.py52
-rw-r--r--wrappers/swig/tests/block2.py44
-rw-r--r--wrappers/swig/tests/encrypt.py37
-rw-r--r--wrappers/swig/tests/filter.py27
-rw-r--r--wrappers/swig/tests/hash.py30
-rw-r--r--wrappers/swig/tests/mac.py12
-rw-r--r--wrappers/swig/tests/pubkey.py10
-rw-r--r--wrappers/swig/tests/stream.py17
8 files changed, 229 insertions, 0 deletions
diff --git a/wrappers/swig/tests/block.py b/wrappers/swig/tests/block.py
new file mode 100644
index 000000000..593937c81
--- /dev/null
+++ b/wrappers/swig/tests/block.py
@@ -0,0 +1,52 @@
+#!/usr/bin/python
+
+import botan, base64
+
+class MyCipher(botan.BlockCipher):
+ def __init__(self):
+ botan.BlockCipher.__init__(self, 16, 16, 32, 8)
+ def encrypt(self, val):
+ print "encrypt", val
+ return val.swapcase()
+ def decrypt(self, val):
+ print "decrypt", val
+ return val.swapcase()
+ def set_key(self, key):
+ print "set_key", key
+ def clone(self):
+ print "cloning"
+ return MyCipher()
+ def name(self):
+ print "naming"
+ return "MyCipher"
+
+cipher = botan.BlockCipher("AES-128")
+
+print cipher.block_size
+print cipher.keylength_min
+print cipher.keylength_max
+print cipher.keylength_mod
+print cipher.name()
+
+for kl in range(1, 128):
+ if cipher.valid_keylength(kl):
+ print "1",
+ else:
+ print "0",
+print
+key = botan.SymmetricKey(16)
+
+cipher.set_key(key)
+ciphertext = cipher.encrypt("ABCDEFGH12345678")
+print base64.b16encode(ciphertext)
+
+cipher2 = cipher.clone()
+cipher2.set_key(key)
+
+plaintext = cipher2.decrypt(ciphertext)
+print plaintext
+
+botan.get_info(cipher)
+
+mycipher = MyCipher()
+botan.get_info(mycipher)
diff --git a/wrappers/swig/tests/block2.py b/wrappers/swig/tests/block2.py
new file mode 100644
index 000000000..5faccaf9a
--- /dev/null
+++ b/wrappers/swig/tests/block2.py
@@ -0,0 +1,44 @@
+#!/usr/bin/python
+
+import botan, base64
+
+class MyCipher(botan.BlockCipherImpl):
+ def __init__(self):
+ botan.BlockCipherImpl.__init__(self, 8, 8, 16, 1)
+
+ def name(self):
+ return "MyCipher"
+
+ def encrypt(self, input):
+ return input.swapcase()
+
+ def decrypt(self, input):
+ return input.swapcase()
+
+ def set_key(self, key):
+ print "Got key",key
+
+def test(cipher):
+ print
+ print cipher
+ print "Testing", cipher.name()
+ print cipher.block_size
+ print cipher.keylength_min, cipher.keylength_max, cipher.keylength_mod
+ for i in range(1, 64):
+ if cipher.valid_keylength(i):
+ print "1",
+ else:
+ print "0",
+ print
+ cipher.set_key(botan.SymmetricKey(16))
+ ciphertext = cipher.encrypt("aBcDeFgH" * (cipher.block_size / 8))
+ print repr(ciphertext)
+ print cipher.decrypt(ciphertext)
+
+def main():
+ test(botan.BlockCipher("Blowfish"))
+ test(MyCipher())
+ test(botan.BlockCipher("AES"))
+
+if __name__ == "__main__":
+ main()
diff --git a/wrappers/swig/tests/encrypt.py b/wrappers/swig/tests/encrypt.py
new file mode 100644
index 000000000..9896777d4
--- /dev/null
+++ b/wrappers/swig/tests/encrypt.py
@@ -0,0 +1,37 @@
+#!/usr/bin/python
+
+import sys, botan
+
+def encrypt(input):
+ 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(cipher, botan.Filter("Hex_Encoder"))
+
+ pipe.start_msg()
+ pipe.write(input)
+ pipe.end_msg()
+
+ str = pipe.read_all()
+ print str
+ return str
+
+def decrypt(input):
+ pipe = botan.Pipe(botan.Filter("Hex_Decoder"),
+ botan.Filter("ARC4",
+ key = botan.SymmetricKey("AABBCCDD")))
+
+ pipe.process_msg(input)
+ return pipe.read_all()
+
+def main():
+ ciphertext = encrypt("hi chappy")
+ print ciphertext
+ print decrypt(ciphertext)
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/wrappers/swig/tests/filter.py b/wrappers/swig/tests/filter.py
new file mode 100644
index 000000000..2b65d9ff2
--- /dev/null
+++ b/wrappers/swig/tests/filter.py
@@ -0,0 +1,27 @@
+#!/usr/bin/python
+
+import sys, botan
+
+class MyFilter(botan.FilterObj):
+ def write(self, input):
+ print "MyFilter::write",input
+ self.send(input)
+ def start_msg(self):
+ print "MyFilter::start_msg"
+ def end_msg(self):
+ print "MyFilter::end_msg"
+ def __del__(self):
+ print "~MyFilter"
+
+def main():
+ filter = MyFilter()
+
+ pipe = botan.Pipe(botan.Filter("Hex_Encoder"), filter,
+ botan.Filter("Hex_Decoder"))
+ pipe.start_msg()
+ pipe.write("hi chappy")
+ pipe.end_msg()
+ print pipe.read_all()
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/wrappers/swig/tests/hash.py b/wrappers/swig/tests/hash.py
new file mode 100644
index 000000000..930b8c81a
--- /dev/null
+++ b/wrappers/swig/tests/hash.py
@@ -0,0 +1,30 @@
+#!/usr/bin/python
+
+import botan, base64, md5
+
+class PyMD5(botan.HashFunctionImpl):
+ def name(self):
+ return "PyMD5"
+ def update(self, input):
+ self.md5.update(input)
+ def final(self):
+ output = self.md5.digest()
+ self.md5 = md5.new()
+ return output
+ def __init__(self):
+ botan.HashFunctionImpl.__init__(self, 16, 64)
+ self.md5 = md5.new()
+
+hash = botan.HashFunction("SHA-256")
+
+print hash.name()
+print hash.digest_size
+
+hash.update("hi")
+hash.update(" ")
+hash.update("chappy")
+print base64.b16encode(hash.final())
+
+hash2 = PyMD5()
+hash2.update("hi chappy")
+print base64.b16encode(hash2.final())
diff --git a/wrappers/swig/tests/mac.py b/wrappers/swig/tests/mac.py
new file mode 100644
index 000000000..6110b6102
--- /dev/null
+++ b/wrappers/swig/tests/mac.py
@@ -0,0 +1,12 @@
+#!/usr/bin/python
+
+import botan, base64
+
+mac = botan.MAC("HMAC(SHA-512)")
+
+print mac.name
+print mac.output_length
+
+mac.set_key(botan.SymmetricKey("abcd"))
+mac.update("hi chappy")
+print base64.b16encode(mac.final())
diff --git a/wrappers/swig/tests/pubkey.py b/wrappers/swig/tests/pubkey.py
new file mode 100644
index 000000000..456c52069
--- /dev/null
+++ b/wrappers/swig/tests/pubkey.py
@@ -0,0 +1,10 @@
+#!/usr/bin/python
+
+import botan
+
+key = botan.X509_PublicKey("rsapub.pem")
+print key
+print key.key_id()
+print key.max_input_bits
+print key.algo
+print key.oid
diff --git a/wrappers/swig/tests/stream.py b/wrappers/swig/tests/stream.py
new file mode 100644
index 000000000..59d3ffa16
--- /dev/null
+++ b/wrappers/swig/tests/stream.py
@@ -0,0 +1,17 @@
+#!/usr/bin/python
+
+import botan, base64
+
+cipher = botan.StreamCipher("ARC4")
+
+print cipher.name
+
+key = botan.SymmetricKey(16)
+
+cipher.set_key(key)
+ciphertext = cipher.crypt("hi chappy")
+
+cipher.set_key(key)
+plaintext = cipher.crypt(ciphertext)
+
+print plaintext