summaryrefslogtreecommitdiff
path: root/tests/test_bigfile.py
blob: ffca5b0b8ff476750598a5d3fc05ecb9f2e8fa9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'''Tests block operations.'''

from StringIO import StringIO
import unittest

import rsa
from rsa import bigfile, varblock

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()

        bigfile.encrypt_bigfile(infile, outfile, pub_key)

        # Test
        crypto = outfile.getvalue()

        cryptfile = StringIO(crypto)
        clearfile = StringIO()

        bigfile.decrypt_bigfile(cryptfile, clearfile, priv_key)
        self.assertEquals(clearfile.getvalue(), message)
        
        # We have 2x6 bytes in the message, so that should result in two
        # bigfile.
        cryptfile.seek(0)
        varblocks = list(varblock.yield_varblocks(cryptfile))
        self.assertEqual(2, len(varblocks))