From 1fb0d8a27711e751eff682bd379c4bd3bb924063 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sat, 11 Nov 2023 16:40:14 -0500 Subject: [PATCH] Added a test for update_into with an empty out buf (#9863) refs #9859 --- tests/hazmat/primitives/test_aes_gcm.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/hazmat/primitives/test_aes_gcm.py b/tests/hazmat/primitives/test_aes_gcm.py index 7802a0e23d81..d82e37470cae 100644 --- a/tests/hazmat/primitives/test_aes_gcm.py +++ b/tests/hazmat/primitives/test_aes_gcm.py @@ -206,22 +206,24 @@ def test_gcm_tag_decrypt_finalize_tag_length(self, tag, backend): def test_buffer_protocol(self, backend): data = bytearray(b"helloworld") - enc = base.Cipher( + c = base.Cipher( algorithms.AES(bytearray(b"\x00" * 16)), modes.GCM(bytearray(b"\x00" * 12)), backend, - ).encryptor() + ) + enc = c.encryptor() enc.authenticate_additional_data(bytearray(b"foo")) ct = enc.update(data) + enc.finalize() - dec = base.Cipher( - algorithms.AES(bytearray(b"\x00" * 16)), - modes.GCM(bytearray(b"\x00" * 12), enc.tag), - backend, - ).decryptor() + + dec = c.decryptor() dec.authenticate_additional_data(bytearray(b"foo")) - pt = dec.update(ct) + dec.finalize() + pt = dec.update(ct) + dec.finalize_with_tag(enc.tag) assert pt == data + enc = c.encryptor() + with pytest.raises(ValueError): + enc.update_into(b"abc123", bytearray(0)) + @pytest.mark.parametrize("size", [8, 128]) def test_gcm_min_max_iv(self, size, backend): if backend._fips_enabled: