Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions tests/hazmat/primitives/test_aes_gcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down