xref: /freebsd/crypto/heimdal/lib/asn1/check-der.c (revision 6a068746777241722b2b32c5d0bc443a2a64d80b)
1b528cefcSMark Murray /*
2*ae771770SStanislav Sedov  * Copyright (c) 1999 - 2007 Kungliga Tekniska Högskolan
3b528cefcSMark Murray  * (Royal Institute of Technology, Stockholm, Sweden).
4b528cefcSMark Murray  * All rights reserved.
5b528cefcSMark Murray  *
6*ae771770SStanislav Sedov  * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
7*ae771770SStanislav Sedov  *
8b528cefcSMark Murray  * Redistribution and use in source and binary forms, with or without
9b528cefcSMark Murray  * modification, are permitted provided that the following conditions
10b528cefcSMark Murray  * are met:
11b528cefcSMark Murray  *
12b528cefcSMark Murray  * 1. Redistributions of source code must retain the above copyright
13b528cefcSMark Murray  *    notice, this list of conditions and the following disclaimer.
14b528cefcSMark Murray  *
15b528cefcSMark Murray  * 2. Redistributions in binary form must reproduce the above copyright
16b528cefcSMark Murray  *    notice, this list of conditions and the following disclaimer in the
17b528cefcSMark Murray  *    documentation and/or other materials provided with the distribution.
18b528cefcSMark Murray  *
19b528cefcSMark Murray  * 3. Neither the name of the Institute nor the names of its contributors
20b528cefcSMark Murray  *    may be used to endorse or promote products derived from this software
21b528cefcSMark Murray  *    without specific prior written permission.
22b528cefcSMark Murray  *
23b528cefcSMark Murray  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24b528cefcSMark Murray  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25b528cefcSMark Murray  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26b528cefcSMark Murray  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27b528cefcSMark Murray  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28b528cefcSMark Murray  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29b528cefcSMark Murray  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30b528cefcSMark Murray  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31b528cefcSMark Murray  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32b528cefcSMark Murray  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33b528cefcSMark Murray  * SUCH DAMAGE.
34b528cefcSMark Murray  */
35b528cefcSMark Murray 
36c19800e8SDoug Rabson #include "der_locl.h"
37b528cefcSMark Murray #include <err.h>
38b528cefcSMark Murray #include <roken.h>
39b528cefcSMark Murray 
408373020dSJacques Vidrine #include <asn1-common.h>
418373020dSJacques Vidrine #include <asn1_err.h>
428373020dSJacques Vidrine #include <der.h>
43b528cefcSMark Murray 
44bbd80c28SJacques Vidrine #include "check-common.h"
45b528cefcSMark Murray 
46*ae771770SStanislav Sedov RCSID("$Id$");
47b528cefcSMark Murray 
48b528cefcSMark Murray static int
cmp_integer(void * a,void * b)49b528cefcSMark Murray cmp_integer (void *a, void *b)
50b528cefcSMark Murray {
51b528cefcSMark Murray     int *ia = (int *)a;
52b528cefcSMark Murray     int *ib = (int *)b;
53b528cefcSMark Murray 
54b528cefcSMark Murray     return *ib - *ia;
55b528cefcSMark Murray }
56b528cefcSMark Murray 
57b528cefcSMark Murray static int
test_integer(void)58b528cefcSMark Murray test_integer (void)
59b528cefcSMark Murray {
60b528cefcSMark Murray     struct test_case tests[] = {
61c19800e8SDoug Rabson 	{NULL, 1, "\x00"},
62c19800e8SDoug Rabson 	{NULL, 1, "\x7f"},
63c19800e8SDoug Rabson 	{NULL, 2, "\x00\x80"},
64c19800e8SDoug Rabson 	{NULL, 2, "\x01\x00"},
65c19800e8SDoug Rabson 	{NULL, 1, "\x80"},
66c19800e8SDoug Rabson 	{NULL, 2, "\xff\x7f"},
67c19800e8SDoug Rabson 	{NULL, 1, "\xff"},
68c19800e8SDoug Rabson 	{NULL, 2, "\xff\x01"},
69c19800e8SDoug Rabson 	{NULL, 2, "\x00\xff"},
70c19800e8SDoug Rabson 	{NULL, 4, "\x7f\xff\xff\xff"}
71b528cefcSMark Murray     };
72b528cefcSMark Murray 
73b528cefcSMark Murray     int values[] = {0, 127, 128, 256, -128, -129, -1, -255, 255,
74c19800e8SDoug Rabson 		    0x7fffffff};
75c19800e8SDoug Rabson     int i, ret;
76b528cefcSMark Murray     int ntests = sizeof(tests) / sizeof(*tests);
77b528cefcSMark Murray 
78b528cefcSMark Murray     for (i = 0; i < ntests; ++i) {
79b528cefcSMark Murray 	tests[i].val = &values[i];
80*ae771770SStanislav Sedov 	if (asprintf (&tests[i].name, "integer %d", values[i]) < 0)
81*ae771770SStanislav Sedov 	    errx(1, "malloc");
82c19800e8SDoug Rabson 	if (tests[i].name == NULL)
83c19800e8SDoug Rabson 	    errx(1, "malloc");
84b528cefcSMark Murray     }
85b528cefcSMark Murray 
86c19800e8SDoug Rabson     ret = generic_test (tests, ntests, sizeof(int),
87c19800e8SDoug Rabson 			(generic_encode)der_put_integer,
88c19800e8SDoug Rabson 			(generic_length) der_length_integer,
89c19800e8SDoug Rabson 			(generic_decode)der_get_integer,
90c19800e8SDoug Rabson 			(generic_free)NULL,
91*ae771770SStanislav Sedov 			cmp_integer,
92*ae771770SStanislav Sedov 			NULL);
93c19800e8SDoug Rabson 
94c19800e8SDoug Rabson     for (i = 0; i < ntests; ++i)
95c19800e8SDoug Rabson 	free (tests[i].name);
96c19800e8SDoug Rabson     return ret;
97c19800e8SDoug Rabson }
98c19800e8SDoug Rabson 
99c19800e8SDoug Rabson static int
test_one_int(int val)100c19800e8SDoug Rabson test_one_int(int val)
101c19800e8SDoug Rabson {
102c19800e8SDoug Rabson     int ret, dval;
103c19800e8SDoug Rabson     unsigned char *buf;
104c19800e8SDoug Rabson     size_t len_len, len;
105c19800e8SDoug Rabson 
106c19800e8SDoug Rabson     len = _heim_len_int(val);
107c19800e8SDoug Rabson 
108c19800e8SDoug Rabson     buf = emalloc(len + 2);
109c19800e8SDoug Rabson 
110c19800e8SDoug Rabson     buf[0] = '\xff';
111c19800e8SDoug Rabson     buf[len + 1] = '\xff';
112c19800e8SDoug Rabson     memset(buf + 1, 0, len);
113c19800e8SDoug Rabson 
114c19800e8SDoug Rabson     ret = der_put_integer(buf + 1 + len - 1, len, &val, &len_len);
115c19800e8SDoug Rabson     if (ret) {
116c19800e8SDoug Rabson 	printf("integer %d encode failed %d\n", val, ret);
117c19800e8SDoug Rabson 	return 1;
118c19800e8SDoug Rabson     }
119c19800e8SDoug Rabson     if (len != len_len) {
120c19800e8SDoug Rabson 	printf("integer %d encode fail with %d len %lu, result len %lu\n",
121c19800e8SDoug Rabson 	       val, ret, (unsigned long)len, (unsigned long)len_len);
122c19800e8SDoug Rabson 	return 1;
123c19800e8SDoug Rabson     }
124c19800e8SDoug Rabson 
125c19800e8SDoug Rabson     ret = der_get_integer(buf + 1, len, &dval, &len_len);
126c19800e8SDoug Rabson     if (ret) {
127c19800e8SDoug Rabson 	printf("integer %d decode failed %d\n", val, ret);
128c19800e8SDoug Rabson 	return 1;
129c19800e8SDoug Rabson     }
130c19800e8SDoug Rabson     if (len != len_len) {
131c19800e8SDoug Rabson 	printf("integer %d decoded diffrent len %lu != %lu",
132c19800e8SDoug Rabson 	       val, (unsigned long)len, (unsigned long)len_len);
133c19800e8SDoug Rabson 	return 1;
134c19800e8SDoug Rabson     }
135c19800e8SDoug Rabson     if (val != dval) {
136c19800e8SDoug Rabson 	printf("decode decoded to diffrent value %d != %d",
137c19800e8SDoug Rabson 	       val, dval);
138c19800e8SDoug Rabson 	return 1;
139c19800e8SDoug Rabson     }
140c19800e8SDoug Rabson 
141c19800e8SDoug Rabson     if (buf[0] != (unsigned char)'\xff') {
142c19800e8SDoug Rabson 	printf("precanary dead %d\n", val);
143c19800e8SDoug Rabson 	return 1;
144c19800e8SDoug Rabson     }
145c19800e8SDoug Rabson     if (buf[len + 1] != (unsigned char)'\xff') {
146c19800e8SDoug Rabson 	printf("postecanary dead %d\n", val);
147c19800e8SDoug Rabson 	return 1;
148c19800e8SDoug Rabson     }
149c19800e8SDoug Rabson     free(buf);
150c19800e8SDoug Rabson     return 0;
151c19800e8SDoug Rabson }
152c19800e8SDoug Rabson 
153c19800e8SDoug Rabson static int
test_integer_more(void)154c19800e8SDoug Rabson test_integer_more (void)
155c19800e8SDoug Rabson {
156c19800e8SDoug Rabson     int i, n1, n2, n3, n4, n5, n6;
157c19800e8SDoug Rabson 
158c19800e8SDoug Rabson     n2 = 0;
159c19800e8SDoug Rabson     for (i = 0; i < (sizeof(int) * 8); i++) {
160c19800e8SDoug Rabson 	n1 = 0x01 << i;
161c19800e8SDoug Rabson 	n2 = n2 | n1;
162c19800e8SDoug Rabson 	n3 = ~n1;
163c19800e8SDoug Rabson 	n4 = ~n2;
164c19800e8SDoug Rabson 	n5 = (-1) & ~(0x3f << i);
165c19800e8SDoug Rabson 	n6 = (-1) & ~(0x7f << i);
166c19800e8SDoug Rabson 
167c19800e8SDoug Rabson 	test_one_int(n1);
168c19800e8SDoug Rabson 	test_one_int(n2);
169c19800e8SDoug Rabson 	test_one_int(n3);
170c19800e8SDoug Rabson 	test_one_int(n4);
171c19800e8SDoug Rabson 	test_one_int(n5);
172c19800e8SDoug Rabson 	test_one_int(n6);
173c19800e8SDoug Rabson     }
174c19800e8SDoug Rabson     return 0;
175c19800e8SDoug Rabson }
176c19800e8SDoug Rabson 
177c19800e8SDoug Rabson static int
cmp_unsigned(void * a,void * b)178c19800e8SDoug Rabson cmp_unsigned (void *a, void *b)
179c19800e8SDoug Rabson {
180c19800e8SDoug Rabson     return *(unsigned int*)b - *(unsigned int*)a;
181c19800e8SDoug Rabson }
182c19800e8SDoug Rabson 
183c19800e8SDoug Rabson static int
test_unsigned(void)184c19800e8SDoug Rabson test_unsigned (void)
185c19800e8SDoug Rabson {
186c19800e8SDoug Rabson     struct test_case tests[] = {
187c19800e8SDoug Rabson 	{NULL, 1, "\x00"},
188c19800e8SDoug Rabson 	{NULL, 1, "\x7f"},
189c19800e8SDoug Rabson 	{NULL, 2, "\x00\x80"},
190c19800e8SDoug Rabson 	{NULL, 2, "\x01\x00"},
191c19800e8SDoug Rabson 	{NULL, 2, "\x02\x00"},
192c19800e8SDoug Rabson 	{NULL, 3, "\x00\x80\x00"},
193c19800e8SDoug Rabson 	{NULL, 5, "\x00\x80\x00\x00\x00"},
194c19800e8SDoug Rabson 	{NULL, 4, "\x7f\xff\xff\xff"}
195c19800e8SDoug Rabson     };
196c19800e8SDoug Rabson 
197c19800e8SDoug Rabson     unsigned int values[] = {0, 127, 128, 256, 512, 32768,
198c19800e8SDoug Rabson 			     0x80000000, 0x7fffffff};
199c19800e8SDoug Rabson     int i, ret;
200c19800e8SDoug Rabson     int ntests = sizeof(tests) / sizeof(*tests);
201c19800e8SDoug Rabson 
202c19800e8SDoug Rabson     for (i = 0; i < ntests; ++i) {
203c19800e8SDoug Rabson 	tests[i].val = &values[i];
204*ae771770SStanislav Sedov 	if (asprintf (&tests[i].name, "unsigned %u", values[i]) < 0)
205*ae771770SStanislav Sedov 	    errx(1, "malloc");
206c19800e8SDoug Rabson 	if (tests[i].name == NULL)
207c19800e8SDoug Rabson 	    errx(1, "malloc");
208c19800e8SDoug Rabson     }
209c19800e8SDoug Rabson 
210c19800e8SDoug Rabson     ret = generic_test (tests, ntests, sizeof(int),
211c19800e8SDoug Rabson 			(generic_encode)der_put_unsigned,
212c19800e8SDoug Rabson 			(generic_length)der_length_unsigned,
213c19800e8SDoug Rabson 			(generic_decode)der_get_unsigned,
214c19800e8SDoug Rabson 			(generic_free)NULL,
215*ae771770SStanislav Sedov 			cmp_unsigned,
216*ae771770SStanislav Sedov 			NULL);
217c19800e8SDoug Rabson     for (i = 0; i < ntests; ++i)
218c19800e8SDoug Rabson 	free (tests[i].name);
219c19800e8SDoug Rabson     return ret;
220b528cefcSMark Murray }
221b528cefcSMark Murray 
222b528cefcSMark Murray static int
cmp_octet_string(void * a,void * b)223b528cefcSMark Murray cmp_octet_string (void *a, void *b)
224b528cefcSMark Murray {
225c19800e8SDoug Rabson     heim_octet_string *oa = (heim_octet_string *)a;
226c19800e8SDoug Rabson     heim_octet_string *ob = (heim_octet_string *)b;
227b528cefcSMark Murray 
228b528cefcSMark Murray     if (oa->length != ob->length)
229b528cefcSMark Murray 	return ob->length - oa->length;
230b528cefcSMark Murray 
231b528cefcSMark Murray     return (memcmp (oa->data, ob->data, oa->length));
232b528cefcSMark Murray }
233b528cefcSMark Murray 
234b528cefcSMark Murray static int
test_octet_string(void)235b528cefcSMark Murray test_octet_string (void)
236b528cefcSMark Murray {
237c19800e8SDoug Rabson     heim_octet_string s1 = {8, "\x01\x23\x45\x67\x89\xab\xcd\xef"};
238b528cefcSMark Murray 
239b528cefcSMark Murray     struct test_case tests[] = {
240c19800e8SDoug Rabson 	{NULL, 8, "\x01\x23\x45\x67\x89\xab\xcd\xef"}
241b528cefcSMark Murray     };
242b528cefcSMark Murray     int ntests = sizeof(tests) / sizeof(*tests);
243c19800e8SDoug Rabson     int ret;
244b528cefcSMark Murray 
245b528cefcSMark Murray     tests[0].val = &s1;
246*ae771770SStanislav Sedov     if (asprintf (&tests[0].name, "a octet string") < 0)
247*ae771770SStanislav Sedov 	errx(1, "malloc");
248c19800e8SDoug Rabson     if (tests[0].name == NULL)
249c19800e8SDoug Rabson 	errx(1, "malloc");
250b528cefcSMark Murray 
251c19800e8SDoug Rabson     ret = generic_test (tests, ntests, sizeof(heim_octet_string),
252c19800e8SDoug Rabson 			(generic_encode)der_put_octet_string,
253c19800e8SDoug Rabson 			(generic_length)der_length_octet_string,
254c19800e8SDoug Rabson 			(generic_decode)der_get_octet_string,
255c19800e8SDoug Rabson 			(generic_free)der_free_octet_string,
256*ae771770SStanislav Sedov 			cmp_octet_string,
257*ae771770SStanislav Sedov 			NULL);
258c19800e8SDoug Rabson     free(tests[0].name);
259c19800e8SDoug Rabson     return ret;
260c19800e8SDoug Rabson }
261c19800e8SDoug Rabson 
262c19800e8SDoug Rabson static int
cmp_bmp_string(void * a,void * b)263c19800e8SDoug Rabson cmp_bmp_string (void *a, void *b)
264c19800e8SDoug Rabson {
265c19800e8SDoug Rabson     heim_bmp_string *oa = (heim_bmp_string *)a;
266c19800e8SDoug Rabson     heim_bmp_string *ob = (heim_bmp_string *)b;
267c19800e8SDoug Rabson 
268c19800e8SDoug Rabson     return der_heim_bmp_string_cmp(oa, ob);
269c19800e8SDoug Rabson }
270c19800e8SDoug Rabson 
271c19800e8SDoug Rabson static uint16_t bmp_d1[] = { 32 };
272c19800e8SDoug Rabson static uint16_t bmp_d2[] = { 32, 32 };
273c19800e8SDoug Rabson 
274c19800e8SDoug Rabson static int
test_bmp_string(void)275c19800e8SDoug Rabson test_bmp_string (void)
276c19800e8SDoug Rabson {
277c19800e8SDoug Rabson     heim_bmp_string s1 = { 1, bmp_d1 };
278c19800e8SDoug Rabson     heim_bmp_string s2 = { 2, bmp_d2 };
279c19800e8SDoug Rabson 
280c19800e8SDoug Rabson     struct test_case tests[] = {
281c19800e8SDoug Rabson 	{NULL, 2, "\x00\x20"},
282c19800e8SDoug Rabson 	{NULL, 4, "\x00\x20\x00\x20"}
283c19800e8SDoug Rabson     };
284c19800e8SDoug Rabson     int ntests = sizeof(tests) / sizeof(*tests);
285c19800e8SDoug Rabson     int ret;
286c19800e8SDoug Rabson 
287c19800e8SDoug Rabson     tests[0].val = &s1;
288*ae771770SStanislav Sedov     if (asprintf (&tests[0].name, "a bmp string") < 0)
289*ae771770SStanislav Sedov 	errx(1, "malloc");
290c19800e8SDoug Rabson     if (tests[0].name == NULL)
291c19800e8SDoug Rabson 	errx(1, "malloc");
292c19800e8SDoug Rabson     tests[1].val = &s2;
293*ae771770SStanislav Sedov     if (asprintf (&tests[1].name, "second bmp string") < 0)
294*ae771770SStanislav Sedov 	errx(1, "malloc");
295c19800e8SDoug Rabson     if (tests[1].name == NULL)
296c19800e8SDoug Rabson 	errx(1, "malloc");
297c19800e8SDoug Rabson 
298c19800e8SDoug Rabson     ret = generic_test (tests, ntests, sizeof(heim_bmp_string),
299c19800e8SDoug Rabson 			(generic_encode)der_put_bmp_string,
300c19800e8SDoug Rabson 			(generic_length)der_length_bmp_string,
301c19800e8SDoug Rabson 			(generic_decode)der_get_bmp_string,
302c19800e8SDoug Rabson 			(generic_free)der_free_bmp_string,
303*ae771770SStanislav Sedov 			cmp_bmp_string,
304*ae771770SStanislav Sedov 			NULL);
305c19800e8SDoug Rabson     free(tests[0].name);
306c19800e8SDoug Rabson     free(tests[1].name);
307c19800e8SDoug Rabson     return ret;
308c19800e8SDoug Rabson }
309c19800e8SDoug Rabson 
310c19800e8SDoug Rabson static int
cmp_universal_string(void * a,void * b)311c19800e8SDoug Rabson cmp_universal_string (void *a, void *b)
312c19800e8SDoug Rabson {
313c19800e8SDoug Rabson     heim_universal_string *oa = (heim_universal_string *)a;
314c19800e8SDoug Rabson     heim_universal_string *ob = (heim_universal_string *)b;
315c19800e8SDoug Rabson 
316c19800e8SDoug Rabson     return der_heim_universal_string_cmp(oa, ob);
317c19800e8SDoug Rabson }
318c19800e8SDoug Rabson 
319c19800e8SDoug Rabson static uint32_t universal_d1[] = { 32 };
320c19800e8SDoug Rabson static uint32_t universal_d2[] = { 32, 32 };
321c19800e8SDoug Rabson 
322c19800e8SDoug Rabson static int
test_universal_string(void)323c19800e8SDoug Rabson test_universal_string (void)
324c19800e8SDoug Rabson {
325c19800e8SDoug Rabson     heim_universal_string s1 = { 1, universal_d1 };
326c19800e8SDoug Rabson     heim_universal_string s2 = { 2, universal_d2 };
327c19800e8SDoug Rabson 
328c19800e8SDoug Rabson     struct test_case tests[] = {
329c19800e8SDoug Rabson 	{NULL, 4, "\x00\x00\x00\x20"},
330c19800e8SDoug Rabson 	{NULL, 8, "\x00\x00\x00\x20\x00\x00\x00\x20"}
331c19800e8SDoug Rabson     };
332c19800e8SDoug Rabson     int ntests = sizeof(tests) / sizeof(*tests);
333c19800e8SDoug Rabson     int ret;
334c19800e8SDoug Rabson 
335c19800e8SDoug Rabson     tests[0].val = &s1;
336*ae771770SStanislav Sedov     if (asprintf (&tests[0].name, "a universal string") < 0)
337*ae771770SStanislav Sedov 	errx(1, "malloc");
338c19800e8SDoug Rabson     if (tests[0].name == NULL)
339c19800e8SDoug Rabson 	errx(1, "malloc");
340c19800e8SDoug Rabson     tests[1].val = &s2;
341*ae771770SStanislav Sedov     if (asprintf (&tests[1].name, "second universal string") < 0)
342*ae771770SStanislav Sedov 	errx(1, "malloc");
343c19800e8SDoug Rabson     if (tests[1].name == NULL)
344c19800e8SDoug Rabson 	errx(1, "malloc");
345c19800e8SDoug Rabson 
346c19800e8SDoug Rabson     ret = generic_test (tests, ntests, sizeof(heim_universal_string),
347c19800e8SDoug Rabson 			(generic_encode)der_put_universal_string,
348c19800e8SDoug Rabson 			(generic_length)der_length_universal_string,
349c19800e8SDoug Rabson 			(generic_decode)der_get_universal_string,
350c19800e8SDoug Rabson 			(generic_free)der_free_universal_string,
351*ae771770SStanislav Sedov 			cmp_universal_string,
352*ae771770SStanislav Sedov 			NULL);
353c19800e8SDoug Rabson     free(tests[0].name);
354c19800e8SDoug Rabson     free(tests[1].name);
355c19800e8SDoug Rabson     return ret;
356b528cefcSMark Murray }
357b528cefcSMark Murray 
358b528cefcSMark Murray static int
cmp_general_string(void * a,void * b)359b528cefcSMark Murray cmp_general_string (void *a, void *b)
360b528cefcSMark Murray {
361c19800e8SDoug Rabson     char **sa = (char **)a;
362c19800e8SDoug Rabson     char **sb = (char **)b;
363b528cefcSMark Murray 
364b528cefcSMark Murray     return strcmp (*sa, *sb);
365b528cefcSMark Murray }
366b528cefcSMark Murray 
367b528cefcSMark Murray static int
test_general_string(void)368b528cefcSMark Murray test_general_string (void)
369b528cefcSMark Murray {
370c19800e8SDoug Rabson     char *s1 = "Test User 1";
371b528cefcSMark Murray 
372b528cefcSMark Murray     struct test_case tests[] = {
373c19800e8SDoug Rabson 	{NULL, 11, "\x54\x65\x73\x74\x20\x55\x73\x65\x72\x20\x31"}
374b528cefcSMark Murray     };
375c19800e8SDoug Rabson     int ret, ntests = sizeof(tests) / sizeof(*tests);
376b528cefcSMark Murray 
377b528cefcSMark Murray     tests[0].val = &s1;
378*ae771770SStanislav Sedov     if (asprintf (&tests[0].name, "the string \"%s\"", s1) < 0)
379*ae771770SStanislav Sedov 	errx(1, "malloc");
380c19800e8SDoug Rabson     if (tests[0].name == NULL)
381c19800e8SDoug Rabson 	errx(1, "malloc");
382b528cefcSMark Murray 
383c19800e8SDoug Rabson     ret = generic_test (tests, ntests, sizeof(unsigned char *),
384c19800e8SDoug Rabson 			(generic_encode)der_put_general_string,
385c19800e8SDoug Rabson 			(generic_length)der_length_general_string,
386c19800e8SDoug Rabson 			(generic_decode)der_get_general_string,
387c19800e8SDoug Rabson 			(generic_free)der_free_general_string,
388*ae771770SStanislav Sedov 			cmp_general_string,
389*ae771770SStanislav Sedov 			NULL);
390c19800e8SDoug Rabson     free(tests[0].name);
391c19800e8SDoug Rabson     return ret;
392b528cefcSMark Murray }
393b528cefcSMark Murray 
394b528cefcSMark Murray static int
cmp_generalized_time(void * a,void * b)395b528cefcSMark Murray cmp_generalized_time (void *a, void *b)
396b528cefcSMark Murray {
397b528cefcSMark Murray     time_t *ta = (time_t *)a;
398b528cefcSMark Murray     time_t *tb = (time_t *)b;
399b528cefcSMark Murray 
400b528cefcSMark Murray     return *tb - *ta;
401b528cefcSMark Murray }
402b528cefcSMark Murray 
403b528cefcSMark Murray static int
test_generalized_time(void)404b528cefcSMark Murray test_generalized_time (void)
405b528cefcSMark Murray {
406b528cefcSMark Murray     struct test_case tests[] = {
407c19800e8SDoug Rabson 	{NULL, 15, "19700101000000Z"},
408c19800e8SDoug Rabson 	{NULL, 15, "19851106210627Z"}
409b528cefcSMark Murray     };
410b528cefcSMark Murray     time_t values[] = {0, 500159187};
411c19800e8SDoug Rabson     int i, ret;
412b528cefcSMark Murray     int ntests = sizeof(tests) / sizeof(*tests);
413b528cefcSMark Murray 
414b528cefcSMark Murray     for (i = 0; i < ntests; ++i) {
415b528cefcSMark Murray 	tests[i].val = &values[i];
416*ae771770SStanislav Sedov 	if (asprintf (&tests[i].name, "time %d", (int)values[i]) < 0)
417*ae771770SStanislav Sedov 	    errx(1, "malloc");
418c19800e8SDoug Rabson 	if (tests[i].name == NULL)
419c19800e8SDoug Rabson 	    errx(1, "malloc");
420b528cefcSMark Murray     }
421b528cefcSMark Murray 
422c19800e8SDoug Rabson     ret = generic_test (tests, ntests, sizeof(time_t),
423c19800e8SDoug Rabson 			(generic_encode)der_put_generalized_time,
424c19800e8SDoug Rabson 			(generic_length)der_length_generalized_time,
425c19800e8SDoug Rabson 			(generic_decode)der_get_generalized_time,
426c19800e8SDoug Rabson 			(generic_free)NULL,
427*ae771770SStanislav Sedov 			cmp_generalized_time,
428*ae771770SStanislav Sedov 			NULL);
429c19800e8SDoug Rabson     for (i = 0; i < ntests; ++i)
430c19800e8SDoug Rabson 	free(tests[i].name);
431c19800e8SDoug Rabson     return ret;
432c19800e8SDoug Rabson }
433c19800e8SDoug Rabson 
434c19800e8SDoug Rabson static int
test_cmp_oid(void * a,void * b)435c19800e8SDoug Rabson test_cmp_oid (void *a, void *b)
436c19800e8SDoug Rabson {
437c19800e8SDoug Rabson     return der_heim_oid_cmp((heim_oid *)a, (heim_oid *)b);
438c19800e8SDoug Rabson }
439c19800e8SDoug Rabson 
440c19800e8SDoug Rabson static unsigned oid_comp1[] = { 1, 1, 1 };
441c19800e8SDoug Rabson static unsigned oid_comp2[] = { 1, 1 };
442c19800e8SDoug Rabson static unsigned oid_comp3[] = { 6, 15, 1 };
443c19800e8SDoug Rabson static unsigned oid_comp4[] = { 6, 15 };
444c19800e8SDoug Rabson 
445c19800e8SDoug Rabson static int
test_oid(void)446c19800e8SDoug Rabson test_oid (void)
447c19800e8SDoug Rabson {
448c19800e8SDoug Rabson     struct test_case tests[] = {
449c19800e8SDoug Rabson 	{NULL, 2, "\x29\x01"},
450c19800e8SDoug Rabson 	{NULL, 1, "\x29"},
451c19800e8SDoug Rabson 	{NULL, 2, "\xff\x01"},
452c19800e8SDoug Rabson 	{NULL, 1, "\xff"}
453c19800e8SDoug Rabson     };
454c19800e8SDoug Rabson     heim_oid values[] = {
455c19800e8SDoug Rabson 	{ 3, oid_comp1 },
456c19800e8SDoug Rabson 	{ 2, oid_comp2 },
457c19800e8SDoug Rabson 	{ 3, oid_comp3 },
458c19800e8SDoug Rabson 	{ 2, oid_comp4 }
459c19800e8SDoug Rabson     };
460c19800e8SDoug Rabson     int i, ret;
461c19800e8SDoug Rabson     int ntests = sizeof(tests) / sizeof(*tests);
462c19800e8SDoug Rabson 
463c19800e8SDoug Rabson     for (i = 0; i < ntests; ++i) {
464c19800e8SDoug Rabson 	tests[i].val = &values[i];
465*ae771770SStanislav Sedov 	if (asprintf (&tests[i].name, "oid %d", i) < 0)
466*ae771770SStanislav Sedov 	    errx(1, "malloc");
467c19800e8SDoug Rabson 	if (tests[i].name == NULL)
468c19800e8SDoug Rabson 	    errx(1, "malloc");
469c19800e8SDoug Rabson     }
470c19800e8SDoug Rabson 
471c19800e8SDoug Rabson     ret = generic_test (tests, ntests, sizeof(heim_oid),
472c19800e8SDoug Rabson 			(generic_encode)der_put_oid,
473c19800e8SDoug Rabson 			(generic_length)der_length_oid,
474c19800e8SDoug Rabson 			(generic_decode)der_get_oid,
475c19800e8SDoug Rabson 			(generic_free)der_free_oid,
476*ae771770SStanislav Sedov 			test_cmp_oid,
477*ae771770SStanislav Sedov 			NULL);
478c19800e8SDoug Rabson     for (i = 0; i < ntests; ++i)
479c19800e8SDoug Rabson 	free(tests[i].name);
480c19800e8SDoug Rabson     return ret;
481c19800e8SDoug Rabson }
482c19800e8SDoug Rabson 
483c19800e8SDoug Rabson static int
test_cmp_bit_string(void * a,void * b)484c19800e8SDoug Rabson test_cmp_bit_string (void *a, void *b)
485c19800e8SDoug Rabson {
486c19800e8SDoug Rabson     return der_heim_bit_string_cmp((heim_bit_string *)a, (heim_bit_string *)b);
487c19800e8SDoug Rabson }
488c19800e8SDoug Rabson 
489c19800e8SDoug Rabson static int
test_bit_string(void)490c19800e8SDoug Rabson test_bit_string (void)
491c19800e8SDoug Rabson {
492c19800e8SDoug Rabson     struct test_case tests[] = {
493c19800e8SDoug Rabson 	{NULL, 1, "\x00"}
494c19800e8SDoug Rabson     };
495c19800e8SDoug Rabson     heim_bit_string values[] = {
496c19800e8SDoug Rabson 	{ 0, "" }
497c19800e8SDoug Rabson     };
498c19800e8SDoug Rabson     int i, ret;
499c19800e8SDoug Rabson     int ntests = sizeof(tests) / sizeof(*tests);
500c19800e8SDoug Rabson 
501c19800e8SDoug Rabson     for (i = 0; i < ntests; ++i) {
502c19800e8SDoug Rabson 	tests[i].val = &values[i];
503*ae771770SStanislav Sedov 	if (asprintf (&tests[i].name, "bit_string %d", i) < 0)
504*ae771770SStanislav Sedov 	    errx(1, "malloc");
505c19800e8SDoug Rabson 	if (tests[i].name == NULL)
506c19800e8SDoug Rabson 	    errx(1, "malloc");
507c19800e8SDoug Rabson     }
508c19800e8SDoug Rabson 
509c19800e8SDoug Rabson     ret = generic_test (tests, ntests, sizeof(heim_bit_string),
510c19800e8SDoug Rabson 			(generic_encode)der_put_bit_string,
511c19800e8SDoug Rabson 			(generic_length)der_length_bit_string,
512c19800e8SDoug Rabson 			(generic_decode)der_get_bit_string,
513c19800e8SDoug Rabson 			(generic_free)der_free_bit_string,
514*ae771770SStanislav Sedov 			test_cmp_bit_string,
515*ae771770SStanislav Sedov 			NULL);
516c19800e8SDoug Rabson     for (i = 0; i < ntests; ++i)
517c19800e8SDoug Rabson 	free(tests[i].name);
518c19800e8SDoug Rabson     return ret;
519c19800e8SDoug Rabson }
520c19800e8SDoug Rabson 
521c19800e8SDoug Rabson static int
test_cmp_heim_integer(void * a,void * b)522c19800e8SDoug Rabson test_cmp_heim_integer (void *a, void *b)
523c19800e8SDoug Rabson {
524c19800e8SDoug Rabson     return der_heim_integer_cmp((heim_integer *)a, (heim_integer *)b);
525c19800e8SDoug Rabson }
526c19800e8SDoug Rabson 
527c19800e8SDoug Rabson static int
test_heim_integer(void)528c19800e8SDoug Rabson test_heim_integer (void)
529c19800e8SDoug Rabson {
530c19800e8SDoug Rabson     struct test_case tests[] = {
531c19800e8SDoug Rabson 	{NULL, 2, "\xfe\x01"},
532c19800e8SDoug Rabson 	{NULL, 2, "\xef\x01"},
533c19800e8SDoug Rabson 	{NULL, 3, "\xff\x00\xff"},
534c19800e8SDoug Rabson 	{NULL, 3, "\xff\x01\x00"},
535c19800e8SDoug Rabson 	{NULL, 1, "\x00"},
536c19800e8SDoug Rabson 	{NULL, 1, "\x01"},
537c19800e8SDoug Rabson 	{NULL, 2, "\x00\x80"}
538c19800e8SDoug Rabson     };
539c19800e8SDoug Rabson 
540c19800e8SDoug Rabson     heim_integer values[] = {
541c19800e8SDoug Rabson 	{ 2, "\x01\xff", 1 },
542c19800e8SDoug Rabson 	{ 2, "\x10\xff", 1 },
543c19800e8SDoug Rabson 	{ 2, "\xff\x01", 1 },
544c19800e8SDoug Rabson 	{ 2, "\xff\x00", 1 },
545c19800e8SDoug Rabson 	{ 0, "", 0 },
546c19800e8SDoug Rabson 	{ 1, "\x01", 0 },
547c19800e8SDoug Rabson 	{ 1, "\x80", 0 }
548c19800e8SDoug Rabson     };
549c19800e8SDoug Rabson     int i, ret;
550c19800e8SDoug Rabson     int ntests = sizeof(tests) / sizeof(tests[0]);
551c19800e8SDoug Rabson     size_t size;
552c19800e8SDoug Rabson     heim_integer i2;
553c19800e8SDoug Rabson 
554c19800e8SDoug Rabson     for (i = 0; i < ntests; ++i) {
555c19800e8SDoug Rabson 	tests[i].val = &values[i];
556*ae771770SStanislav Sedov 	if (asprintf (&tests[i].name, "heim_integer %d", i) < 0)
557*ae771770SStanislav Sedov 	    errx(1, "malloc");
558c19800e8SDoug Rabson 	if (tests[i].name == NULL)
559c19800e8SDoug Rabson 	    errx(1, "malloc");
560c19800e8SDoug Rabson     }
561c19800e8SDoug Rabson 
562c19800e8SDoug Rabson     ret = generic_test (tests, ntests, sizeof(heim_integer),
563c19800e8SDoug Rabson 			(generic_encode)der_put_heim_integer,
564c19800e8SDoug Rabson 			(generic_length)der_length_heim_integer,
565c19800e8SDoug Rabson 			(generic_decode)der_get_heim_integer,
566c19800e8SDoug Rabson 			(generic_free)der_free_heim_integer,
567*ae771770SStanislav Sedov 			test_cmp_heim_integer,
568*ae771770SStanislav Sedov 			NULL);
569c19800e8SDoug Rabson     for (i = 0; i < ntests; ++i)
570c19800e8SDoug Rabson 	free (tests[i].name);
571c19800e8SDoug Rabson     if (ret)
572c19800e8SDoug Rabson 	return ret;
573c19800e8SDoug Rabson 
574c19800e8SDoug Rabson     /* test zero length integer (BER format) */
575c19800e8SDoug Rabson     ret = der_get_heim_integer(NULL, 0, &i2, &size);
576c19800e8SDoug Rabson     if (ret)
577c19800e8SDoug Rabson 	errx(1, "der_get_heim_integer");
578c19800e8SDoug Rabson     if (i2.length != 0)
579c19800e8SDoug Rabson 	errx(1, "der_get_heim_integer wrong length");
580c19800e8SDoug Rabson     der_free_heim_integer(&i2);
581c19800e8SDoug Rabson 
582c19800e8SDoug Rabson     return 0;
583c19800e8SDoug Rabson }
584c19800e8SDoug Rabson 
585c19800e8SDoug Rabson static int
test_cmp_boolean(void * a,void * b)586c19800e8SDoug Rabson test_cmp_boolean (void *a, void *b)
587c19800e8SDoug Rabson {
588c19800e8SDoug Rabson     return !!*(int *)a != !!*(int *)b;
589c19800e8SDoug Rabson }
590c19800e8SDoug Rabson 
591c19800e8SDoug Rabson static int
test_boolean(void)592c19800e8SDoug Rabson test_boolean (void)
593c19800e8SDoug Rabson {
594c19800e8SDoug Rabson     struct test_case tests[] = {
595c19800e8SDoug Rabson 	{NULL, 1, "\xff"},
596c19800e8SDoug Rabson 	{NULL, 1, "\x00"}
597c19800e8SDoug Rabson     };
598c19800e8SDoug Rabson 
599c19800e8SDoug Rabson     int values[] = { 1, 0 };
600c19800e8SDoug Rabson     int i, ret;
601c19800e8SDoug Rabson     int ntests = sizeof(tests) / sizeof(tests[0]);
602c19800e8SDoug Rabson     size_t size;
603c19800e8SDoug Rabson     heim_integer i2;
604c19800e8SDoug Rabson 
605c19800e8SDoug Rabson     for (i = 0; i < ntests; ++i) {
606c19800e8SDoug Rabson 	tests[i].val = &values[i];
607*ae771770SStanislav Sedov 	if (asprintf (&tests[i].name, "heim_boolean %d", i) < 0)
608*ae771770SStanislav Sedov 	    errx(1, "malloc");
609c19800e8SDoug Rabson 	if (tests[i].name == NULL)
610c19800e8SDoug Rabson 	    errx(1, "malloc");
611c19800e8SDoug Rabson     }
612c19800e8SDoug Rabson 
613c19800e8SDoug Rabson     ret = generic_test (tests, ntests, sizeof(int),
614c19800e8SDoug Rabson 			(generic_encode)der_put_boolean,
615c19800e8SDoug Rabson 			(generic_length)der_length_boolean,
616c19800e8SDoug Rabson 			(generic_decode)der_get_boolean,
617c19800e8SDoug Rabson 			(generic_free)NULL,
618*ae771770SStanislav Sedov 			test_cmp_boolean,
619*ae771770SStanislav Sedov 			NULL);
620c19800e8SDoug Rabson     for (i = 0; i < ntests; ++i)
621c19800e8SDoug Rabson 	free (tests[i].name);
622c19800e8SDoug Rabson     if (ret)
623c19800e8SDoug Rabson 	return ret;
624c19800e8SDoug Rabson 
625c19800e8SDoug Rabson     /* test zero length integer (BER format) */
626c19800e8SDoug Rabson     ret = der_get_heim_integer(NULL, 0, &i2, &size);
627c19800e8SDoug Rabson     if (ret)
628c19800e8SDoug Rabson 	errx(1, "der_get_heim_integer");
629c19800e8SDoug Rabson     if (i2.length != 0)
630c19800e8SDoug Rabson 	errx(1, "der_get_heim_integer wrong length");
631c19800e8SDoug Rabson     der_free_heim_integer(&i2);
632c19800e8SDoug Rabson 
633c19800e8SDoug Rabson     return 0;
634c19800e8SDoug Rabson }
635c19800e8SDoug Rabson 
636c19800e8SDoug Rabson static int
check_fail_unsigned(void)637c19800e8SDoug Rabson check_fail_unsigned(void)
638c19800e8SDoug Rabson {
639c19800e8SDoug Rabson     struct test_case tests[] = {
640c19800e8SDoug Rabson 	{NULL, sizeof(unsigned) + 1,
641c19800e8SDoug Rabson 	 "\x01\x01\x01\x01\x01\x01\x01\x01\x01", "data overrun" }
642c19800e8SDoug Rabson     };
643c19800e8SDoug Rabson     int ntests = sizeof(tests) / sizeof(*tests);
644c19800e8SDoug Rabson 
645c19800e8SDoug Rabson     return generic_decode_fail(tests, ntests, sizeof(unsigned),
646c19800e8SDoug Rabson 			       (generic_decode)der_get_unsigned);
647c19800e8SDoug Rabson }
648c19800e8SDoug Rabson 
649c19800e8SDoug Rabson static int
check_fail_integer(void)650c19800e8SDoug Rabson check_fail_integer(void)
651c19800e8SDoug Rabson {
652c19800e8SDoug Rabson     struct test_case tests[] = {
653c19800e8SDoug Rabson 	{NULL, sizeof(int) + 1,
654c19800e8SDoug Rabson 	 "\x01\x01\x01\x01\x01\x01\x01\x01\x01", "data overrun" }
655c19800e8SDoug Rabson     };
656c19800e8SDoug Rabson     int ntests = sizeof(tests) / sizeof(*tests);
657c19800e8SDoug Rabson 
658c19800e8SDoug Rabson     return generic_decode_fail(tests, ntests, sizeof(int),
659c19800e8SDoug Rabson 			       (generic_decode)der_get_integer);
660c19800e8SDoug Rabson }
661c19800e8SDoug Rabson 
662c19800e8SDoug Rabson static int
check_fail_length(void)663c19800e8SDoug Rabson check_fail_length(void)
664c19800e8SDoug Rabson {
665c19800e8SDoug Rabson     struct test_case tests[] = {
666c19800e8SDoug Rabson 	{NULL, 0, "", "empty input data"},
667c19800e8SDoug Rabson 	{NULL, 1, "\x82", "internal length overrun" }
668c19800e8SDoug Rabson     };
669c19800e8SDoug Rabson     int ntests = sizeof(tests) / sizeof(*tests);
670c19800e8SDoug Rabson 
671c19800e8SDoug Rabson     return generic_decode_fail(tests, ntests, sizeof(size_t),
672c19800e8SDoug Rabson 			       (generic_decode)der_get_length);
673c19800e8SDoug Rabson }
674c19800e8SDoug Rabson 
675c19800e8SDoug Rabson static int
check_fail_boolean(void)676c19800e8SDoug Rabson check_fail_boolean(void)
677c19800e8SDoug Rabson {
678c19800e8SDoug Rabson     struct test_case tests[] = {
679c19800e8SDoug Rabson 	{NULL, 0, "", "empty input data"}
680c19800e8SDoug Rabson     };
681c19800e8SDoug Rabson     int ntests = sizeof(tests) / sizeof(*tests);
682c19800e8SDoug Rabson 
683c19800e8SDoug Rabson     return generic_decode_fail(tests, ntests, sizeof(int),
684c19800e8SDoug Rabson 			       (generic_decode)der_get_boolean);
685c19800e8SDoug Rabson }
686c19800e8SDoug Rabson 
687c19800e8SDoug Rabson static int
check_fail_general_string(void)688c19800e8SDoug Rabson check_fail_general_string(void)
689c19800e8SDoug Rabson {
690c19800e8SDoug Rabson     struct test_case tests[] = {
691c19800e8SDoug Rabson 	{ NULL, 3, "A\x00i", "NUL char in string"}
692c19800e8SDoug Rabson     };
693c19800e8SDoug Rabson     int ntests = sizeof(tests) / sizeof(*tests);
694c19800e8SDoug Rabson 
695c19800e8SDoug Rabson     return generic_decode_fail(tests, ntests, sizeof(heim_general_string),
696c19800e8SDoug Rabson 			       (generic_decode)der_get_general_string);
697c19800e8SDoug Rabson }
698c19800e8SDoug Rabson 
699c19800e8SDoug Rabson static int
check_fail_bmp_string(void)700c19800e8SDoug Rabson check_fail_bmp_string(void)
701c19800e8SDoug Rabson {
702c19800e8SDoug Rabson     struct test_case tests[] = {
703c19800e8SDoug Rabson 	{NULL, 1, "\x00", "odd (1) length bmpstring"},
704c19800e8SDoug Rabson 	{NULL, 3, "\x00\x00\x00", "odd (3) length bmpstring"}
705c19800e8SDoug Rabson     };
706c19800e8SDoug Rabson     int ntests = sizeof(tests) / sizeof(*tests);
707c19800e8SDoug Rabson 
708c19800e8SDoug Rabson     return generic_decode_fail(tests, ntests, sizeof(heim_bmp_string),
709c19800e8SDoug Rabson 			       (generic_decode)der_get_bmp_string);
710c19800e8SDoug Rabson }
711c19800e8SDoug Rabson 
712c19800e8SDoug Rabson static int
check_fail_universal_string(void)713c19800e8SDoug Rabson check_fail_universal_string(void)
714c19800e8SDoug Rabson {
715c19800e8SDoug Rabson     struct test_case tests[] = {
716c19800e8SDoug Rabson 	{NULL, 1, "\x00", "x & 3 == 1 universal string"},
717c19800e8SDoug Rabson 	{NULL, 2, "\x00\x00", "x & 3 == 2 universal string"},
718c19800e8SDoug Rabson 	{NULL, 3, "\x00\x00\x00", "x & 3 == 3 universal string"},
719c19800e8SDoug Rabson 	{NULL, 5, "\x00\x00\x00\x00\x00", "x & 3 == 1 universal string"},
720c19800e8SDoug Rabson 	{NULL, 6, "\x00\x00\x00\x00\x00\x00", "x & 3 == 2 universal string"},
721c19800e8SDoug Rabson 	{NULL, 7, "\x00\x00\x00\x00\x00\x00\x00", "x & 3 == 3 universal string"}
722c19800e8SDoug Rabson     };
723c19800e8SDoug Rabson     int ntests = sizeof(tests) / sizeof(*tests);
724c19800e8SDoug Rabson 
725c19800e8SDoug Rabson     return generic_decode_fail(tests, ntests, sizeof(heim_universal_string),
726c19800e8SDoug Rabson 			       (generic_decode)der_get_universal_string);
727c19800e8SDoug Rabson }
728c19800e8SDoug Rabson 
729c19800e8SDoug Rabson static int
check_fail_heim_integer(void)730c19800e8SDoug Rabson check_fail_heim_integer(void)
731c19800e8SDoug Rabson {
732c19800e8SDoug Rabson #if 0
733c19800e8SDoug Rabson     struct test_case tests[] = {
734c19800e8SDoug Rabson     };
735c19800e8SDoug Rabson     int ntests = sizeof(tests) / sizeof(*tests);
736c19800e8SDoug Rabson 
737c19800e8SDoug Rabson     return generic_decode_fail(tests, ntests, sizeof(heim_integer),
738c19800e8SDoug Rabson 			       (generic_decode)der_get_heim_integer);
739c19800e8SDoug Rabson #else
740c19800e8SDoug Rabson     return 0;
741c19800e8SDoug Rabson #endif
742c19800e8SDoug Rabson }
743c19800e8SDoug Rabson 
744c19800e8SDoug Rabson static int
check_fail_generalized_time(void)745c19800e8SDoug Rabson check_fail_generalized_time(void)
746c19800e8SDoug Rabson {
747c19800e8SDoug Rabson     struct test_case tests[] = {
748c19800e8SDoug Rabson 	{NULL, 1, "\x00", "no time"}
749c19800e8SDoug Rabson     };
750c19800e8SDoug Rabson     int ntests = sizeof(tests) / sizeof(*tests);
751c19800e8SDoug Rabson 
752c19800e8SDoug Rabson     return generic_decode_fail(tests, ntests, sizeof(time_t),
753c19800e8SDoug Rabson 			       (generic_decode)der_get_generalized_time);
754c19800e8SDoug Rabson }
755c19800e8SDoug Rabson 
756c19800e8SDoug Rabson static int
check_fail_oid(void)757c19800e8SDoug Rabson check_fail_oid(void)
758c19800e8SDoug Rabson {
759c19800e8SDoug Rabson     struct test_case tests[] = {
760c19800e8SDoug Rabson 	{NULL, 0, "", "empty input data"},
761c19800e8SDoug Rabson 	{NULL, 2, "\x00\x80", "last byte continuation" },
762c19800e8SDoug Rabson 	{NULL, 11, "\x00\x81\x80\x80\x80\x80\x80\x80\x80\x80\x00",
763c19800e8SDoug Rabson 	"oid element overflow" }
764c19800e8SDoug Rabson     };
765c19800e8SDoug Rabson     int ntests = sizeof(tests) / sizeof(*tests);
766c19800e8SDoug Rabson 
767c19800e8SDoug Rabson     return generic_decode_fail(tests, ntests, sizeof(heim_oid),
768c19800e8SDoug Rabson 			       (generic_decode)der_get_oid);
769c19800e8SDoug Rabson }
770c19800e8SDoug Rabson 
771c19800e8SDoug Rabson static int
check_fail_bitstring(void)772c19800e8SDoug Rabson check_fail_bitstring(void)
773c19800e8SDoug Rabson {
774c19800e8SDoug Rabson     struct test_case tests[] = {
775c19800e8SDoug Rabson 	{NULL, 0, "", "empty input data"},
776c19800e8SDoug Rabson 	{NULL, 1, "\x08", "larger then 8 bits trailer"},
777c19800e8SDoug Rabson 	{NULL, 1, "\x01", "to few bytes for bits"},
778c19800e8SDoug Rabson 	{NULL, -2, "\x00", "length overrun"},
779c19800e8SDoug Rabson 	{NULL, -1, "", "length to short"}
780c19800e8SDoug Rabson     };
781c19800e8SDoug Rabson     int ntests = sizeof(tests) / sizeof(*tests);
782c19800e8SDoug Rabson 
783c19800e8SDoug Rabson     return generic_decode_fail(tests, ntests, sizeof(heim_bit_string),
784c19800e8SDoug Rabson 			       (generic_decode)der_get_bit_string);
785c19800e8SDoug Rabson }
786c19800e8SDoug Rabson 
787c19800e8SDoug Rabson static int
check_heim_integer_same(const char * p,const char * norm_p,heim_integer * i)788c19800e8SDoug Rabson check_heim_integer_same(const char *p, const char *norm_p, heim_integer *i)
789c19800e8SDoug Rabson {
790c19800e8SDoug Rabson     heim_integer i2;
791c19800e8SDoug Rabson     char *str;
792c19800e8SDoug Rabson     int ret;
793c19800e8SDoug Rabson 
794c19800e8SDoug Rabson     ret = der_print_hex_heim_integer(i, &str);
795c19800e8SDoug Rabson     if (ret)
796c19800e8SDoug Rabson 	errx(1, "der_print_hex_heim_integer: %d", ret);
797c19800e8SDoug Rabson 
798c19800e8SDoug Rabson     if (strcmp(str, norm_p) != 0)
799c19800e8SDoug Rabson 	errx(1, "der_print_hex_heim_integer: %s != %s", str, p);
800c19800e8SDoug Rabson 
801c19800e8SDoug Rabson     ret = der_parse_hex_heim_integer(str, &i2);
802c19800e8SDoug Rabson     if (ret)
803c19800e8SDoug Rabson 	errx(1, "der_parse_hex_heim_integer: %d", ret);
804c19800e8SDoug Rabson 
805c19800e8SDoug Rabson     if (der_heim_integer_cmp(i, &i2) != 0)
806c19800e8SDoug Rabson 	errx(1, "der_heim_integer_cmp: p %s", p);
807c19800e8SDoug Rabson 
808c19800e8SDoug Rabson     der_free_heim_integer(&i2);
809c19800e8SDoug Rabson     free(str);
810c19800e8SDoug Rabson 
811c19800e8SDoug Rabson     ret = der_parse_hex_heim_integer(p, &i2);
812c19800e8SDoug Rabson     if (ret)
813c19800e8SDoug Rabson 	errx(1, "der_parse_hex_heim_integer: %d", ret);
814c19800e8SDoug Rabson 
815c19800e8SDoug Rabson     if (der_heim_integer_cmp(i, &i2) != 0)
816c19800e8SDoug Rabson 	errx(1, "der_heim_integer_cmp: norm");
817c19800e8SDoug Rabson 
818c19800e8SDoug Rabson     der_free_heim_integer(&i2);
819c19800e8SDoug Rabson 
820c19800e8SDoug Rabson     return 0;
821c19800e8SDoug Rabson }
822c19800e8SDoug Rabson 
823c19800e8SDoug Rabson static int
test_heim_int_format(void)824c19800e8SDoug Rabson test_heim_int_format(void)
825c19800e8SDoug Rabson {
826c19800e8SDoug Rabson     heim_integer i = { 1, "\x10", 0 };
827c19800e8SDoug Rabson     heim_integer i2 = { 1, "\x10", 1 };
828c19800e8SDoug Rabson     heim_integer i3 = { 1, "\01", 0 };
829c19800e8SDoug Rabson     char *p =
830c19800e8SDoug Rabson 	"FFFFFFFF" "FFFFFFFF" "C90FDAA2" "2168C234" "C4C6628B" "80DC1CD1"
831c19800e8SDoug Rabson 	"29024E08" "8A67CC74" "020BBEA6" "3B139B22" "514A0879" "8E3404DD"
832c19800e8SDoug Rabson 	"EF9519B3" "CD3A431B" "302B0A6D" "F25F1437" "4FE1356D" "6D51C245"
833c19800e8SDoug Rabson 	"E485B576" "625E7EC6" "F44C42E9" "A637ED6B" "0BFF5CB6" "F406B7ED"
834c19800e8SDoug Rabson 	"EE386BFB" "5A899FA5" "AE9F2411" "7C4B1FE6" "49286651" "ECE65381"
835c19800e8SDoug Rabson 	"FFFFFFFF" "FFFFFFFF";
836c19800e8SDoug Rabson     heim_integer bni = {
837c19800e8SDoug Rabson 	128,
838c19800e8SDoug Rabson 	"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xC9\x0F\xDA\xA2"
839c19800e8SDoug Rabson 	"\x21\x68\xC2\x34\xC4\xC6\x62\x8B\x80\xDC\x1C\xD1"
840c19800e8SDoug Rabson 	"\x29\x02\x4E\x08\x8A\x67\xCC\x74\x02\x0B\xBE\xA6"
841c19800e8SDoug Rabson 	"\x3B\x13\x9B\x22\x51\x4A\x08\x79\x8E\x34\x04\xDD"
842c19800e8SDoug Rabson 	"\xEF\x95\x19\xB3\xCD\x3A\x43\x1B\x30\x2B\x0A\x6D"
843c19800e8SDoug Rabson 	"\xF2\x5F\x14\x37\x4F\xE1\x35\x6D\x6D\x51\xC2\x45"
844c19800e8SDoug Rabson 	"\xE4\x85\xB5\x76\x62\x5E\x7E\xC6\xF4\x4C\x42\xE9"
845c19800e8SDoug Rabson 	"\xA6\x37\xED\x6B\x0B\xFF\x5C\xB6\xF4\x06\xB7\xED"
846c19800e8SDoug Rabson 	"\xEE\x38\x6B\xFB\x5A\x89\x9F\xA5\xAE\x9F\x24\x11"
847c19800e8SDoug Rabson 	"\x7C\x4B\x1F\xE6\x49\x28\x66\x51\xEC\xE6\x53\x81"
848c19800e8SDoug Rabson 	"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF",
849c19800e8SDoug Rabson 	0
850c19800e8SDoug Rabson     };
851c19800e8SDoug Rabson     heim_integer f;
852c19800e8SDoug Rabson     int ret = 0;
853c19800e8SDoug Rabson 
854c19800e8SDoug Rabson     ret += check_heim_integer_same(p, p, &bni);
855c19800e8SDoug Rabson     ret += check_heim_integer_same("10", "10", &i);
856c19800e8SDoug Rabson     ret += check_heim_integer_same("00000010", "10", &i);
857c19800e8SDoug Rabson     ret += check_heim_integer_same("-10", "-10", &i2);
858c19800e8SDoug Rabson     ret += check_heim_integer_same("-00000010", "-10", &i2);
859c19800e8SDoug Rabson     ret += check_heim_integer_same("01", "01", &i3);
860c19800e8SDoug Rabson     ret += check_heim_integer_same("1", "01", &i3);
861c19800e8SDoug Rabson 
862c19800e8SDoug Rabson     {
863c19800e8SDoug Rabson 	int r;
864c19800e8SDoug Rabson 	r = der_parse_hex_heim_integer("-", &f);
865c19800e8SDoug Rabson 	if (r == 0) {
866c19800e8SDoug Rabson 	    der_free_heim_integer(&f);
867c19800e8SDoug Rabson 	    ret++;
868c19800e8SDoug Rabson 	}
869c19800e8SDoug Rabson 	/* used to cause UMR */
870c19800e8SDoug Rabson 	r = der_parse_hex_heim_integer("00", &f);
871c19800e8SDoug Rabson 	if (r == 0)
872c19800e8SDoug Rabson 	    der_free_heim_integer(&f);
873c19800e8SDoug Rabson 	else
874c19800e8SDoug Rabson 	    ret++;
875c19800e8SDoug Rabson     }
876c19800e8SDoug Rabson 
877c19800e8SDoug Rabson     return ret;
878c19800e8SDoug Rabson }
879c19800e8SDoug Rabson 
880c19800e8SDoug Rabson static int
test_heim_oid_format_same(const char * str,const heim_oid * oid)881c19800e8SDoug Rabson test_heim_oid_format_same(const char *str, const heim_oid *oid)
882c19800e8SDoug Rabson {
883c19800e8SDoug Rabson     int ret;
884c19800e8SDoug Rabson     char *p;
885c19800e8SDoug Rabson     heim_oid o2;
886c19800e8SDoug Rabson 
887c19800e8SDoug Rabson     ret = der_print_heim_oid(oid, ' ', &p);
888c19800e8SDoug Rabson     if (ret) {
889c19800e8SDoug Rabson 	printf("fail to print oid: %s\n", str);
890c19800e8SDoug Rabson 	return 1;
891c19800e8SDoug Rabson     }
892c19800e8SDoug Rabson     ret = strcmp(p, str);
893c19800e8SDoug Rabson     if (ret) {
894c19800e8SDoug Rabson 	printf("oid %s != formated oid %s\n", str, p);
895c19800e8SDoug Rabson 	free(p);
896c19800e8SDoug Rabson 	return ret;
897c19800e8SDoug Rabson     }
898c19800e8SDoug Rabson 
899c19800e8SDoug Rabson     ret = der_parse_heim_oid(p, " ", &o2);
900c19800e8SDoug Rabson     if (ret) {
901c19800e8SDoug Rabson 	printf("failed to parse %s\n", p);
902c19800e8SDoug Rabson 	free(p);
903c19800e8SDoug Rabson 	return ret;
904c19800e8SDoug Rabson     }
905c19800e8SDoug Rabson     free(p);
906c19800e8SDoug Rabson     ret = der_heim_oid_cmp(&o2, oid);
907c19800e8SDoug Rabson     der_free_oid(&o2);
908c19800e8SDoug Rabson 
909c19800e8SDoug Rabson     return ret;
910c19800e8SDoug Rabson }
911c19800e8SDoug Rabson 
912c19800e8SDoug Rabson static unsigned sha1_oid_tree[] = { 1, 3, 14, 3, 2, 26 };
913c19800e8SDoug Rabson 
914c19800e8SDoug Rabson static int
test_heim_oid_format(void)915c19800e8SDoug Rabson test_heim_oid_format(void)
916c19800e8SDoug Rabson {
917c19800e8SDoug Rabson     heim_oid sha1 = { 6, sha1_oid_tree };
918c19800e8SDoug Rabson     int ret = 0;
919c19800e8SDoug Rabson 
920c19800e8SDoug Rabson     ret += test_heim_oid_format_same("1 3 14 3 2 26", &sha1);
921c19800e8SDoug Rabson 
922c19800e8SDoug Rabson     return ret;
923c19800e8SDoug Rabson }
924c19800e8SDoug Rabson 
925c19800e8SDoug Rabson static int
check_trailing_nul(void)926c19800e8SDoug Rabson check_trailing_nul(void)
927c19800e8SDoug Rabson {
928c19800e8SDoug Rabson     int i, ret;
929c19800e8SDoug Rabson     struct {
930c19800e8SDoug Rabson 	int fail;
931c19800e8SDoug Rabson 	const unsigned char *p;
932c19800e8SDoug Rabson 	size_t len;
933c19800e8SDoug Rabson 	const char *s;
934c19800e8SDoug Rabson 	size_t size;
935c19800e8SDoug Rabson     } foo[] = {
936c19800e8SDoug Rabson 	{ 1, (const unsigned char *)"foo\x00o", 5, NULL, 0 },
937c19800e8SDoug Rabson 	{ 1, (const unsigned char *)"\x00o", 2, NULL, 0 },
938c19800e8SDoug Rabson 	{ 0, (const unsigned char *)"\x00\x00\x00\x00\x00", 5, "", 5 },
939c19800e8SDoug Rabson 	{ 0, (const unsigned char *)"\x00", 1, "", 1 },
940c19800e8SDoug Rabson 	{ 0, (const unsigned char *)"", 0, "", 0 },
941c19800e8SDoug Rabson 	{ 0, (const unsigned char *)"foo\x00\x00", 5, "foo", 5 },
942c19800e8SDoug Rabson 	{ 0, (const unsigned char *)"foo\0", 4, "foo", 4 },
943c19800e8SDoug Rabson 	{ 0, (const unsigned char *)"foo", 3, "foo", 3 }
944c19800e8SDoug Rabson     };
945c19800e8SDoug Rabson 
946c19800e8SDoug Rabson     for (i = 0; i < sizeof(foo)/sizeof(foo[0]); i++) {
947c19800e8SDoug Rabson 	char *s;
948c19800e8SDoug Rabson 	size_t size;
949c19800e8SDoug Rabson 	ret = der_get_general_string(foo[i].p, foo[i].len, &s, &size);
950c19800e8SDoug Rabson 	if (foo[i].fail) {
951c19800e8SDoug Rabson 	    if (ret == 0)
952c19800e8SDoug Rabson 		errx(1, "check %d NULL didn't fail", i);
953c19800e8SDoug Rabson 	    continue;
954c19800e8SDoug Rabson 	}
955c19800e8SDoug Rabson 	if (ret)
956c19800e8SDoug Rabson 	    errx(1, "NULL check %d der_get_general_string failed", i);
957c19800e8SDoug Rabson 	if (foo[i].size != size)
958c19800e8SDoug Rabson 	    errx(1, "NUL check i = %d size failed", i);
959c19800e8SDoug Rabson 	if (strcmp(foo[i].s, s) != 0)
960c19800e8SDoug Rabson 	    errx(1, "NUL check i = %d content failed", i);
961c19800e8SDoug Rabson 	free(s);
962c19800e8SDoug Rabson     }
963c19800e8SDoug Rabson     return 0;
964c19800e8SDoug Rabson }
965c19800e8SDoug Rabson 
966c19800e8SDoug Rabson static int
test_misc_cmp(void)967c19800e8SDoug Rabson test_misc_cmp(void)
968c19800e8SDoug Rabson {
969c19800e8SDoug Rabson     int ret;
970c19800e8SDoug Rabson 
971c19800e8SDoug Rabson     /* diffrent lengths are diffrent */
972c19800e8SDoug Rabson     {
973c19800e8SDoug Rabson 	const heim_octet_string os1 = { 1, "a" } , os2 = { 0, NULL };
974c19800e8SDoug Rabson 	ret = der_heim_octet_string_cmp(&os1, &os2);
975c19800e8SDoug Rabson 	if (ret == 0)
976c19800e8SDoug Rabson 	    return 1;
977c19800e8SDoug Rabson     }
978c19800e8SDoug Rabson     /* diffrent data are diffrent */
979c19800e8SDoug Rabson     {
980c19800e8SDoug Rabson 	const heim_octet_string os1 = { 1, "a" } , os2 = { 1, "b" };
981c19800e8SDoug Rabson 	ret = der_heim_octet_string_cmp(&os1, &os2);
982c19800e8SDoug Rabson 	if (ret == 0)
983c19800e8SDoug Rabson 	    return 1;
984c19800e8SDoug Rabson     }
985c19800e8SDoug Rabson     /* diffrent lengths are diffrent */
986c19800e8SDoug Rabson     {
987c19800e8SDoug Rabson 	const heim_bit_string bs1 = { 8, "a" } , bs2 = { 7, "a" };
988c19800e8SDoug Rabson 	ret = der_heim_bit_string_cmp(&bs1, &bs2);
989c19800e8SDoug Rabson 	if (ret == 0)
990c19800e8SDoug Rabson 	    return 1;
991c19800e8SDoug Rabson     }
992c19800e8SDoug Rabson     /* diffrent data are diffrent */
993c19800e8SDoug Rabson     {
994c19800e8SDoug Rabson 	const heim_bit_string bs1 = { 7, "\x0f" } , bs2 = { 7, "\x02" };
995c19800e8SDoug Rabson 	ret = der_heim_bit_string_cmp(&bs1, &bs2);
996c19800e8SDoug Rabson 	if (ret == 0)
997c19800e8SDoug Rabson 	    return 1;
998c19800e8SDoug Rabson     }
999c19800e8SDoug Rabson     /* diffrent lengths are diffrent */
1000c19800e8SDoug Rabson     {
1001c19800e8SDoug Rabson 	uint16_t data = 1;
1002c19800e8SDoug Rabson 	heim_bmp_string bs1 = { 1, NULL } , bs2 = { 0, NULL };
1003c19800e8SDoug Rabson 	bs1.data = &data;
1004c19800e8SDoug Rabson 	ret = der_heim_bmp_string_cmp(&bs1, &bs2);
1005c19800e8SDoug Rabson 	if (ret == 0)
1006c19800e8SDoug Rabson 	    return 1;
1007c19800e8SDoug Rabson     }
1008c19800e8SDoug Rabson     /* diffrent lengths are diffrent */
1009c19800e8SDoug Rabson     {
1010c19800e8SDoug Rabson 	uint32_t data;
1011c19800e8SDoug Rabson 	heim_universal_string us1 = { 1, NULL } , us2 = { 0, NULL };
1012c19800e8SDoug Rabson 	us1.data = &data;
1013c19800e8SDoug Rabson 	ret = der_heim_universal_string_cmp(&us1, &us2);
1014c19800e8SDoug Rabson 	if (ret == 0)
1015c19800e8SDoug Rabson 	    return 1;
1016c19800e8SDoug Rabson     }
1017c19800e8SDoug Rabson     /* same */
1018c19800e8SDoug Rabson     {
1019c19800e8SDoug Rabson 	uint32_t data = (uint32_t)'a';
1020c19800e8SDoug Rabson 	heim_universal_string us1 = { 1, NULL } , us2 = { 1, NULL };
1021c19800e8SDoug Rabson 	us1.data = &data;
1022c19800e8SDoug Rabson 	us2.data = &data;
1023c19800e8SDoug Rabson 	ret = der_heim_universal_string_cmp(&us1, &us2);
1024c19800e8SDoug Rabson 	if (ret != 0)
1025c19800e8SDoug Rabson 	    return 1;
1026c19800e8SDoug Rabson     }
1027c19800e8SDoug Rabson 
1028c19800e8SDoug Rabson     return 0;
1029c19800e8SDoug Rabson }
1030c19800e8SDoug Rabson 
1031c19800e8SDoug Rabson static int
corner_generalized_time(void)1032c19800e8SDoug Rabson corner_generalized_time(void)
1033c19800e8SDoug Rabson {
1034c19800e8SDoug Rabson     const char *str = "760520140000Z";
1035c19800e8SDoug Rabson     size_t size;
1036c19800e8SDoug Rabson     time_t t;
1037c19800e8SDoug Rabson     int ret;
1038c19800e8SDoug Rabson 
1039c19800e8SDoug Rabson     ret = der_get_generalized_time((const unsigned char*)str, strlen(str),
1040c19800e8SDoug Rabson 				   &t, &size);
1041c19800e8SDoug Rabson     if (ret)
1042c19800e8SDoug Rabson 	return 1;
1043c19800e8SDoug Rabson     return 0;
1044c19800e8SDoug Rabson }
1045c19800e8SDoug Rabson 
1046c19800e8SDoug Rabson static int
corner_tag(void)1047c19800e8SDoug Rabson corner_tag(void)
1048c19800e8SDoug Rabson {
1049c19800e8SDoug Rabson     struct {
1050c19800e8SDoug Rabson 	int ok;
1051c19800e8SDoug Rabson 	const char *ptr;
1052c19800e8SDoug Rabson 	size_t len;
1053c19800e8SDoug Rabson     } tests[] = {
1054c19800e8SDoug Rabson 	{ 1, "\x00", 1 },
1055c19800e8SDoug Rabson 	{ 0, "\xff", 1 },
1056c19800e8SDoug Rabson 	{ 0, "\xff\xff\xff\xff\xff\xff\xff\xff", 8 }
1057c19800e8SDoug Rabson     };
1058c19800e8SDoug Rabson     int i, ret;
1059c19800e8SDoug Rabson     Der_class cl;
1060c19800e8SDoug Rabson     Der_type ty;
1061c19800e8SDoug Rabson     unsigned int tag;
1062c19800e8SDoug Rabson     size_t size;
1063c19800e8SDoug Rabson 
1064c19800e8SDoug Rabson     for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) {
1065c19800e8SDoug Rabson 	ret = der_get_tag((const unsigned char*)tests[i].ptr,
1066c19800e8SDoug Rabson 			  tests[i].len, &cl, &ty, &tag, &size);
1067c19800e8SDoug Rabson 	if (ret) {
1068c19800e8SDoug Rabson 	    if (tests[i].ok)
1069c19800e8SDoug Rabson 		errx(1, "failed while shouldn't");
1070c19800e8SDoug Rabson 	} else {
1071c19800e8SDoug Rabson 	    if (!tests[i].ok)
1072c19800e8SDoug Rabson 		errx(1, "passed while shouldn't");
1073c19800e8SDoug Rabson 	}
1074c19800e8SDoug Rabson     }
1075c19800e8SDoug Rabson     return 0;
1076b528cefcSMark Murray }
1077b528cefcSMark Murray 
1078b528cefcSMark Murray int
main(int argc,char ** argv)1079b528cefcSMark Murray main(int argc, char **argv)
1080b528cefcSMark Murray {
1081b528cefcSMark Murray     int ret = 0;
1082b528cefcSMark Murray 
1083b528cefcSMark Murray     ret += test_integer ();
1084c19800e8SDoug Rabson     ret += test_integer_more();
1085c19800e8SDoug Rabson     ret += test_unsigned ();
1086b528cefcSMark Murray     ret += test_octet_string ();
1087c19800e8SDoug Rabson     ret += test_bmp_string ();
1088c19800e8SDoug Rabson     ret += test_universal_string ();
1089b528cefcSMark Murray     ret += test_general_string ();
1090b528cefcSMark Murray     ret += test_generalized_time ();
1091c19800e8SDoug Rabson     ret += test_oid ();
1092c19800e8SDoug Rabson     ret += test_bit_string();
1093c19800e8SDoug Rabson     ret += test_heim_integer();
1094c19800e8SDoug Rabson     ret += test_boolean();
1095c19800e8SDoug Rabson 
1096c19800e8SDoug Rabson     ret += check_fail_unsigned();
1097c19800e8SDoug Rabson     ret += check_fail_integer();
1098c19800e8SDoug Rabson     ret += check_fail_length();
1099c19800e8SDoug Rabson     ret += check_fail_boolean();
1100c19800e8SDoug Rabson     ret += check_fail_general_string();
1101c19800e8SDoug Rabson     ret += check_fail_bmp_string();
1102c19800e8SDoug Rabson     ret += check_fail_universal_string();
1103c19800e8SDoug Rabson     ret += check_fail_heim_integer();
1104c19800e8SDoug Rabson     ret += check_fail_generalized_time();
1105c19800e8SDoug Rabson     ret += check_fail_oid();
1106c19800e8SDoug Rabson     ret += check_fail_bitstring();
1107c19800e8SDoug Rabson     ret += test_heim_int_format();
1108c19800e8SDoug Rabson     ret += test_heim_oid_format();
1109c19800e8SDoug Rabson     ret += check_trailing_nul();
1110c19800e8SDoug Rabson     ret += test_misc_cmp();
1111c19800e8SDoug Rabson     ret += corner_generalized_time();
1112c19800e8SDoug Rabson     ret += corner_tag();
1113b528cefcSMark Murray 
1114b528cefcSMark Murray     return ret;
1115b528cefcSMark Murray }
1116