From 26bdafe0445cdd5c1b1174dedfd9292847e47758 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Wed, 15 Mar 2017 20:25:35 -0300 Subject: [feature] incremental decrypter --- testing/tests/client/test_crypto.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'testing') diff --git a/testing/tests/client/test_crypto.py b/testing/tests/client/test_crypto.py index 44e1b2a5..11384ad7 100644 --- a/testing/tests/client/test_crypto.py +++ b/testing/tests/client/test_crypto.py @@ -142,6 +142,35 @@ class BlobTestCase(unittest.TestCase): ciphertext, preamble) assert str(decrypted) == snowden1 + @defer.inlineCallbacks + def test_init_with_preamble_alone(self): + ciphertext = yield self.blob.encrypt() + preamble = ciphertext.getvalue().split()[0] + decryptor = _crypto.BlobDecryptor( + self.doc_info, BytesIO(preamble), + start_stream=False, + secret='A' * 96) + assert decryptor._consume_preamble() + + @defer.inlineCallbacks + def test_incremental_blob_decryptor(self): + ciphertext = yield self.blob.encrypt() + preamble, ciphertext = ciphertext.getvalue().split() + ciphertext = base64.urlsafe_b64decode(ciphertext) + + decryptor = _crypto.BlobDecryptor( + self.doc_info, BytesIO(preamble), + start_stream=False, + secret='A' * 96, + tag=ciphertext[-16:]) + ciphertext = BytesIO(ciphertext[:-16]) + chunk = ciphertext.read(10) + while chunk: + decryptor.write(chunk) + chunk = ciphertext.read(10) + decrypted = decryptor._end_stream() + assert decrypted.getvalue() == snowden1 + @defer.inlineCallbacks def test_blob_decryptor(self): ciphertext = yield self.blob.encrypt() -- cgit v1.2.3