Skip to content

Commit 3bf8840

Browse files
Add unit test for ChaCha20 key size validation
1 parent 62f93d9 commit 3bf8840

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

crypto/tests/test_chacha20.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,20 @@
77
VALID_NONCE = B"\x00" * 12
88
assert len(VALID_NONCE) == 12, "VALID_NONCE must be exactly 12 bytes"
99

10-
secure_rng = random.SystemRandom()
10+
secure_rng = random.SystemRandom()
11+
12+
def test_invalid_key_size():
13+
"""Test invalid key sizes."""
14+
try:
15+
ChaCha20(b"short_key", VALID_NONCE)
16+
except ValueError as e:
17+
assert "Key must be exactly 32 bytes" in str(e)
18+
else:
19+
assert False, "ValueError was not raised for short key"
20+
21+
try:
22+
ChaCha20(b"A" * 33, VALID_NONCE)
23+
except ValueError as e:
24+
assert "Key must be exactly 32 bytes" in str(e)
25+
else:
26+
assert False, "ValueError was not raised for long key"

0 commit comments

Comments
 (0)