Skip to content

Commit 9c046ee

Browse files
committed
tests: reject truncated DER lengths
1 parent acc40fd commit 9c046ee

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/ecdsa/test_der.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,3 +600,23 @@ def test_oids(ids):
600600
decoded_oid, rest = remove_object(encoded_oid)
601601
assert rest == b""
602602
assert decoded_oid == ids
603+
604+
def test_remove_octet_string_rejects_truncated_length():
605+
# OCTET STRING: declared length 4096, but only 3 bytes present
606+
bad = b"\x04\x82\x10\x00" + b"ABC"
607+
with pytest.raises(UnexpectedDER, match="Length longer than the provided buffer"):
608+
remove_octet_string(bad)
609+
610+
def test_remove_constructed_rejects_truncated_length():
611+
# Constructed tag: 0xA0 (context-specific constructed, tag=0)
612+
# declared length 4096, but only 3 bytes present
613+
bad = b"\xA0\x82\x10\x00" + b"ABC"
614+
with pytest.raises(UnexpectedDER, match="Length longer than the provided buffer"):
615+
remove_constructed(bad)
616+
617+
def test_remove_implicit_rejects_truncated_length():
618+
# IMPLICIT primitive context-specific tag 0: 0x80
619+
# declared length 4096, but only 3 bytes present
620+
bad = b"\x80\x82\x10\x00" + b"ABC"
621+
with pytest.raises(UnexpectedDER, match="Length longer than the provided buffer"):
622+
remove_implicit(bad)

0 commit comments

Comments
 (0)