Skip to content

Commit 75e464e

Browse files
committed
add more tests for corner cases
1 parent 362f08d commit 75e464e

File tree

2 files changed

+163
-2
lines changed

2 files changed

+163
-2
lines changed

src/tests/unit/protocols/der/base.txt

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,5 +987,63 @@ encode-pair option0 = 1, option1 = 2
987987
match c0 01 01 c1 01 02
988988

989989

990+
proto-dictionary der
991+
992+
#
993+
# ---- Integer boundary encode tests ----
994+
#
995+
996+
# Integer zero
997+
encode-pair Test-Integer = 0
998+
match 02 01 00
999+
1000+
# Negative integer -1
1001+
encode-pair Test-Integer = -1
1002+
match 02 01 ff
1003+
1004+
# Negative integer -128 (minimum 1-byte signed)
1005+
encode-pair Test-Integer = -128
1006+
match 02 01 80
1007+
1008+
# Negative integer -129 (requires 2 bytes)
1009+
encode-pair Test-Integer = -129
1010+
match 02 02 ff 7f
1011+
1012+
# Integer 128 (requires leading 0x00 byte)
1013+
encode-pair Test-Integer = 128
1014+
match 02 02 00 80
1015+
1016+
# Integer 255
1017+
encode-pair Test-Integer = 255
1018+
match 02 02 00 ff
1019+
1020+
# Integer 256
1021+
encode-pair Test-Integer = 256
1022+
match 02 02 01 00
1023+
1024+
# Minimum int64 value
1025+
encode-pair Test-Integer = -9223372036854775808
1026+
match 02 08 80 00 00 00 00 00 00 00
1027+
1028+
#
1029+
# ---- Empty string encode tests ----
1030+
#
1031+
1032+
encode-pair Test-String-UTF8 = ""
1033+
match 0c 00
1034+
1035+
encode-pair Test-String-Printable = ""
1036+
match 13 00
1037+
1038+
#
1039+
# ---- Enumerated boundary tests ----
1040+
#
1041+
1042+
encode-pair Test-Enumerated = 0
1043+
match 0a 01 00
1044+
1045+
encode-pair Test-Enumerated = -1
1046+
match 0a 01 ff
1047+
9901048
count
991-
match 583
1049+
match 608

src/tests/unit/protocols/der/error.txt

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,108 @@ match Invalid character in a string (1)
145145
decode-pair 1a 01 7f
146146
match Invalid character in a string (127)
147147

148+
#
149+
# ---- Boolean value errors ----
150+
#
151+
152+
#
153+
# Boolean with incorrect length (3 bytes instead of required 1)
154+
#
155+
proto-dictionary-root Test-Boolean
156+
157+
decode-pair 01 03 ff ff ff
158+
match Boolean has incorrect length (3). Must be 1.
159+
160+
#
161+
# Boolean with zero length
162+
#
163+
decode-pair 01 00
164+
match Boolean has incorrect length (0). Must be 1.
165+
166+
#
167+
# Boolean with non-DER value 0x01 (must be exactly 0x00 or 0xff)
168+
#
169+
decode-pair 01 01 01
170+
match Boolean is not correctly DER encoded (0x00 or 0xff).
171+
172+
#
173+
# Boolean with non-DER value 0x7f
174+
#
175+
decode-pair 01 01 7f
176+
match Boolean is not correctly DER encoded (0x00 or 0xff).
177+
178+
#
179+
# ---- Integer DER encoding errors ----
180+
#
181+
182+
#
183+
# Integer too large - 9 bytes exceeds maximum of 8 (sizeof uint64_t)
184+
#
185+
proto-dictionary-root Test-Integer
186+
187+
decode-pair 02 09 01 02 03 04 05 06 07 08 09
188+
match Integer too large (9)
189+
190+
#
191+
# Non-DER integer: unnecessary leading zero (0x00 0x01 should be just 0x01)
192+
#
193+
decode-pair 02 02 00 01
194+
match Integer is not correctly DER encoded. First two bytes are all 0s or all 1s.
195+
196+
#
197+
# Non-DER integer: unnecessary sign extension (0xff 0xfe should be just 0xfe)
198+
#
199+
decode-pair 02 02 ff fe
200+
match Integer is not correctly DER encoded. First two bytes are all 0s or all 1s.
201+
202+
#
203+
# ---- OID errors ----
204+
#
205+
206+
#
207+
# OID with truncated subidentifier - high bit set on last byte indicating
208+
# continuation, but no more data available
209+
#
210+
proto-dictionary-root Test-Oid
211+
212+
decode-pair 06 02 2b 88
213+
match OID subidentifier is truncated
214+
215+
#
216+
# ---- PrintableString character validation ----
217+
#
218+
219+
#
220+
# PrintableString with '@' (0x40=64) - not in allowed character set
221+
#
222+
proto-dictionary-root Test-String-Printable
223+
224+
decode-pair 13 01 40
225+
match Invalid character in a string (64)
226+
227+
#
228+
# PrintableString with '*' (0x2a=42) - not in allowed character set
229+
#
230+
decode-pair 13 01 2a
231+
match Invalid character in a string (42)
232+
233+
#
234+
# ---- Length field errors ----
235+
#
236+
237+
#
238+
# Multi-byte length field too large - 9 bytes of length exceeds max of 8
239+
#
240+
proto-dictionary-root Test-Boolean
241+
242+
decode-pair 01 89 01 02 03 04 05 06 07 08 09
243+
match Length field too large (9): Failed decoding Test-Boolean header
244+
245+
#
246+
# Insufficient data for declared length - header says 4 bytes but only 3 available
247+
#
248+
decode-pair 01 04 ff ff ff
249+
match Insufficient data for length field (4): Failed decoding Test-Boolean header
250+
148251
count
149-
match 43
252+
match 72

0 commit comments

Comments
 (0)