summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSybren A. St?vel <sybren@stuvel.eu>2011-07-31 20:25:40 +0200
committerSybren A. St?vel <sybren@stuvel.eu>2011-07-31 20:25:40 +0200
commit5e7aa172647a6571abd28bb174b7a1f62e2f81f5 (patch)
treef9260ee42ee6247868eebd76f77696b72cb7d2e9 /tests
parentd60005063ce734cc963e4a93e1406d22ccb1383b (diff)
downloadrsa-5e7aa172647a6571abd28bb174b7a1f62e2f81f5.tar.gz
Added encrypting and decrypting of large files
Diffstat (limited to 'tests')
-rw-r--r--tests/test_blocks.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/test_blocks.py b/tests/test_blocks.py
index ce5f03a..22d6500 100644
--- a/tests/test_blocks.py
+++ b/tests/test_blocks.py
@@ -3,6 +3,7 @@
from StringIO import StringIO
import unittest
+import rsa
from rsa import blocks
class VarintTest(unittest.TestCase):
@@ -73,3 +74,33 @@ class FixedblockTest(unittest.TestCase):
fixedblocks = list(blocks.yield_fixedblocks(infile, 6))
self.assertEqual(['123456', 'Sybren'], fixedblocks)
+
+class BigfileTest(unittest.TestCase):
+
+ def test_encrypt_decrypt_bigfile(self):
+
+ # Expected block size + 11 bytes padding
+ pub_key, priv_key = rsa.newkeys((6 + 11) * 8)
+
+ # Encrypt the file
+ message = '123456Sybren'
+ infile = StringIO(message)
+ outfile = StringIO()
+
+ blocks.encrypt_bigfile(infile, outfile, pub_key)
+
+ # Test
+ crypto = outfile.getvalue()
+
+ cryptfile = StringIO(crypto)
+ clearfile = StringIO()
+
+ blocks.decrypt_bigfile(cryptfile, clearfile, priv_key)
+ self.assertEquals(clearfile.getvalue(), message)
+
+ # We have 2x6 bytes in the message, so that should result in two
+ # blocks.
+ cryptfile.seek(0)
+ varblocks = list(blocks.yield_varblocks(cryptfile))
+ self.assertEqual(2, len(varblocks))
+