blob: ffca5b0b8ff476750598a5d3fc05ecb9f2e8fa9b [file] [log] [blame]
Sybren A. Stüvel3200f892011-07-31 20:47:49 +02001'''Tests block operations.'''
2
3from StringIO import StringIO
4import unittest
5
6import rsa
7from rsa import bigfile, varblock
8
9class BigfileTest(unittest.TestCase):
10
11 def test_encrypt_decrypt_bigfile(self):
12
13 # Expected block size + 11 bytes padding
14 pub_key, priv_key = rsa.newkeys((6 + 11) * 8)
15
16 # Encrypt the file
17 message = '123456Sybren'
18 infile = StringIO(message)
19 outfile = StringIO()
20
21 bigfile.encrypt_bigfile(infile, outfile, pub_key)
22
23 # Test
24 crypto = outfile.getvalue()
25
26 cryptfile = StringIO(crypto)
27 clearfile = StringIO()
28
29 bigfile.decrypt_bigfile(cryptfile, clearfile, priv_key)
30 self.assertEquals(clearfile.getvalue(), message)
31
32 # We have 2x6 bytes in the message, so that should result in two
33 # bigfile.
34 cryptfile.seek(0)
35 varblocks = list(varblock.yield_varblocks(cryptfile))
36 self.assertEqual(2, len(varblocks))
37