aboutsummaryrefslogtreecommitdiffstats
path: root/tests/hazmat/primitives/test_chacha20.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/hazmat/primitives/test_chacha20.py')
-rw-r--r--tests/hazmat/primitives/test_chacha20.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/hazmat/primitives/test_chacha20.py b/tests/hazmat/primitives/test_chacha20.py
index 33730d91..7c475c0f 100644
--- a/tests/hazmat/primitives/test_chacha20.py
+++ b/tests/hazmat/primitives/test_chacha20.py
@@ -44,6 +44,18 @@ class TestChaCha20(object):
computed_ct = encryptor.update(pt) + encryptor.finalize()
assert binascii.hexlify(computed_ct) == vector["ciphertext"]
+ def test_buffer_protocol(self, backend):
+ key = bytearray(os.urandom(32))
+ nonce = bytearray(os.urandom(16))
+ cipher = Cipher(
+ algorithms.ChaCha20(key, nonce), None, backend
+ )
+ enc = cipher.encryptor()
+ ct = enc.update(bytearray(b"hello")) + enc.finalize()
+ dec = cipher.decryptor()
+ pt = dec.update(ct) + dec.finalize()
+ assert pt == b"hello"
+
def test_key_size(self):
chacha = algorithms.ChaCha20(b"0" * 32, b"0" * 16)
assert chacha.key_size == 256