Exemplo n.º 1
0
 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)))
Exemplo n.º 2
0
 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)))
Exemplo n.º 3
0
 def test_decrypt_invalid_base64(self):
     encrypted = encrypt_binary(b"stuff", self.key)
     with self.assertRaises(ValueError):
         decrypt_binary(encrypted[1:], self.key)
Exemplo n.º 4
0
 def test_encrypt_salting(self):
     self.assertNotEqual(encrypt_binary(b"stuff", self.key),
                         encrypt_binary(b"stuff", self.key))
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
 def test_encrypt_and_decrypt_empty(self):
     self.assertEqual(
         decrypt_binary(encrypt_binary(b"", self.key), self.key), b"")
Exemplo n.º 7
0
 def test_encrypt_and_decrypt(self):
     self.assertEqual(
         decrypt_binary(encrypt_binary(b"stuff", self.key), self.key),
         b"stuff")
Exemplo n.º 8
0
 def test_encrypt_and_decrypt_long(self):
     self.assertEqual(
         decrypt_binary(encrypt_binary(b"0" * 1000000, self.key), self.key),
         b"0" * 1000000)
Exemplo n.º 9
0
 def test_decrypt_invalid_base64(self):
     encrypted = encrypt_binary(b"stuff", self.key)
     with self.assertRaises(ValueError):
         decrypt_binary(encrypted[1:], self.key)
Exemplo n.º 10
0
 def test_encrypt_salting(self):
     self.assertNotEqual(encrypt_binary(b"stuff", self.key),
                         encrypt_binary(b"stuff", self.key))
Exemplo n.º 11
0
 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)
Exemplo n.º 12
0
 def test_encrypt_and_decrypt_empty(self):
     self.assertEqual(
         decrypt_binary(encrypt_binary(b"", self.key), self.key),
         b"")
Exemplo n.º 13
0
 def test_encrypt_and_decrypt(self):
     self.assertEqual(
         decrypt_binary(encrypt_binary(b"stuff", self.key), self.key),
         b"stuff")
Exemplo n.º 14
0
 def test_encrypt_and_decrypt_long(self):
     self.assertEqual(
         decrypt_binary(encrypt_binary(b"0" * 1000000, self.key), self.key),
         b"0" * 1000000)