def test_encrypt_chaining(self): # Even if the input is repeated, the output should not be. encrypted = encrypt_binary(b"0" * 1_000_000, self.key) # The output should appear random, so any sequence of 64 bytes is # very unlikely to repeat. blocks = re.findall(".{64}", encrypted) self.assertEqual(len(blocks), len(set(blocks)))
def test_encrypt_chaining(self): # Even if the input is repeated, the output should not be. encrypted = encrypt_binary(b"0" * 1000000, self.key) # The output should appear random, so any sequence of 64 bytes is # very unlikely to repeat. blocks = re.findall(".{64}", encrypted) self.assertEqual(len(blocks), len(set(blocks)))
def test_decrypt_invalid_base64(self): encrypted = encrypt_binary(b"stuff", self.key) with self.assertRaises(ValueError): decrypt_binary(encrypted[1:], self.key)
def test_encrypt_salting(self): self.assertNotEqual(encrypt_binary(b"stuff", self.key), encrypt_binary(b"stuff", self.key))
def test_encrypt_and_decrypt_long(self): value = b"0" * 1_000_000 self.assertEqual( decrypt_binary(encrypt_binary(value, self.key), self.key), value)
def test_encrypt_and_decrypt_empty(self): self.assertEqual( decrypt_binary(encrypt_binary(b"", self.key), self.key), b"")
def test_encrypt_and_decrypt(self): self.assertEqual( decrypt_binary(encrypt_binary(b"stuff", self.key), self.key), b"stuff")
def test_encrypt_and_decrypt_long(self): self.assertEqual( decrypt_binary(encrypt_binary(b"0" * 1000000, self.key), self.key), b"0" * 1000000)