2 * Copyright (c) 1999 - 2005 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 #include <asn1-common.h>
45 #include <krb5_asn1.h>
46 #include <heim_asn1.h>
47 #include <rfc2459_asn1.h>
48 #include <test_asn1.h>
50 #include "check-common.h"
54 static char *lha_principal
[] = { "lha" };
55 static char *lharoot_princ
[] = { "lha", "root" };
56 static char *datan_princ
[] = { "host", "nutcracker.e.kth.se" };
57 static char *nada_tgt_principal
[] = { "krbtgt", "NADA.KTH.SE" };
60 #define IF_OPT_COMPARE(ac,bc,e) \
61 if (((ac)->e == NULL && (bc)->e != NULL) || (((ac)->e != NULL && (bc)->e == NULL))) return 1; if ((ab)->e)
62 #define COMPARE_OPT_STRING(ac,bc,e) \
63 do { if (strcmp(*(ac)->e, *(bc)->e) != 0) return 1; } while(0)
64 #define COMPARE_OPT_OCTECT_STRING(ac,bc,e) \
65 do { if ((ac)->e->length != (bc)->e->length || memcmp((ac)->e->data, (bc)->e->data, (ac)->e->length) != 0) return 1; } while(0)
66 #define COMPARE_STRING(ac,bc,e) \
67 do { if (strcmp((ac)->e, (bc)->e) != 0) return 1; } while(0)
68 #define COMPARE_INTEGER(ac,bc,e) \
69 do { if ((ac)->e != (bc)->e) return 1; } while(0)
70 #define COMPARE_MEM(ac,bc,e,len) \
71 do { if (memcmp((ac)->e, (bc)->e,len) != 0) return 1; } while(0)
74 cmp_principal (void *a
, void *b
)
80 COMPARE_STRING(pa
,pb
,realm
);
81 COMPARE_INTEGER(pa
,pb
,name
.name_type
);
82 COMPARE_INTEGER(pa
,pb
,name
.name_string
.len
);
84 for (i
= 0; i
< pa
->name
.name_string
.len
; i
++)
85 COMPARE_STRING(pa
,pb
,name
.name_string
.val
[i
]);
94 struct test_case tests
[] = {
96 "\x30\x1b\xa0\x10\x30\x0e\xa0\x03\x02\x01\x01\xa1\x07\x30\x05\x1b"
97 "\x03\x6c\x68\x61\xa1\x07\x1b\x05\x53\x55\x2e\x53\x45"
100 "\x30\x21\xa0\x16\x30\x14\xa0\x03\x02\x01\x01\xa1\x0d\x30\x0b\x1b"
101 "\x03\x6c\x68\x61\x1b\x04\x72\x6f\x6f\x74\xa1\x07\x1b\x05\x53\x55"
105 "\x30\x34\xa0\x26\x30\x24\xa0\x03\x02\x01\x03\xa1\x1d\x30\x1b\x1b"
106 "\x04\x68\x6f\x73\x74\x1b\x13\x6e\x75\x74\x63\x72\x61\x63\x6b\x65"
107 "\x72\x2e\x65\x2e\x6b\x74\x68\x2e\x73\x65\xa1\x0a\x1b\x08\x45\x2e"
108 "\x4b\x54\x48\x2e\x53\x45"
113 Principal values
[] = {
114 { { KRB5_NT_PRINCIPAL
, { 1, lha_principal
} }, "SU.SE" },
115 { { KRB5_NT_PRINCIPAL
, { 2, lharoot_princ
} }, "SU.SE" },
116 { { KRB5_NT_SRV_HST
, { 2, datan_princ
} }, "E.KTH.SE" }
119 int ntests
= sizeof(tests
) / sizeof(*tests
);
121 for (i
= 0; i
< ntests
; ++i
) {
122 tests
[i
].val
= &values
[i
];
123 asprintf (&tests
[i
].name
, "Principal %d", i
);
126 ret
= generic_test (tests
, ntests
, sizeof(Principal
),
127 (generic_encode
)encode_Principal
,
128 (generic_length
)length_Principal
,
129 (generic_decode
)decode_Principal
,
130 (generic_free
)free_Principal
,
132 for (i
= 0; i
< ntests
; ++i
)
133 free (tests
[i
].name
);
139 cmp_authenticator (void *a
, void *b
)
141 Authenticator
*aa
= a
;
142 Authenticator
*ab
= b
;
145 COMPARE_INTEGER(aa
,ab
,authenticator_vno
);
146 COMPARE_STRING(aa
,ab
,crealm
);
148 COMPARE_INTEGER(aa
,ab
,cname
.name_type
);
149 COMPARE_INTEGER(aa
,ab
,cname
.name_string
.len
);
151 for (i
= 0; i
< aa
->cname
.name_string
.len
; i
++)
152 COMPARE_STRING(aa
,ab
,cname
.name_string
.val
[i
]);
158 test_authenticator (void)
160 struct test_case tests
[] = {
162 "\x62\x3d\x30\x3b\xa0\x03\x02\x01\x05\xa1\x0a\x1b\x08"
163 "\x45\x2e\x4b\x54\x48\x2e\x53\x45\xa2\x10\x30\x0e\xa0"
164 "\x03\x02\x01\x01\xa1\x07\x30\x05\x1b\x03\x6c\x68\x61"
165 "\xa4\x03\x02\x01\x0a\xa5\x11\x18\x0f\x31\x39\x37\x30"
166 "\x30\x31\x30\x31\x30\x30\x30\x31\x33\x39\x5a"
169 "\x62\x41\x30\x3f\xa0\x03\x02\x01\x05\xa1\x07\x1b\x05"
170 "\x53\x55\x2e\x53\x45\xa2\x16\x30\x14\xa0\x03\x02\x01"
171 "\x01\xa1\x0d\x30\x0b\x1b\x03\x6c\x68\x61\x1b\x04\x72"
172 "\x6f\x6f\x74\xa4\x04\x02\x02\x01\x24\xa5\x11\x18\x0f"
173 "\x31\x39\x37\x30\x30\x31\x30\x31\x30\x30\x31\x36\x33"
178 Authenticator values
[] = {
179 { 5, "E.KTH.SE", { KRB5_NT_PRINCIPAL
, { 1, lha_principal
} },
180 NULL
, 10, 99, NULL
, NULL
, NULL
},
181 { 5, "SU.SE", { KRB5_NT_PRINCIPAL
, { 2, lharoot_princ
} },
182 NULL
, 292, 999, NULL
, NULL
, NULL
}
185 int ntests
= sizeof(tests
) / sizeof(*tests
);
187 for (i
= 0; i
< ntests
; ++i
) {
188 tests
[i
].val
= &values
[i
];
189 asprintf (&tests
[i
].name
, "Authenticator %d", i
);
192 return generic_test (tests
, ntests
, sizeof(Authenticator
),
193 (generic_encode
)encode_Authenticator
,
194 (generic_length
)length_Authenticator
,
195 (generic_decode
)decode_Authenticator
,
196 (generic_free
)free_Authenticator
,
201 cmp_KRB_ERROR (void *a
, void *b
)
207 COMPARE_INTEGER(aa
,ab
,pvno
);
208 COMPARE_INTEGER(aa
,ab
,msg_type
);
210 IF_OPT_COMPARE(aa
,ab
,ctime
) {
211 COMPARE_INTEGER(aa
,ab
,ctime
);
213 IF_OPT_COMPARE(aa
,ab
,cusec
) {
214 COMPARE_INTEGER(aa
,ab
,cusec
);
216 COMPARE_INTEGER(aa
,ab
,stime
);
217 COMPARE_INTEGER(aa
,ab
,susec
);
218 COMPARE_INTEGER(aa
,ab
,error_code
);
220 IF_OPT_COMPARE(aa
,ab
,crealm
) {
221 COMPARE_OPT_STRING(aa
,ab
,crealm
);
224 IF_OPT_COMPARE(aa
,ab
,cname
) {
225 COMPARE_OPT_STRING(aa
,ab
,cname
);
228 COMPARE_STRING(aa
,ab
,realm
);
230 COMPARE_INTEGER(aa
,ab
,sname
.name_string
.len
);
231 for (i
= 0; i
< aa
->sname
.name_string
.len
; i
++)
232 COMPARE_STRING(aa
,ab
,sname
.name_string
.val
[i
]);
234 IF_OPT_COMPARE(aa
,ab
,e_text
) {
235 COMPARE_OPT_STRING(aa
,ab
,e_text
);
237 IF_OPT_COMPARE(aa
,ab
,e_data
) {
238 /* COMPARE_OPT_OCTECT_STRING(aa,ab,e_data); */
245 test_krb_error (void)
247 struct test_case tests
[] = {
249 "\x7e\x7d\x30\x7b\xa0\x03\x02\x01\x05\xa1\x03\x02\x01\x1e\xa4\x11"
250 "\x18\x0f\x32\x30\x30\x33\x31\x31\x32\x34\x30\x30\x31\x31\x31\x39"
251 "\x5a\xa5\x05\x02\x03\x04\xed\xa5\xa6\x03\x02\x01\x1f\xa7\x0d\x1b"
252 "\x0b\x4e\x41\x44\x41\x2e\x4b\x54\x48\x2e\x53\x45\xa8\x10\x30\x0e"
253 "\xa0\x03\x02\x01\x01\xa1\x07\x30\x05\x1b\x03\x6c\x68\x61\xa9\x0d"
254 "\x1b\x0b\x4e\x41\x44\x41\x2e\x4b\x54\x48\x2e\x53\x45\xaa\x20\x30"
255 "\x1e\xa0\x03\x02\x01\x01\xa1\x17\x30\x15\x1b\x06\x6b\x72\x62\x74"
256 "\x67\x74\x1b\x0b\x4e\x41\x44\x41\x2e\x4b\x54\x48\x2e\x53\x45",
260 int ntests
= sizeof(tests
) / sizeof(*tests
);
262 PrincipalName lhaprincipalname
= { 1, { 1, lha_principal
} };
263 PrincipalName tgtprincipalname
= { 1, { 2, nada_tgt_principal
} };
264 char *realm
= "NADA.KTH.SE";
270 e1
.stime
= 1069632679;
274 e1
.cname
= &lhaprincipalname
;
275 e1
.realm
= "NADA.KTH.SE";
276 e1
.sname
= tgtprincipalname
;
282 return generic_test (tests
, ntests
, sizeof(KRB_ERROR
),
283 (generic_encode
)encode_KRB_ERROR
,
284 (generic_length
)length_KRB_ERROR
,
285 (generic_decode
)decode_KRB_ERROR
,
286 (generic_free
)free_KRB_ERROR
,
291 cmp_Name (void *a
, void *b
)
296 COMPARE_INTEGER(aa
,ab
,element
);
304 struct test_case tests
[] = {
306 "\x30\x21\x31\x1f\x30\x0b\x06\x03\x55\x04\x03\x13\x04\x4c\x6f\x76"
307 "\x65\x30\x10\x06\x03\x55\x04\x07\x13\x09\x53\x54\x4f\x43\x4b\x48"
309 "Name CN=Love+L=STOCKHOLM"
312 "\x30\x21\x31\x1f\x30\x0b\x06\x03\x55\x04\x03\x13\x04\x4c\x6f\x76"
313 "\x65\x30\x10\x06\x03\x55\x04\x07\x13\x09\x53\x54\x4f\x43\x4b\x48"
315 "Name L=STOCKHOLM+CN=Love"
319 int ntests
= sizeof(tests
) / sizeof(*tests
);
321 RelativeDistinguishedName rdn1
[1];
322 RelativeDistinguishedName rdn2
[1];
323 AttributeTypeAndValue atv1
[2];
324 AttributeTypeAndValue atv2
[2];
325 unsigned cmp_CN
[] = { 2, 5, 4, 3 };
326 unsigned cmp_L
[] = { 2, 5, 4, 7 };
329 n1
.element
= choice_Name_rdnSequence
;
330 n1
.u
.rdnSequence
.val
= rdn1
;
331 n1
.u
.rdnSequence
.len
= sizeof(rdn1
)/sizeof(rdn1
[0]);
333 rdn1
[0].len
= sizeof(atv1
)/sizeof(atv1
[0]);
335 atv1
[0].type
.length
= sizeof(cmp_CN
)/sizeof(cmp_CN
[0]);
336 atv1
[0].type
.components
= cmp_CN
;
337 atv1
[0].value
.element
= choice_DirectoryString_printableString
;
338 atv1
[0].value
.u
.printableString
= "Love";
340 atv1
[1].type
.length
= sizeof(cmp_L
)/sizeof(cmp_L
[0]);
341 atv1
[1].type
.components
= cmp_L
;
342 atv1
[1].value
.element
= choice_DirectoryString_printableString
;
343 atv1
[1].value
.u
.printableString
= "STOCKHOLM";
346 n2
.element
= choice_Name_rdnSequence
;
347 n2
.u
.rdnSequence
.val
= rdn2
;
348 n2
.u
.rdnSequence
.len
= sizeof(rdn2
)/sizeof(rdn2
[0]);
350 rdn2
[0].len
= sizeof(atv2
)/sizeof(atv2
[0]);
352 atv2
[0].type
.length
= sizeof(cmp_L
)/sizeof(cmp_L
[0]);
353 atv2
[0].type
.components
= cmp_L
;
354 atv2
[0].value
.element
= choice_DirectoryString_printableString
;
355 atv2
[0].value
.u
.printableString
= "STOCKHOLM";
357 atv2
[1].type
.length
= sizeof(cmp_CN
)/sizeof(cmp_CN
[0]);
358 atv2
[1].type
.components
= cmp_CN
;
359 atv2
[1].value
.element
= choice_DirectoryString_printableString
;
360 atv2
[1].value
.u
.printableString
= "Love";
366 return generic_test (tests
, ntests
, sizeof(Name
),
367 (generic_encode
)encode_Name
,
368 (generic_length
)length_Name
,
369 (generic_decode
)decode_Name
,
370 (generic_free
)free_Name
,
375 cmp_KeyUsage (void *a
, void *b
)
380 return KeyUsage2int(*aa
) != KeyUsage2int(*ab
);
384 test_bit_string (void)
386 struct test_case tests
[] = {
396 "\x03\x03\x07\x00\x80",
405 int ntests
= sizeof(tests
) / sizeof(*tests
);
406 KeyUsage ku1
, ku2
, ku3
, ku4
;
408 memset(&ku1
, 0, sizeof(ku1
));
409 ku1
.digitalSignature
= 1;
412 memset(&ku2
, 0, sizeof(ku2
));
413 ku2
.digitalSignature
= 1;
414 ku2
.keyEncipherment
= 1;
417 memset(&ku3
, 0, sizeof(ku3
));
418 ku3
.decipherOnly
= 1;
421 memset(&ku4
, 0, sizeof(ku4
));
425 return generic_test (tests
, ntests
, sizeof(KeyUsage
),
426 (generic_encode
)encode_KeyUsage
,
427 (generic_length
)length_KeyUsage
,
428 (generic_decode
)decode_KeyUsage
,
429 (generic_free
)free_KeyUsage
,
434 cmp_TESTLargeTag (void *a
, void *b
)
436 TESTLargeTag
*aa
= a
;
437 TESTLargeTag
*ab
= b
;
439 COMPARE_INTEGER(aa
,ab
,foo
);
444 test_large_tag (void)
446 struct test_case tests
[] = {
447 { NULL
, 8, "\x30\x06\xbf\x7f\x03\x02\x01\x01", "large tag 1" }
450 int ntests
= sizeof(tests
) / sizeof(*tests
);
453 memset(<1
, 0, sizeof(lt1
));
458 return generic_test (tests
, ntests
, sizeof(TESTLargeTag
),
459 (generic_encode
)encode_TESTLargeTag
,
460 (generic_length
)length_TESTLargeTag
,
461 (generic_decode
)decode_TESTLargeTag
,
462 (generic_free
)free_TESTLargeTag
,
474 check_tag_length(void)
476 struct test_data td
[] = {
477 { 1, 3, 3, "\x02\x01\x00"},
478 { 1, 3, 3, "\x02\x01\x7f"},
479 { 1, 4, 4, "\x02\x02\x00\x80"},
480 { 1, 4, 4, "\x02\x02\x01\x00"},
481 { 1, 4, 4, "\x02\x02\x02\x00"},
482 { 0, 3, 0, "\x02\x02\x00"},
483 { 0, 3, 0, "\x02\x7f\x7f"},
484 { 0, 4, 0, "\x02\x03\x00\x80"},
485 { 0, 4, 0, "\x02\x7f\x01\x00"},
486 { 0, 5, 0, "\x02\xff\x7f\x02\x00"}
489 krb5uint32 values
[] = {0, 127, 128, 256, 512,
490 0, 127, 128, 256, 512 };
492 int i
, ret
, failed
= 0;
495 for (i
= 0; i
< sizeof(td
)/sizeof(td
[0]); i
++) {
496 struct map_page
*page
;
498 buf
= map_alloc(OVERRUN
, td
[i
].data
, td
[i
].len
, &page
);
500 ret
= decode_krb5uint32(buf
, td
[i
].len
, &u
, &sz
);
503 printf("failed with tag len test %d\n", i
);
508 printf("failed with success for tag len test %d\n", i
);
511 if (td
[i
].expected_len
!= sz
) {
512 printf("wrong expected size for tag test %d\n", i
);
515 if (values
[i
] != u
) {
516 printf("wrong value for tag test %d\n", i
);
520 map_free(page
, "test", "decode");
526 cmp_TESTChoice (void *a
, void *b
)
534 struct test_case tests
[] = {
535 { NULL
, 5, "\xa1\x03\x02\x01\x01", "large choice 1" },
536 { NULL
, 5, "\xa2\x03\x02\x01\x02", "large choice 2" }
539 int ret
= 0, ntests
= sizeof(tests
) / sizeof(*tests
);
544 memset(&c1
, 0, sizeof(c1
));
545 c1
.element
= choice_TESTChoice1_i1
;
549 memset(&c2_1
, 0, sizeof(c2_1
));
550 c2_1
.element
= choice_TESTChoice1_i2
;
552 tests
[1].val
= &c2_1
;
554 ret
+= generic_test (tests
, ntests
, sizeof(TESTChoice1
),
555 (generic_encode
)encode_TESTChoice1
,
556 (generic_length
)length_TESTChoice1
,
557 (generic_decode
)decode_TESTChoice1
,
558 (generic_free
)free_TESTChoice1
,
561 memset(&c2_2
, 0, sizeof(c2_2
));
562 c2_2
.element
= choice_TESTChoice2_asn1_ellipsis
;
563 c2_2
.u
.asn1_ellipsis
.data
= "\xa2\x03\x02\x01\x02";
564 c2_2
.u
.asn1_ellipsis
.length
= 5;
565 tests
[1].val
= &c2_2
;
567 ret
+= generic_test (tests
, ntests
, sizeof(TESTChoice2
),
568 (generic_encode
)encode_TESTChoice2
,
569 (generic_length
)length_TESTChoice2
,
570 (generic_decode
)decode_TESTChoice2
,
571 (generic_free
)free_TESTChoice2
,
578 cmp_TESTImplicit (void *a
, void *b
)
580 TESTImplicit
*aa
= a
;
581 TESTImplicit
*ab
= b
;
583 COMPARE_INTEGER(aa
,ab
,ti1
);
584 COMPARE_INTEGER(aa
,ab
,ti2
.foo
);
585 COMPARE_INTEGER(aa
,ab
,ti3
);
590 UNIV CONS Sequence 14
594 UNIV PRIM Integer 1 02
601 struct test_case tests
[] = {
603 "\x30\x0e\x80\x01\x00\xa1\x06\xbf"
604 "\x7f\x03\x02\x01\x02\x82\x01\x03",
608 int ret
= 0, ntests
= sizeof(tests
) / sizeof(*tests
);
611 memset(&c0
, 0, sizeof(c0
));
617 ret
+= generic_test (tests
, ntests
, sizeof(TESTImplicit
),
618 (generic_encode
)encode_TESTImplicit
,
619 (generic_length
)length_TESTImplicit
,
620 (generic_decode
)decode_TESTImplicit
,
621 (generic_free
)free_TESTImplicit
,
624 #ifdef IMPLICIT_TAGGING_WORKS
625 ret
+= generic_test (tests
, ntests
, sizeof(TESTImplicit2
),
626 (generic_encode
)encode_TESTImplicit2
,
627 (generic_length
)length_TESTImplicit2
,
628 (generic_decode
)decode_TESTImplicit2
,
629 (generic_free
)free_TESTImplicit2
,
632 #endif /* IMPLICIT_TAGGING_WORKS */
637 cmp_TESTAlloc (void *a
, void *b
)
642 IF_OPT_COMPARE(aa
,ab
,tagless
) {
643 COMPARE_INTEGER(aa
,ab
,tagless
->ai
);
646 COMPARE_INTEGER(aa
,ab
,three
);
648 IF_OPT_COMPARE(aa
,ab
,tagless2
) {
649 COMPARE_OPT_OCTECT_STRING(aa
, ab
, tagless2
);
656 UNIV CONS Sequence 12
659 UNIV PRIM Integer 1 01
661 UNIV PRIM Integer 1 03
665 UNIV PRIM Integer 1 03
669 UNIV PRIM Integer 1 04
670 UNIV PRIM Integer 1 05
675 test_taglessalloc (void)
677 struct test_case tests
[] = {
679 "\x30\x0c\x30\x05\xa0\x03\x02\x01\x01\xa1\x03\x02\x01\x03",
682 "\x30\x05\xa1\x03\x02\x01\x03",
685 "\x30\x08\xa1\x03\x02\x01\x04\x02\x01\x05",
689 int ret
= 0, ntests
= sizeof(tests
) / sizeof(*tests
);
690 TESTAlloc c1
, c2
, c3
;
693 memset(&c1
, 0, sizeof(c1
));
694 c1
.tagless
= ecalloc(1, sizeof(*c1
.tagless
));
699 memset(&c2
, 0, sizeof(c2
));
704 memset(&c3
, 0, sizeof(c3
));
708 any3
.data
= "\x02\x01\x05";
712 ret
+= generic_test (tests
, ntests
, sizeof(TESTAlloc
),
713 (generic_encode
)encode_TESTAlloc
,
714 (generic_length
)length_TESTAlloc
,
715 (generic_decode
)decode_TESTAlloc
,
716 (generic_free
)free_TESTAlloc
,
726 check_fail_largetag(void)
728 struct test_case tests
[] = {
729 {NULL
, 14, "\x30\x0c\xbf\x87\xff\xff\xff\xff\xff\x7f\x03\x02\x01\x01",
731 {NULL
, 0, "", "empty buffer"},
732 {NULL
, 7, "\x30\x05\xa1\x03\x02\x02\x01",
734 {NULL
, 7, "\x30\x04\xa1\x03\x02\x02\x01"
736 {NULL
, 7, "\x30\x03\xa1\x03\x02\x02\x01",
738 {NULL
, 7, "\x30\x02\xa1\x03\x02\x02\x01",
740 {NULL
, 7, "\x30\x01\xa1\x03\x02\x02\x01",
742 {NULL
, 7, "\x30\x00\xa1\x03\x02\x02\x01",
744 {NULL
, 7, "\x30\x05\xa1\x04\x02\x02\x01",
745 "inner one too long" },
746 {NULL
, 7, "\x30\x00\xa1\x02\x02\x02\x01",
747 "inner one too short" },
748 {NULL
, 8, "\x30\x05\xbf\x7f\x03\x02\x02\x01",
749 "inner one too short"},
750 {NULL
, 8, "\x30\x06\xbf\x64\x03\x02\x01\x01",
752 {NULL
, 10, "\x30\x08\xbf\x9a\x9b\x38\x03\x02\x01\x01",
755 int ntests
= sizeof(tests
) / sizeof(*tests
);
757 return generic_decode_fail(tests
, ntests
, sizeof(TESTLargeTag
),
758 (generic_decode
)decode_TESTLargeTag
);
763 check_fail_sequence(void)
765 struct test_case tests
[] = {
766 {NULL
, 0, "", "empty buffer"},
768 "\x30\x16\xa0\x03\x02\x01\x01\xa1\x08\x30\x06\xbf\x7f\x03\x02\x01\x01"
769 "\x02\x01\x01\xa2\x03\x02\x01\x01"
770 "missing one byte from the end, internal length ok"},
772 "\x30\x18\xa0\x03\x02\x01\x01\xa1\x08\x30\x06\xbf\x7f\x03\x02\x01\x01"
773 "\x02\x01\x01\xa2\x03\x02\x01\x01",
774 "inner length one byte too long"},
776 "\x30\x17\xa0\x03\x02\x01\x01\xa1\x08\x30\x06\xbf\x7f\x03\x02\x01"
777 "\x01\x02\x01\x01\xa2\x03\x02\x01\x01",
778 "correct buffer but missing one too short"}
780 int ntests
= sizeof(tests
) / sizeof(*tests
);
782 return generic_decode_fail(tests
, ntests
, sizeof(TESTSeq
),
783 (generic_decode
)decode_TESTSeq
);
787 check_fail_choice(void)
789 struct test_case tests
[] = {
791 "\xa1\x02\x02\x01\x01",
794 "\xa1\x03\x02\x02\x01",
795 "one too short inner"}
797 int ntests
= sizeof(tests
) / sizeof(*tests
);
799 return generic_decode_fail(tests
, ntests
, sizeof(TESTChoice1
),
800 (generic_decode
)decode_TESTChoice1
);
813 ret
= add_TESTSeqOf(&seq
, &i
);
814 if (ret
) { printf("failed adding\n"); goto out
; }
815 ret
= add_TESTSeqOf(&seq
, &i
);
816 if (ret
) { printf("failed adding\n"); goto out
; }
817 ret
= add_TESTSeqOf(&seq
, &i
);
818 if (ret
) { printf("failed adding\n"); goto out
; }
819 ret
= add_TESTSeqOf(&seq
, &i
);
820 if (ret
) { printf("failed adding\n"); goto out
; }
822 ret
= remove_TESTSeqOf(&seq
, seq
.len
- 1);
823 if (ret
) { printf("failed removing\n"); goto out
; }
824 ret
= remove_TESTSeqOf(&seq
, 2);
825 if (ret
) { printf("failed removing\n"); goto out
; }
826 ret
= remove_TESTSeqOf(&seq
, 0);
827 if (ret
) { printf("failed removing\n"); goto out
; }
828 ret
= remove_TESTSeqOf(&seq
, 0);
829 if (ret
) { printf("failed removing\n"); goto out
; }
830 ret
= remove_TESTSeqOf(&seq
, 0);
832 printf("can remove from empty list");
837 printf("seq not empty!");
849 main(int argc
, char **argv
)
853 ret
+= test_principal ();
854 ret
+= test_authenticator();
855 ret
+= test_krb_error();
857 ret
+= test_bit_string();
859 ret
+= check_tag_length();
860 ret
+= test_large_tag();
861 ret
+= test_choice();
863 ret
+= test_implicit();
864 ret
+= test_taglessalloc();
866 ret
+= check_fail_largetag();
867 ret
+= check_fail_sequence();
868 ret
+= check_fail_choice();