From 5e7aa172647a6571abd28bb174b7a1f62e2f81f5 Mon Sep 17 00:00:00 2001 From: "Sybren A. St?vel" Date: Sun, 31 Jul 2011 20:25:40 +0200 Subject: Added encrypting and decrypting of large files --- tests/test_blocks.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests') 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)) + -- cgit v1.2.1