Skip to content

Commit 8541ed6

Browse files
Add unit test for ChaCha20 nonce size validation
1 parent 3bf8840 commit 8541ed6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

crypto/tests/test_chacha20.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,19 @@ def test_invalid_key_size():
2424
assert "Key must be exactly 32 bytes" in str(e)
2525
else:
2626
assert False, "ValueError was not raised for long key"
27+
28+
def test_invalid_nonce_size():
29+
"""Test invalid nonce sizes."""
30+
try:
31+
ChaCha20(VALID_KEY, b"short")
32+
except ValueError as e:
33+
assert "Nonce must be exactly 12 bytes" in str(e)
34+
else:
35+
assert False, "ValueError was not raised for short nonce"
36+
37+
try:
38+
ChaCha20(VALID_KEY, b"A" * 13)
39+
except ValueError as e:
40+
assert "Nonce must be exactly 12 bytes" in str(e)
41+
else:
42+
assert False, "ValueError was not raised for long nonce"

0 commit comments

Comments
 (0)