2 * Copyright (c) 1999 - 2005 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 #include <asn1-common.h>
47 #include <krb5_asn1.h>
48 #include <heim_asn1.h>
49 #include <rfc2459_asn1.h>
50 #include <test_asn1.h>
52 #include "check-common.h"
56 static char *lha_principal
[] = { "lha" };
57 static char *lharoot_princ
[] = { "lha", "root" };
58 static char *datan_princ
[] = { "host", "nutcracker.e.kth.se" };
59 static char *nada_tgt_principal
[] = { "krbtgt", "NADA.KTH.SE" };
62 #define IF_OPT_COMPARE(ac,bc,e) \
63 if (((ac)->e == NULL && (bc)->e != NULL) || (((ac)->e != NULL && (bc)->e == NULL))) return 1; if ((ab)->e)
64 #define COMPARE_OPT_STRING(ac,bc,e) \
65 do { if (strcmp(*(ac)->e, *(bc)->e) != 0) return 1; } while(0)
66 #define COMPARE_OPT_OCTECT_STRING(ac,bc,e) \
67 do { if ((ac)->e->length != (bc)->e->length || memcmp((ac)->e->data, (bc)->e->data, (ac)->e->length) != 0) return 1; } while(0)
68 #define COMPARE_STRING(ac,bc,e) \
69 do { if (strcmp((ac)->e, (bc)->e) != 0) return 1; } while(0)
70 #define COMPARE_INTEGER(ac,bc,e) \
71 do { if ((ac)->e != (bc)->e) return 1; } while(0)
72 #define COMPARE_OPT_INTEGER(ac,bc,e) \
73 do { if (*(ac)->e != *(bc)->e) return 1; } while(0)
74 #define COMPARE_MEM(ac,bc,e,len) \
75 do { if (memcmp((ac)->e, (bc)->e,len) != 0) return 1; } while(0)
78 cmp_principal (void *a
, void *b
)
84 COMPARE_STRING(pa
,pb
,realm
);
85 COMPARE_INTEGER(pa
,pb
,name
.name_type
);
86 COMPARE_INTEGER(pa
,pb
,name
.name_string
.len
);
88 for (i
= 0; i
< pa
->name
.name_string
.len
; i
++)
89 COMPARE_STRING(pa
,pb
,name
.name_string
.val
[i
]);
98 struct test_case tests
[] = {
100 "\x30\x1b\xa0\x10\x30\x0e\xa0\x03\x02\x01\x01\xa1\x07\x30\x05\x1b"
101 "\x03\x6c\x68\x61\xa1\x07\x1b\x05\x53\x55\x2e\x53\x45",
105 "\x30\x21\xa0\x16\x30\x14\xa0\x03\x02\x01\x01\xa1\x0d\x30\x0b\x1b"
106 "\x03\x6c\x68\x61\x1b\x04\x72\x6f\x6f\x74\xa1\x07\x1b\x05\x53\x55"
111 "\x30\x34\xa0\x26\x30\x24\xa0\x03\x02\x01\x03\xa1\x1d\x30\x1b\x1b"
112 "\x04\x68\x6f\x73\x74\x1b\x13\x6e\x75\x74\x63\x72\x61\x63\x6b\x65"
113 "\x72\x2e\x65\x2e\x6b\x74\x68\x2e\x73\x65\xa1\x0a\x1b\x08\x45\x2e"
114 "\x4b\x54\x48\x2e\x53\x45",
120 Principal values
[] = {
121 { { KRB5_NT_PRINCIPAL
, { 1, lha_principal
} }, "SU.SE" },
122 { { KRB5_NT_PRINCIPAL
, { 2, lharoot_princ
} }, "SU.SE" },
123 { { KRB5_NT_SRV_HST
, { 2, datan_princ
} }, "E.KTH.SE" }
126 int ntests
= sizeof(tests
) / sizeof(*tests
);
128 for (i
= 0; i
< ntests
; ++i
) {
129 tests
[i
].val
= &values
[i
];
130 if (asprintf (&tests
[i
].name
, "Principal %d", i
) < 0)
132 if (tests
[i
].name
== NULL
)
136 ret
= generic_test (tests
, ntests
, sizeof(Principal
),
137 (generic_encode
)encode_Principal
,
138 (generic_length
)length_Principal
,
139 (generic_decode
)decode_Principal
,
140 (generic_free
)free_Principal
,
143 for (i
= 0; i
< ntests
; ++i
)
144 free (tests
[i
].name
);
150 cmp_authenticator (void *a
, void *b
)
152 Authenticator
*aa
= a
;
153 Authenticator
*ab
= b
;
156 COMPARE_INTEGER(aa
,ab
,authenticator_vno
);
157 COMPARE_STRING(aa
,ab
,crealm
);
159 COMPARE_INTEGER(aa
,ab
,cname
.name_type
);
160 COMPARE_INTEGER(aa
,ab
,cname
.name_string
.len
);
162 for (i
= 0; i
< aa
->cname
.name_string
.len
; i
++)
163 COMPARE_STRING(aa
,ab
,cname
.name_string
.val
[i
]);
169 test_authenticator (void)
171 struct test_case tests
[] = {
173 "\x62\x3d\x30\x3b\xa0\x03\x02\x01\x05\xa1\x0a\x1b\x08"
174 "\x45\x2e\x4b\x54\x48\x2e\x53\x45\xa2\x10\x30\x0e\xa0"
175 "\x03\x02\x01\x01\xa1\x07\x30\x05\x1b\x03\x6c\x68\x61"
176 "\xa4\x03\x02\x01\x0a\xa5\x11\x18\x0f\x31\x39\x37\x30"
177 "\x30\x31\x30\x31\x30\x30\x30\x31\x33\x39\x5a",
181 "\x62\x41\x30\x3f\xa0\x03\x02\x01\x05\xa1\x07\x1b\x05"
182 "\x53\x55\x2e\x53\x45\xa2\x16\x30\x14\xa0\x03\x02\x01"
183 "\x01\xa1\x0d\x30\x0b\x1b\x03\x6c\x68\x61\x1b\x04\x72"
184 "\x6f\x6f\x74\xa4\x04\x02\x02\x01\x24\xa5\x11\x18\x0f"
185 "\x31\x39\x37\x30\x30\x31\x30\x31\x30\x30\x31\x36\x33"
191 Authenticator values
[] = {
192 { 5, "E.KTH.SE", { KRB5_NT_PRINCIPAL
, { 1, lha_principal
} },
193 NULL
, 10, 99, NULL
, NULL
, NULL
},
194 { 5, "SU.SE", { KRB5_NT_PRINCIPAL
, { 2, lharoot_princ
} },
195 NULL
, 292, 999, NULL
, NULL
, NULL
}
198 int ntests
= sizeof(tests
) / sizeof(*tests
);
200 for (i
= 0; i
< ntests
; ++i
) {
201 tests
[i
].val
= &values
[i
];
202 if (asprintf (&tests
[i
].name
, "Authenticator %d", i
) < 0)
204 if (tests
[i
].name
== NULL
)
208 ret
= generic_test (tests
, ntests
, sizeof(Authenticator
),
209 (generic_encode
)encode_Authenticator
,
210 (generic_length
)length_Authenticator
,
211 (generic_decode
)decode_Authenticator
,
212 (generic_free
)free_Authenticator
,
214 (generic_copy
)copy_Authenticator
);
215 for (i
= 0; i
< ntests
; ++i
)
222 cmp_KRB_ERROR (void *a
, void *b
)
228 COMPARE_INTEGER(aa
,ab
,pvno
);
229 COMPARE_INTEGER(aa
,ab
,msg_type
);
231 IF_OPT_COMPARE(aa
,ab
,ctime
) {
232 COMPARE_INTEGER(aa
,ab
,ctime
);
234 IF_OPT_COMPARE(aa
,ab
,cusec
) {
235 COMPARE_INTEGER(aa
,ab
,cusec
);
237 COMPARE_INTEGER(aa
,ab
,stime
);
238 COMPARE_INTEGER(aa
,ab
,susec
);
239 COMPARE_INTEGER(aa
,ab
,error_code
);
241 IF_OPT_COMPARE(aa
,ab
,crealm
) {
242 COMPARE_OPT_STRING(aa
,ab
,crealm
);
245 IF_OPT_COMPARE(aa
,ab
,cname
) {
246 COMPARE_OPT_STRING(aa
,ab
,cname
);
249 COMPARE_STRING(aa
,ab
,realm
);
251 COMPARE_INTEGER(aa
,ab
,sname
.name_string
.len
);
252 for (i
= 0; i
< aa
->sname
.name_string
.len
; i
++)
253 COMPARE_STRING(aa
,ab
,sname
.name_string
.val
[i
]);
255 IF_OPT_COMPARE(aa
,ab
,e_text
) {
256 COMPARE_OPT_STRING(aa
,ab
,e_text
);
258 IF_OPT_COMPARE(aa
,ab
,e_data
) {
259 /* COMPARE_OPT_OCTECT_STRING(aa,ab,e_data); */
266 test_krb_error (void)
268 struct test_case tests
[] = {
270 "\x7e\x7d\x30\x7b\xa0\x03\x02\x01\x05\xa1\x03\x02\x01\x1e\xa4\x11"
271 "\x18\x0f\x32\x30\x30\x33\x31\x31\x32\x34\x30\x30\x31\x31\x31\x39"
272 "\x5a\xa5\x05\x02\x03\x04\xed\xa5\xa6\x03\x02\x01\x1f\xa7\x0d\x1b"
273 "\x0b\x4e\x41\x44\x41\x2e\x4b\x54\x48\x2e\x53\x45\xa8\x10\x30\x0e"
274 "\xa0\x03\x02\x01\x01\xa1\x07\x30\x05\x1b\x03\x6c\x68\x61\xa9\x0d"
275 "\x1b\x0b\x4e\x41\x44\x41\x2e\x4b\x54\x48\x2e\x53\x45\xaa\x20\x30"
276 "\x1e\xa0\x03\x02\x01\x01\xa1\x17\x30\x15\x1b\x06\x6b\x72\x62\x74"
277 "\x67\x74\x1b\x0b\x4e\x41\x44\x41\x2e\x4b\x54\x48\x2e\x53\x45",
281 int ntests
= sizeof(tests
) / sizeof(*tests
);
283 PrincipalName lhaprincipalname
= { 1, { 1, lha_principal
} };
284 PrincipalName tgtprincipalname
= { 1, { 2, nada_tgt_principal
} };
285 char *realm
= "NADA.KTH.SE";
291 e1
.stime
= 1069632679;
295 e1
.cname
= &lhaprincipalname
;
296 e1
.realm
= "NADA.KTH.SE";
297 e1
.sname
= tgtprincipalname
;
303 return generic_test (tests
, ntests
, sizeof(KRB_ERROR
),
304 (generic_encode
)encode_KRB_ERROR
,
305 (generic_length
)length_KRB_ERROR
,
306 (generic_decode
)decode_KRB_ERROR
,
307 (generic_free
)free_KRB_ERROR
,
309 (generic_copy
)copy_KRB_ERROR
);
313 cmp_Name (void *a
, void *b
)
318 COMPARE_INTEGER(aa
,ab
,element
);
326 struct test_case tests
[] = {
328 "\x30\x21\x31\x1f\x30\x0b\x06\x03\x55\x04\x03\x13\x04\x4c\x6f\x76"
329 "\x65\x30\x10\x06\x03\x55\x04\x07\x13\x09\x53\x54\x4f\x43\x4b\x48"
331 "Name CN=Love+L=STOCKHOLM"
334 "\x30\x21\x31\x1f\x30\x0b\x06\x03\x55\x04\x03\x13\x04\x4c\x6f\x76"
335 "\x65\x30\x10\x06\x03\x55\x04\x07\x13\x09\x53\x54\x4f\x43\x4b\x48"
337 "Name L=STOCKHOLM+CN=Love"
341 int ntests
= sizeof(tests
) / sizeof(*tests
);
343 RelativeDistinguishedName rdn1
[1];
344 RelativeDistinguishedName rdn2
[1];
345 AttributeTypeAndValue atv1
[2];
346 AttributeTypeAndValue atv2
[2];
347 unsigned cmp_CN
[] = { 2, 5, 4, 3 };
348 unsigned cmp_L
[] = { 2, 5, 4, 7 };
351 n1
.element
= choice_Name_rdnSequence
;
352 n1
.u
.rdnSequence
.val
= rdn1
;
353 n1
.u
.rdnSequence
.len
= sizeof(rdn1
)/sizeof(rdn1
[0]);
355 rdn1
[0].len
= sizeof(atv1
)/sizeof(atv1
[0]);
357 atv1
[0].type
.length
= sizeof(cmp_CN
)/sizeof(cmp_CN
[0]);
358 atv1
[0].type
.components
= cmp_CN
;
359 atv1
[0].value
.element
= choice_DirectoryString_printableString
;
360 atv1
[0].value
.u
.printableString
.data
= "Love";
361 atv1
[0].value
.u
.printableString
.length
= 4;
363 atv1
[1].type
.length
= sizeof(cmp_L
)/sizeof(cmp_L
[0]);
364 atv1
[1].type
.components
= cmp_L
;
365 atv1
[1].value
.element
= choice_DirectoryString_printableString
;
366 atv1
[1].value
.u
.printableString
.data
= "STOCKHOLM";
367 atv1
[1].value
.u
.printableString
.length
= 9;
370 n2
.element
= choice_Name_rdnSequence
;
371 n2
.u
.rdnSequence
.val
= rdn2
;
372 n2
.u
.rdnSequence
.len
= sizeof(rdn2
)/sizeof(rdn2
[0]);
374 rdn2
[0].len
= sizeof(atv2
)/sizeof(atv2
[0]);
376 atv2
[0].type
.length
= sizeof(cmp_L
)/sizeof(cmp_L
[0]);
377 atv2
[0].type
.components
= cmp_L
;
378 atv2
[0].value
.element
= choice_DirectoryString_printableString
;
379 atv2
[0].value
.u
.printableString
.data
= "STOCKHOLM";
380 atv2
[0].value
.u
.printableString
.length
= 9;
382 atv2
[1].type
.length
= sizeof(cmp_CN
)/sizeof(cmp_CN
[0]);
383 atv2
[1].type
.components
= cmp_CN
;
384 atv2
[1].value
.element
= choice_DirectoryString_printableString
;
385 atv2
[1].value
.u
.printableString
.data
= "Love";
386 atv2
[1].value
.u
.printableString
.length
= 4;
392 return generic_test (tests
, ntests
, sizeof(Name
),
393 (generic_encode
)encode_Name
,
394 (generic_length
)length_Name
,
395 (generic_decode
)decode_Name
,
396 (generic_free
)free_Name
,
398 (generic_copy
)copy_Name
);
402 cmp_KeyUsage (void *a
, void *b
)
407 return KeyUsage2int(*aa
) != KeyUsage2int(*ab
);
411 test_bit_string (void)
413 struct test_case tests
[] = {
423 "\x03\x03\x07\x00\x80",
432 int ntests
= sizeof(tests
) / sizeof(*tests
);
433 KeyUsage ku1
, ku2
, ku3
, ku4
;
435 memset(&ku1
, 0, sizeof(ku1
));
436 ku1
.digitalSignature
= 1;
439 memset(&ku2
, 0, sizeof(ku2
));
440 ku2
.digitalSignature
= 1;
441 ku2
.keyEncipherment
= 1;
444 memset(&ku3
, 0, sizeof(ku3
));
445 ku3
.decipherOnly
= 1;
448 memset(&ku4
, 0, sizeof(ku4
));
452 return generic_test (tests
, ntests
, sizeof(KeyUsage
),
453 (generic_encode
)encode_KeyUsage
,
454 (generic_length
)length_KeyUsage
,
455 (generic_decode
)decode_KeyUsage
,
456 (generic_free
)free_KeyUsage
,
458 (generic_copy
)copy_KeyUsage
);
462 cmp_TicketFlags (void *a
, void *b
)
467 return TicketFlags2int(*aa
) != TicketFlags2int(*ab
);
471 test_bit_string_rfc1510 (void)
473 struct test_case tests
[] = {
475 "\x03\x05\x00\x80\x00\x00\x00",
479 "\x03\x05\x00\x40\x20\x00\x00",
483 "\x03\x05\x00\x00\x20\x00\x00",
487 "\x03\x05\x00\x00\x00\x00\x00",
492 int ntests
= sizeof(tests
) / sizeof(*tests
);
493 TicketFlags tf1
, tf2
, tf3
, tf4
;
495 memset(&tf1
, 0, sizeof(tf1
));
499 memset(&tf2
, 0, sizeof(tf2
));
504 memset(&tf3
, 0, sizeof(tf3
));
508 memset(&tf4
, 0, sizeof(tf4
));
512 return generic_test (tests
, ntests
, sizeof(TicketFlags
),
513 (generic_encode
)encode_TicketFlags
,
514 (generic_length
)length_TicketFlags
,
515 (generic_decode
)decode_TicketFlags
,
516 (generic_free
)free_TicketFlags
,
518 (generic_copy
)copy_TicketFlags
);
522 cmp_KerberosTime (void *a
, void *b
)
524 KerberosTime
*aa
= a
;
525 KerberosTime
*ab
= b
;
533 struct test_case tests
[] = {
535 "\x18\x0f\x31\x39\x37\x30\x30\x31\x30\x31\x30\x31\x31\x38\x33\x31"
539 "\x18\x0f\x32\x30\x30\x39\x30\x35\x32\x34\x30\x32\x30\x32\x34\x30"
544 int ntests
= sizeof(tests
) / sizeof(*tests
);
545 KerberosTime times
[] = {
550 tests
[0].val
= ×
[0];
551 tests
[1].val
= ×
[1];
553 return generic_test (tests
, ntests
, sizeof(KerberosTime
),
554 (generic_encode
)encode_KerberosTime
,
555 (generic_length
)length_KerberosTime
,
556 (generic_decode
)decode_KerberosTime
,
557 (generic_free
)free_KerberosTime
,
559 (generic_copy
)copy_KerberosTime
);
567 "\x30\x82\x02\x6c\x30\x82\x01\xd5\xa0\x03\x02\x01\x02\x02\x09\x00"
568 "\x99\x32\xde\x61\x0e\x40\x19\x8a\x30\x0d\x06\x09\x2a\x86\x48\x86"
569 "\xf7\x0d\x01\x01\x05\x05\x00\x30\x2a\x31\x1b\x30\x19\x06\x03\x55"
570 "\x04\x03\x0c\x12\x68\x78\x35\x30\x39\x20\x54\x65\x73\x74\x20\x52"
571 "\x6f\x6f\x74\x20\x43\x41\x31\x0b\x30\x09\x06\x03\x55\x04\x06\x13"
572 "\x02\x53\x45\x30\x1e\x17\x0d\x30\x39\x30\x34\x32\x36\x32\x30\x32"
573 "\x39\x34\x30\x5a\x17\x0d\x31\x39\x30\x34\x32\x34\x32\x30\x32\x39"
574 "\x34\x30\x5a\x30\x2a\x31\x1b\x30\x19\x06\x03\x55\x04\x03\x0c\x12"
575 "\x68\x78\x35\x30\x39\x20\x54\x65\x73\x74\x20\x52\x6f\x6f\x74\x20"
576 "\x43\x41\x31\x0b\x30\x09\x06\x03\x55\x04\x06\x13\x02\x53\x45\x30"
577 "\x81\x9f\x30\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x01\x05"
578 "\x00\x03\x81\x8d\x00\x30\x81\x89\x02\x81\x81\x00\xb9\xd3\x1b\x67"
579 "\x1c\xf7\x5e\x26\x81\x3b\x82\xff\x03\xa4\x43\xb5\xb2\x63\x0b\x89"
580 "\x58\x43\xfe\x3d\xe0\x38\x7d\x93\x74\xbb\xad\x21\xa4\x29\xd9\x34"
581 "\x79\xf3\x1c\x8c\x5a\xd6\xb0\xd7\x19\xea\xcc\xaf\xe0\xa8\x40\x02"
582 "\x1d\x91\xf1\xac\x36\xb0\xfb\x08\xbd\xcc\x9a\xe1\xb7\x6e\xee\x0a"
583 "\x69\xbf\x6d\x2b\xee\x20\x82\x61\x06\xf2\x18\xcc\x89\x11\x64\x7e"
584 "\xb2\xff\x47\xd1\x3b\x52\x73\xeb\x5a\xc0\x03\xa6\x4b\xc7\x40\x7e"
585 "\xbc\xe1\x0e\x65\x44\x3f\x40\x8b\x02\x82\x54\x04\xd9\xcc\x2c\x67"
586 "\x01\xb6\x16\x82\xd8\x33\x53\x17\xd7\xde\x8d\x5d\x02\x03\x01\x00"
587 "\x01\xa3\x81\x99\x30\x81\x96\x30\x1d\x06\x03\x55\x1d\x0e\x04\x16"
588 "\x04\x14\x6e\x48\x13\xdc\xbf\x8b\x95\x4c\x13\xf3\x1f\x97\x30\xdd"
589 "\x27\x96\x59\x9b\x0e\x68\x30\x5a\x06\x03\x55\x1d\x23\x04\x53\x30"
590 "\x51\x80\x14\x6e\x48\x13\xdc\xbf\x8b\x95\x4c\x13\xf3\x1f\x97\x30"
591 "\xdd\x27\x96\x59\x9b\x0e\x68\xa1\x2e\xa4\x2c\x30\x2a\x31\x1b\x30"
592 "\x19\x06\x03\x55\x04\x03\x0c\x12\x68\x78\x35\x30\x39\x20\x54\x65"
593 "\x73\x74\x20\x52\x6f\x6f\x74\x20\x43\x41\x31\x0b\x30\x09\x06\x03"
594 "\x55\x04\x06\x13\x02\x53\x45\x82\x09\x00\x99\x32\xde\x61\x0e\x40"
595 "\x19\x8a\x30\x0c\x06\x03\x55\x1d\x13\x04\x05\x30\x03\x01\x01\xff"
596 "\x30\x0b\x06\x03\x55\x1d\x0f\x04\x04\x03\x02\x01\xe6\x30\x0d\x06"
597 "\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x05\x05\x00\x03\x81\x81\x00"
598 "\x52\x9b\xe4\x0e\xee\xc2\x5d\xb7\xf1\xba\x47\xe3\xfe\xaf\x3d\x51"
599 "\x10\xfd\xe8\x0d\x14\x58\x05\x36\xa7\xeb\xd8\x05\xe5\x27\x6f\x51"
600 "\xb8\xec\x90\xd9\x03\xe1\xbc\x9c\x93\x38\x21\x5c\xaf\x4e\x6c\x7b"
601 "\x6c\x65\xa9\x92\xcd\x94\xef\xa8\xae\x90\x12\x14\x78\x2d\xa3\x15"
602 "\xaa\x42\xf1\xd9\x44\x64\x2c\x3c\xc0\xbd\x3a\x48\xd8\x80\x45\x8b"
603 "\xd1\x79\x82\xe0\x0f\xdf\x08\x3c\x60\x21\x6f\x31\x47\x98\xae\x2f"
604 "\xcb\xb1\xa1\xb9\xc1\xa3\x71\x5e\x4a\xc2\x67\xdf\x66\x0a\x51\xb5"
605 "\xad\x60\x05\xdb\x02\xd4\x1a\xd2\xb9\x4e\x01\x08\x2b\xc3\x57\xaf",
608 "\x30\x82\x02\x54\x30\x82\x01\xbd\xa0\x03\x02\x01\x02\x02\x01\x08"
609 "\x30\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x05\x05\x00\x30"
610 "\x2a\x31\x1b\x30\x19\x06\x03\x55\x04\x03\x0c\x12\x68\x78\x35\x30"
611 "\x39\x20\x54\x65\x73\x74\x20\x52\x6f\x6f\x74\x20\x43\x41\x31\x0b"
612 "\x30\x09\x06\x03\x55\x04\x06\x13\x02\x53\x45\x30\x1e\x17\x0d\x30"
613 "\x39\x30\x34\x32\x36\x32\x30\x32\x39\x34\x30\x5a\x17\x0d\x31\x39"
614 "\x30\x34\x32\x34\x32\x30\x32\x39\x34\x30\x5a\x30\x1b\x31\x0b\x30"
615 "\x09\x06\x03\x55\x04\x06\x13\x02\x53\x45\x31\x0c\x30\x0a\x06\x03"
616 "\x55\x04\x03\x0c\x03\x6b\x64\x63\x30\x81\x9f\x30\x0d\x06\x09\x2a"
617 "\x86\x48\x86\xf7\x0d\x01\x01\x01\x05\x00\x03\x81\x8d\x00\x30\x81"
618 "\x89\x02\x81\x81\x00\xd2\x41\x7a\xf8\x4b\x55\xb2\xaf\x11\xf9\x43"
619 "\x9b\x43\x81\x09\x3b\x9a\x94\xcf\x00\xf4\x85\x75\x92\xd7\x2a\xa5"
620 "\x11\xf1\xa8\x50\x6e\xc6\x84\x74\x24\x17\xda\x84\xc8\x03\x37\xb2"
621 "\x20\xf3\xba\xb5\x59\x36\x21\x4d\xab\x70\xe2\xc3\x09\x93\x68\x14"
622 "\x12\x79\xc5\xbb\x9e\x1b\x4a\xf0\xc6\x24\x59\x25\xc3\x1c\xa8\x70"
623 "\x66\x5b\x3e\x41\x8e\xe3\x25\x71\x9a\x94\xa0\x5b\x46\x91\x6f\xdd"
624 "\x58\x14\xec\x89\xe5\x8c\x96\xc5\x38\x60\xe4\xab\xf2\x75\xee\x6e"
625 "\x62\xfc\xe1\xbd\x03\x47\xff\xc4\xbe\x0f\xca\x70\x73\xe3\x74\x58"
626 "\x3a\x2f\x04\x2d\x39\x02\x03\x01\x00\x01\xa3\x81\x98\x30\x81\x95"
627 "\x30\x09\x06\x03\x55\x1d\x13\x04\x02\x30\x00\x30\x0b\x06\x03\x55"
628 "\x1d\x0f\x04\x04\x03\x02\x05\xe0\x30\x12\x06\x03\x55\x1d\x25\x04"
629 "\x0b\x30\x09\x06\x07\x2b\x06\x01\x05\x02\x03\x05\x30\x1d\x06\x03"
630 "\x55\x1d\x0e\x04\x16\x04\x14\x3a\xd3\x73\xff\xab\xdb\x7d\x8d\xc6"
631 "\x3a\xa2\x26\x3e\xae\x78\x95\x80\xc9\xe6\x31\x30\x48\x06\x03\x55"
632 "\x1d\x11\x04\x41\x30\x3f\xa0\x3d\x06\x06\x2b\x06\x01\x05\x02\x02"
633 "\xa0\x33\x30\x31\xa0\x0d\x1b\x0b\x54\x45\x53\x54\x2e\x48\x35\x4c"
634 "\x2e\x53\x45\xa1\x20\x30\x1e\xa0\x03\x02\x01\x01\xa1\x17\x30\x15"
635 "\x1b\x06\x6b\x72\x62\x74\x67\x74\x1b\x0b\x54\x45\x53\x54\x2e\x48"
636 "\x35\x4c\x2e\x53\x45\x30\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01"
637 "\x01\x05\x05\x00\x03\x81\x81\x00\x83\xf4\x14\xa7\x6e\x59\xff\x80"
638 "\x64\xe7\xfa\xcf\x13\x80\x86\xe1\xed\x02\x38\xad\x96\x72\x25\xe5"
639 "\x06\x7a\x9a\xbc\x24\x74\xa9\x75\x55\xb2\x49\x80\x69\x45\x95\x4a"
640 "\x4c\x76\xa9\xe3\x4e\x49\xd3\xc2\x69\x5a\x95\x03\xeb\xba\x72\x23"
641 "\x9c\xfd\x3d\x8b\xc6\x07\x82\x3b\xf4\xf3\xef\x6c\x2e\x9e\x0b\xac"
642 "\x9e\x6c\xbb\x37\x4a\xa1\x9e\x73\xd1\xdc\x97\x61\xba\xfc\xd3\x49"
643 "\xa6\xc2\x4c\x55\x2e\x06\x37\x76\xb5\xef\x57\xe7\x57\x58\x8a\x71"
644 "\x63\xf3\xeb\xe7\x55\x68\x0d\xf6\x46\x4c\xfb\xf9\x43\xbb\x0c\x92"
645 "\x4f\x4e\x22\x7b\x63\xe8\x4f\x9c",
658 for (i
= 0; i
< sizeof(certs
)/sizeof(certs
[0]); i
++) {
660 ret
= decode_Certificate((unsigned char *)certs
[i
].cert
,
661 certs
[i
].len
, &c
, &size
);
665 ret
= copy_Certificate(&c
, &c2
);
666 free_Certificate(&c
);
670 free_Certificate(&c2
);
678 cmp_TESTLargeTag (void *a
, void *b
)
680 TESTLargeTag
*aa
= a
;
681 TESTLargeTag
*ab
= b
;
683 COMPARE_INTEGER(aa
,ab
,foo
);
684 COMPARE_INTEGER(aa
,ab
,bar
);
689 test_large_tag (void)
691 struct test_case tests
[] = {
692 { NULL
, 15, "\x30\x0d\xbf\x7f\x03\x02\x01\x01\xbf\x81\x00\x03\x02\x01\x02", "large tag 1" }
695 int ntests
= sizeof(tests
) / sizeof(*tests
);
698 memset(<1
, 0, sizeof(lt1
));
704 return generic_test (tests
, ntests
, sizeof(TESTLargeTag
),
705 (generic_encode
)encode_TESTLargeTag
,
706 (generic_length
)length_TESTLargeTag
,
707 (generic_decode
)decode_TESTLargeTag
,
708 (generic_free
)free_TESTLargeTag
,
710 (generic_copy
)copy_TESTLargeTag
);
721 check_tag_length(void)
723 struct test_data td
[] = {
724 { 1, 3, 3, "\x02\x01\x00"},
725 { 1, 3, 3, "\x02\x01\x7f"},
726 { 1, 4, 4, "\x02\x02\x00\x80"},
727 { 1, 4, 4, "\x02\x02\x01\x00"},
728 { 1, 4, 4, "\x02\x02\x02\x00"},
729 { 0, 3, 0, "\x02\x02\x00"},
730 { 0, 3, 0, "\x02\x7f\x7f"},
731 { 0, 4, 0, "\x02\x03\x00\x80"},
732 { 0, 4, 0, "\x02\x7f\x01\x00"},
733 { 0, 5, 0, "\x02\xff\x7f\x02\x00"}
736 TESTuint32 values
[] = {0, 127, 128, 256, 512,
737 0, 127, 128, 256, 512 };
739 int i
, ret
, failed
= 0;
742 for (i
= 0; i
< sizeof(td
)/sizeof(td
[0]); i
++) {
743 struct map_page
*page
;
745 buf
= map_alloc(OVERRUN
, td
[i
].data
, td
[i
].len
, &page
);
747 ret
= decode_TESTuint32(buf
, td
[i
].len
, &u
, &sz
);
750 printf("failed with tag len test %d\n", i
);
755 printf("failed with success for tag len test %d\n", i
);
758 if (td
[i
].expected_len
!= sz
) {
759 printf("wrong expected size for tag test %d\n", i
);
762 if (values
[i
] != u
) {
763 printf("wrong value for tag test %d\n", i
);
767 map_free(page
, "test", "decode");
773 check_tag_length64(void)
775 struct test_data td
[] = {
776 { 1, 3, 3, "\x02\x01\x00"},
777 { 1, 7, 7, "\x02\x05\x01\xff\xff\xff\xff"},
778 { 1, 7, 7, "\x02\x05\x02\x00\x00\x00\x00"},
779 { 1, 9, 9, "\x02\x07\x7f\xff\xff\xff\xff\xff\xff"},
780 { 1, 10, 10, "\x02\x08\x00\x80\x00\x00\x00\x00\x00\x00"},
781 { 1, 10, 10, "\x02\x08\x7f\xff\xff\xff\xff\xff\xff\xff"},
782 { 1, 11, 11, "\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xff"},
783 { 0, 3, 0, "\x02\x02\x00"},
784 { 0, 3, 0, "\x02\x7f\x7f"},
785 { 0, 4, 0, "\x02\x03\x00\x80"},
786 { 0, 4, 0, "\x02\x7f\x01\x00"},
787 { 0, 5, 0, "\x02\xff\x7f\x02\x00"}
790 TESTuint64 values
[] = {0, 8589934591LL, 8589934592LL,
791 36028797018963967LL, 36028797018963968LL,
792 9223372036854775807LL, 18446744073709551615ULL,
793 0, 127, 128, 256, 512 };
795 int i
, ret
, failed
= 0;
798 if (sizeof(TESTuint64
) != sizeof(uint64_t)) {
800 printf("sizeof(TESTuint64) %d != sizeof(uint64_t) %d\n",
801 (int)sizeof(TESTuint64
), (int)sizeof(uint64_t));
804 for (i
= 0; i
< sizeof(td
)/sizeof(td
[0]); i
++) {
805 struct map_page
*page
;
807 buf
= map_alloc(OVERRUN
, td
[i
].data
, td
[i
].len
, &page
);
809 ret
= decode_TESTuint64(buf
, td
[i
].len
, &u
, &sz
);
812 printf("failed with tag len test %d\n", i
);
813 printf("ret = %d\n", ret
);
818 printf("failed with success for tag len test %d\n", i
);
821 if (td
[i
].expected_len
!= sz
) {
822 printf("wrong expected size for tag test %d\n", i
);
823 printf("sz = %lu\n", (unsigned long)sz
);
826 if (values
[i
] != u
) {
827 printf("wrong value for tag test %d\n", i
);
828 printf("Expected value: %llu\nActual value: %llu\n",
829 (unsigned long long)values
[i
], (unsigned long long)u
);
833 map_free(page
, "test", "decode");
839 check_tag_length64s(void)
841 struct test_data td
[] = {
842 { 1, 3, 3, "\x02\x01\x00"},
843 { 1, 7, 7, "\x02\x05\xfe\x00\x00\x00\x01"},
844 { 1, 7, 7, "\x02\x05\xfe\x00\x00\x00\x00"},
845 { 1, 9, 9, "\x02\x07\x80\x00\x00\x00\x00\x00\x01"},
846 { 1, 9, 9, "\x02\x07\x80\x00\x00\x00\x00\x00\x00"},
847 { 1, 10, 10, "\x02\x08\x80\x00\x00\x00\x00\x00\x00\x01"},
848 { 1, 9, 9, "\x02\x07\x80\x00\x00\x00\x00\x00\x01"},
849 { 0, 3, 0, "\x02\x02\x00"},
850 { 0, 3, 0, "\x02\x7f\x7f"},
851 { 0, 4, 0, "\x02\x03\x00\x80"},
852 { 0, 4, 0, "\x02\x7f\x01\x00"},
853 { 0, 5, 0, "\x02\xff\x7f\x02\x00"}
856 TESTint64 values
[] = {0, -8589934591LL, -8589934592LL,
857 -36028797018963967LL, -36028797018963968LL,
858 -9223372036854775807LL, -36028797018963967LL,
859 0, 127, 128, 256, 512 };
861 int i
, ret
, failed
= 0;
864 for (i
= 0; i
< sizeof(td
)/sizeof(td
[0]); i
++) {
865 struct map_page
*page
;
867 buf
= map_alloc(OVERRUN
, td
[i
].data
, td
[i
].len
, &page
);
869 ret
= decode_TESTint64(buf
, td
[i
].len
, &u
, &sz
);
872 printf("failed with tag len test %d\n", i
);
873 printf("ret = %d\n", ret
);
878 printf("failed with success for tag len test %d\n", i
);
881 if (td
[i
].expected_len
!= sz
) {
882 printf("wrong expected size for tag test %d\n", i
);
883 printf("sz = %lu\n", (unsigned long)sz
);
886 if (values
[i
] != u
) {
887 printf("wrong value for tag test %d\n", i
);
888 printf("Expected value: %lld\nActual value: %lld\n",
889 (long long)values
[i
], (long long)u
);
893 map_free(page
, "test", "decode");
899 cmp_TESTChoice (void *a
, void *b
)
907 struct test_case tests
[] = {
908 { NULL
, 5, "\xa1\x03\x02\x01\x01", "large choice 1" },
909 { NULL
, 5, "\xa2\x03\x02\x01\x02", "large choice 2" }
912 int ret
= 0, ntests
= sizeof(tests
) / sizeof(*tests
);
917 memset(&c1
, 0, sizeof(c1
));
918 c1
.element
= choice_TESTChoice1_i1
;
922 memset(&c2_1
, 0, sizeof(c2_1
));
923 c2_1
.element
= choice_TESTChoice1_i2
;
925 tests
[1].val
= &c2_1
;
927 ret
+= generic_test (tests
, ntests
, sizeof(TESTChoice1
),
928 (generic_encode
)encode_TESTChoice1
,
929 (generic_length
)length_TESTChoice1
,
930 (generic_decode
)decode_TESTChoice1
,
931 (generic_free
)free_TESTChoice1
,
933 (generic_copy
)copy_TESTChoice1
);
935 memset(&c2_2
, 0, sizeof(c2_2
));
936 c2_2
.element
= choice_TESTChoice2_asn1_ellipsis
;
937 c2_2
.u
.asn1_ellipsis
.data
= "\xa2\x03\x02\x01\x02";
938 c2_2
.u
.asn1_ellipsis
.length
= 5;
939 tests
[1].val
= &c2_2
;
941 ret
+= generic_test (tests
, ntests
, sizeof(TESTChoice2
),
942 (generic_encode
)encode_TESTChoice2
,
943 (generic_length
)length_TESTChoice2
,
944 (generic_decode
)decode_TESTChoice2
,
945 (generic_free
)free_TESTChoice2
,
947 (generic_copy
)copy_TESTChoice2
);
953 cmp_TESTImplicit (void *a
, void *b
)
955 TESTImplicit
*aa
= a
;
956 TESTImplicit
*ab
= b
;
958 COMPARE_INTEGER(aa
,ab
,ti1
);
959 COMPARE_INTEGER(aa
,ab
,ti2
.foo
);
960 COMPARE_INTEGER(aa
,ab
,ti3
);
965 UNIV CONS Sequence 14
969 UNIV PRIM Integer 1 02
976 struct test_case tests
[] = {
978 "\x30\x0e\x80\x01\x00\xa1\x06\xbf"
979 "\x7f\x03\x02\x01\x02\x82\x01\x03",
983 int ret
= 0, ntests
= sizeof(tests
) / sizeof(*tests
);
986 memset(&c0
, 0, sizeof(c0
));
992 ret
+= generic_test (tests
, ntests
, sizeof(TESTImplicit
),
993 (generic_encode
)encode_TESTImplicit
,
994 (generic_length
)length_TESTImplicit
,
995 (generic_decode
)decode_TESTImplicit
,
996 (generic_free
)free_TESTImplicit
,
998 (generic_copy
)copy_TESTImplicit
);
1000 #ifdef IMPLICIT_TAGGING_WORKS
1001 ret
+= generic_test (tests
, ntests
, sizeof(TESTImplicit2
),
1002 (generic_encode
)encode_TESTImplicit2
,
1003 (generic_length
)length_TESTImplicit2
,
1004 (generic_decode
)decode_TESTImplicit2
,
1005 (generic_free
)free_TESTImplicit2
,
1009 #endif /* IMPLICIT_TAGGING_WORKS */
1014 cmp_TESTAlloc (void *a
, void *b
)
1019 IF_OPT_COMPARE(aa
,ab
,tagless
) {
1020 COMPARE_INTEGER(aa
,ab
,tagless
->ai
);
1023 COMPARE_INTEGER(aa
,ab
,three
);
1025 IF_OPT_COMPARE(aa
,ab
,tagless2
) {
1026 COMPARE_OPT_OCTECT_STRING(aa
, ab
, tagless2
);
1033 UNIV CONS Sequence 12
1034 UNIV CONS Sequence 5
1036 UNIV PRIM Integer 1 01
1038 UNIV PRIM Integer 1 03
1040 UNIV CONS Sequence 5
1042 UNIV PRIM Integer 1 03
1044 UNIV CONS Sequence 8
1046 UNIV PRIM Integer 1 04
1047 UNIV PRIM Integer 1 05
1052 test_taglessalloc (void)
1054 struct test_case tests
[] = {
1056 "\x30\x0c\x30\x05\xa0\x03\x02\x01\x01\xa1\x03\x02\x01\x03",
1059 "\x30\x05\xa1\x03\x02\x01\x03",
1062 "\x30\x08\xa1\x03\x02\x01\x04\x02\x01\x05",
1066 int ret
= 0, ntests
= sizeof(tests
) / sizeof(*tests
);
1067 TESTAlloc c1
, c2
, c3
;
1070 memset(&c1
, 0, sizeof(c1
));
1071 c1
.tagless
= ecalloc(1, sizeof(*c1
.tagless
));
1076 memset(&c2
, 0, sizeof(c2
));
1081 memset(&c3
, 0, sizeof(c3
));
1084 c3
.tagless2
= &any3
;
1085 any3
.data
= "\x02\x01\x05";
1089 ret
+= generic_test (tests
, ntests
, sizeof(TESTAlloc
),
1090 (generic_encode
)encode_TESTAlloc
,
1091 (generic_length
)length_TESTAlloc
,
1092 (generic_decode
)decode_TESTAlloc
,
1093 (generic_free
)free_TESTAlloc
,
1095 (generic_copy
)copy_TESTAlloc
);
1103 cmp_TESTOptional (void *a
, void *b
)
1105 TESTOptional
*aa
= a
;
1106 TESTOptional
*ab
= b
;
1108 IF_OPT_COMPARE(aa
,ab
,zero
) {
1109 COMPARE_OPT_INTEGER(aa
,ab
,zero
);
1111 IF_OPT_COMPARE(aa
,ab
,one
) {
1112 COMPARE_OPT_INTEGER(aa
,ab
,one
);
1118 UNIV CONS Sequence 5
1120 UNIV PRIM Integer 1 00
1122 UNIV CONS Sequence 5
1124 UNIV PRIM Integer 1 03
1126 UNIV CONS Sequence 10
1128 UNIV PRIM Integer 1 00
1130 UNIV PRIM Integer 1 01
1135 test_optional (void)
1137 struct test_case tests
[] = {
1142 "\x30\x05\xa0\x03\x02\x01\x00",
1145 "\x30\x05\xa1\x03\x02\x01\x01",
1148 "\x30\x0a\xa0\x03\x02\x01\x00\xa1\x03\x02\x01\x01",
1152 int ret
= 0, ntests
= sizeof(tests
) / sizeof(*tests
);
1153 TESTOptional c0
, c1
, c2
, c3
;
1173 ret
+= generic_test (tests
, ntests
, sizeof(TESTOptional
),
1174 (generic_encode
)encode_TESTOptional
,
1175 (generic_length
)length_TESTOptional
,
1176 (generic_decode
)decode_TESTOptional
,
1177 (generic_free
)free_TESTOptional
,
1179 (generic_copy
)copy_TESTOptional
);
1185 check_fail_largetag(void)
1187 struct test_case tests
[] = {
1188 {NULL
, 14, "\x30\x0c\xbf\x87\xff\xff\xff\xff\xff\x7f\x03\x02\x01\x01",
1190 {NULL
, 0, "", "empty buffer"},
1191 {NULL
, 7, "\x30\x05\xa1\x03\x02\x02\x01",
1193 {NULL
, 7, "\x30\x04\xa1\x03\x02\x02\x01",
1195 {NULL
, 7, "\x30\x03\xa1\x03\x02\x02\x01",
1196 "three too short" },
1197 {NULL
, 7, "\x30\x02\xa1\x03\x02\x02\x01",
1199 {NULL
, 7, "\x30\x01\xa1\x03\x02\x02\x01",
1201 {NULL
, 7, "\x30\x00\xa1\x03\x02\x02\x01",
1203 {NULL
, 7, "\x30\x05\xa1\x04\x02\x02\x01",
1204 "inner one too long" },
1205 {NULL
, 7, "\x30\x00\xa1\x02\x02\x02\x01",
1206 "inner one too short" },
1207 {NULL
, 8, "\x30\x05\xbf\x7f\x03\x02\x02\x01",
1208 "inner one too short"},
1209 {NULL
, 8, "\x30\x06\xbf\x64\x03\x02\x01\x01",
1211 {NULL
, 10, "\x30\x08\xbf\x9a\x9b\x38\x03\x02\x01\x01",
1214 int ntests
= sizeof(tests
) / sizeof(*tests
);
1216 return generic_decode_fail(tests
, ntests
, sizeof(TESTLargeTag
),
1217 (generic_decode
)decode_TESTLargeTag
);
1222 check_fail_sequence(void)
1224 struct test_case tests
[] = {
1225 {NULL
, 0, "", "empty buffer"},
1227 "\x30\x16\xa0\x03\x02\x01\x01\xa1\x08\x30\x06\xbf\x7f\x03\x02\x01\x01"
1228 "\x02\x01\x01\xa2\x03\x02\x01\x01",
1229 "missing one byte from the end, internal length ok"},
1231 "\x30\x18\xa0\x03\x02\x01\x01\xa1\x08\x30\x06\xbf\x7f\x03\x02\x01\x01"
1232 "\x02\x01\x01\xa2\x03\x02\x01\x01",
1233 "inner length one byte too long"},
1235 "\x30\x17\xa0\x03\x02\x01\x01\xa1\x08\x30\x06\xbf\x7f\x03\x02\x01"
1236 "\x01\x02\x01\x01\xa2\x03\x02\x01\x01",
1237 "correct buffer but missing one too short"}
1239 int ntests
= sizeof(tests
) / sizeof(*tests
);
1241 return generic_decode_fail(tests
, ntests
, sizeof(TESTSeq
),
1242 (generic_decode
)decode_TESTSeq
);
1246 check_fail_choice(void)
1248 struct test_case tests
[] = {
1250 "\xa1\x02\x02\x01\x01",
1251 "choice one too short"},
1253 "\xa1\x03\x02\x02\x01",
1254 "choice one too short inner"}
1256 int ntests
= sizeof(tests
) / sizeof(*tests
);
1258 return generic_decode_fail(tests
, ntests
, sizeof(TESTChoice1
),
1259 (generic_decode
)decode_TESTChoice1
);
1272 ret
= add_TESTSeqOf(&seq
, &i
);
1273 if (ret
) { printf("failed adding\n"); goto out
; }
1274 ret
= add_TESTSeqOf(&seq
, &i
);
1275 if (ret
) { printf("failed adding\n"); goto out
; }
1276 ret
= add_TESTSeqOf(&seq
, &i
);
1277 if (ret
) { printf("failed adding\n"); goto out
; }
1278 ret
= add_TESTSeqOf(&seq
, &i
);
1279 if (ret
) { printf("failed adding\n"); goto out
; }
1281 ret
= remove_TESTSeqOf(&seq
, seq
.len
- 1);
1282 if (ret
) { printf("failed removing\n"); goto out
; }
1283 ret
= remove_TESTSeqOf(&seq
, 2);
1284 if (ret
) { printf("failed removing\n"); goto out
; }
1285 ret
= remove_TESTSeqOf(&seq
, 0);
1286 if (ret
) { printf("failed removing\n"); goto out
; }
1287 ret
= remove_TESTSeqOf(&seq
, 0);
1288 if (ret
) { printf("failed removing\n"); goto out
; }
1289 ret
= remove_TESTSeqOf(&seq
, 0);
1291 printf("can remove from empty list");
1296 printf("seq not empty!");
1299 free_TESTSeqOf(&seq
);
1307 #define test_seq_of(type, ok, ptr) \
1309 heim_octet_string os; \
1312 ASN1_MALLOC_ENCODE(type, os.data, os.length, ptr, &size, ret); \
1315 if (os.length != size) \
1317 ret = decode_##type(os.data, os.length, &decode, &size); \
1323 free_##type(&decode); \
1333 check_seq_of_size(void)
1335 #if 0 /* template */
1336 TESTInteger integers
[4] = { 1, 2, 3, 4 };
1340 TESTSeqSizeOf1 ssof1f1
= { 1, integers
};
1341 TESTSeqSizeOf1 ssof1ok1
= { 2, integers
};
1342 TESTSeqSizeOf1 ssof1f2
= { 3, integers
};
1344 test_seq_of(TESTSeqSizeOf1
, 0, &ssof1f1
);
1345 test_seq_of(TESTSeqSizeOf1
, 1, &ssof1ok1
);
1346 test_seq_of(TESTSeqSizeOf1
, 0, &ssof1f2
);
1349 TESTSeqSizeOf2 ssof2f1
= { 0, NULL
};
1350 TESTSeqSizeOf2 ssof2ok1
= { 1, integers
};
1351 TESTSeqSizeOf2 ssof2ok2
= { 2, integers
};
1352 TESTSeqSizeOf2 ssof2f2
= { 3, integers
};
1354 test_seq_of(TESTSeqSizeOf2
, 0, &ssof2f1
);
1355 test_seq_of(TESTSeqSizeOf2
, 1, &ssof2ok1
);
1356 test_seq_of(TESTSeqSizeOf2
, 1, &ssof2ok2
);
1357 test_seq_of(TESTSeqSizeOf2
, 0, &ssof2f2
);
1360 TESTSeqSizeOf3 ssof3f1
= { 0, NULL
};
1361 TESTSeqSizeOf3 ssof3ok1
= { 1, integers
};
1362 TESTSeqSizeOf3 ssof3ok2
= { 2, integers
};
1364 test_seq_of(TESTSeqSizeOf3
, 0, &ssof3f1
);
1365 test_seq_of(TESTSeqSizeOf3
, 1, &ssof3ok1
);
1366 test_seq_of(TESTSeqSizeOf3
, 1, &ssof3ok2
);
1369 TESTSeqSizeOf4 ssof4ok1
= { 0, NULL
};
1370 TESTSeqSizeOf4 ssof4ok2
= { 1, integers
};
1371 TESTSeqSizeOf4 ssof4ok3
= { 2, integers
};
1372 TESTSeqSizeOf4 ssof4f1
= { 3, integers
};
1374 test_seq_of(TESTSeqSizeOf4
, 1, &ssof4ok1
);
1375 test_seq_of(TESTSeqSizeOf4
, 1, &ssof4ok2
);
1376 test_seq_of(TESTSeqSizeOf4
, 1, &ssof4ok3
);
1377 test_seq_of(TESTSeqSizeOf4
, 0, &ssof4f1
);
1384 check_TESTMechTypeList(void)
1386 TESTMechTypeList tl
;
1387 unsigned oid1
[] = { 1, 2, 840, 48018, 1, 2, 2};
1388 unsigned oid2
[] = { 1, 2, 840, 113554, 1, 2, 2};
1389 unsigned oid3
[] = { 1, 3, 6, 1, 4, 1, 311, 2, 2, 30};
1390 unsigned oid4
[] = { 1, 3, 6, 1, 4, 1, 311, 2, 2, 10};
1391 TESTMechType array
[] = {{ 7, oid1
},
1402 ASN1_MALLOC_ENCODE(TESTMechTypeList
, ptr
, len
, &tl
, &size
, ret
);
1404 errx(1, "TESTMechTypeList: %d", ret
);
1411 main(int argc
, char **argv
)
1415 ret
+= test_principal ();
1416 ret
+= test_authenticator();
1417 ret
+= test_krb_error();
1419 ret
+= test_bit_string();
1420 ret
+= test_bit_string_rfc1510();
1424 ret
+= check_tag_length();
1425 ret
+= check_tag_length64();
1426 ret
+= check_tag_length64s();
1427 ret
+= test_large_tag();
1428 ret
+= test_choice();
1430 ret
+= test_implicit();
1431 ret
+= test_taglessalloc();
1432 ret
+= test_optional();
1434 ret
+= check_fail_largetag();
1435 ret
+= check_fail_sequence();
1436 ret
+= check_fail_choice();
1439 ret
+= check_seq_of_size();
1441 ret
+= check_TESTMechTypeList();