MCPcopy Create free account
hub / github.com/Keeper-Security/Commander / test_stream_decrypter

Method test_stream_decrypter

unit-tests/test_crypto.py:10–38  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

8
9class TestCrypto(TestCase):
10 def test_stream_decrypter(self):
11 data = bytearray(999)
12 for i in range(len(data)):
13 data[i] = i & 0xff
14
15 key = utils.generate_aes_key()
16
17 crypter = crypto.StreamCrypter()
18 crypter.key = key
19 crypter.is_gcm = False
20
21 encrypted_data = bytearray()
22 with crypter.set_stream(io.BytesIO(data), True) as cs:
23 while True:
24 buffer = cs.read(1024)
25 if not buffer:
26 break
27 encrypted_data.extend(buffer)
28 self.assertEqual(crypter.bytes_read, len(data))
29
30 decrypted_data = bytearray()
31 with crypter.set_stream(io.BytesIO(encrypted_data), False) as cs:
32 while True:
33 buffer = cs.read(1024)
34 if not buffer:
35 break
36 decrypted_data.extend(buffer)
37
38 self.assertEqual(decrypted_data, data)
39
40 def test_decrypt_aes_v1(self):
41 data = utils.base64_url_decode('KvsOJmE4JNK1HwKSpkBeR5R9YDms86uOb3wjNvc4LbUnZhKQtDxWifgA99tH2ZuP')

Callers

nothing calls this directly

Calls 2

set_streamMethod · 0.80
readMethod · 0.45

Tested by

no test coverage detected