Test AESGCM stream: ignore failures for small auth tags

Smaller authentication tags may not be supported by the library.
This fix makes the test work for the default case that tags
should be minimum 12 bytes in size.
pull/126/head
Martijn de Milliano 2026-06-04 18:05:58 +02:00
parent 52886c4034
commit eb93f657bf
1 changed files with 9 additions and 2 deletions

View File

@ -25,7 +25,7 @@ from wolfcrypt._ffi import lib as _lib
if _lib.AESGCM_STREAM_ENABLED:
import pytest
from wolfcrypt.utils import t2b
from wolfcrypt.exceptions import WolfCryptError
from wolfcrypt.exceptions import WolfCryptError, WolfCryptApiError
from binascii import hexlify as b2h
from wolfcrypt.ciphers import AesGcmStream
@ -141,7 +141,14 @@ if _lib.AESGCM_STREAM_ENABLED:
for good in (4, 8, 12, 13, 14, 15, 16):
gcm = AesGcmStream(key, iv, tag_bytes=good)
gcm.encrypt("hello world")
tag = gcm.final()
try:
tag = gcm.final()
except WolfCryptApiError as exception:
if "(-173)" in str(exception) and good < 12:
# Probably this authentication tag size is not supported,
# the minimum is 12 by default. Ignore.
continue
raise
assert len(tag) == good
def test_decrypt_rejects_wrong_tag_length():