Skip to content

Commit a2cfcbf

Browse files
Add unit test for negative counter validation
1 parent 8541ed6 commit a2cfcbf

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

crypto/tests/test_chacha20.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,13 @@ def test_invalid_nonce_size():
4040
assert "Nonce must be exactly 12 bytes" in str(e)
4141
else:
4242
assert False, "ValueError was not raised for long nonce"
43+
44+
def test_invalid_counter_values():
45+
"""Test invalid counter values for ChaCha20."""
46+
for invalid_counter in [-1, -100, -999999]:
47+
try:
48+
ChaCha20(VALID_KEY, VALID_NONCE, counter=invalid_counter)
49+
except ValueError as e:
50+
assert "Counter must be a non-negative integer" in str(e)
51+
else:
52+
assert False, f"ValueError not raised for counter={invalid_counter}"

0 commit comments

Comments
 (0)