1 /* $OpenBSD: tasn_typ.c,v 1.13 2015/07/24 15:09:52 jsing Exp $ */
2 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3  * project 2000.
4  */
5 /* ====================================================================
6  * Copyright (c) 2000 The OpenSSL Project.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in
17  *    the documentation and/or other materials provided with the
18  *    distribution.
19  *
20  * 3. All advertising materials mentioning features or use of this
21  *    software must display the following acknowledgment:
22  *    "This product includes software developed by the OpenSSL Project
23  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24  *
25  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26  *    endorse or promote products derived from this software without
27  *    prior written permission. For written permission, please contact
28  *    licensing@OpenSSL.org.
29  *
30  * 5. Products derived from this software may not be called "OpenSSL"
31  *    nor may "OpenSSL" appear in their names without prior written
32  *    permission of the OpenSSL Project.
33  *
34  * 6. Redistributions of any form whatsoever must retain the following
35  *    acknowledgment:
36  *    "This product includes software developed by the OpenSSL Project
37  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38  *
39  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
43  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50  * OF THE POSSIBILITY OF SUCH DAMAGE.
51  * ====================================================================
52  *
53  * This product includes cryptographic software written by Eric Young
54  * (eay@cryptsoft.com).  This product includes software written by Tim
55  * Hudson (tjh@cryptsoft.com).
56  *
57  */
58 #include <stdio.h>
59 #include <openssl/asn1.h>
60 #include <openssl/asn1t.h>
61 
62 /* Declarations for string types */
63 
64 const ASN1_ITEM ASN1_INTEGER_it = {
65 	.itype = ASN1_ITYPE_PRIMITIVE,
66 	.utype = V_ASN1_INTEGER,
67 	.sname = "ASN1_INTEGER",
68 };
69 
70 ASN1_INTEGER *
71 d2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **in, long len)
72 {
73 	return (ASN1_INTEGER *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
74 	    &ASN1_INTEGER_it);
75 }
76 
77 int
78 i2d_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **out)
79 {
80 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_INTEGER_it);
81 }
82 
83 ASN1_INTEGER *
84 ASN1_INTEGER_new(void)
85 {
86 	return (ASN1_INTEGER *)ASN1_item_new(&ASN1_INTEGER_it);
87 }
88 
89 void
90 ASN1_INTEGER_free(ASN1_INTEGER *a)
91 {
92 	ASN1_item_free((ASN1_VALUE *)a, &ASN1_INTEGER_it);
93 }
94 
95 
96 const ASN1_ITEM ASN1_ENUMERATED_it = {
97 	.itype = ASN1_ITYPE_PRIMITIVE,
98 	.utype = V_ASN1_ENUMERATED,
99 	.sname = "ASN1_ENUMERATED",
100 };
101 
102 ASN1_ENUMERATED *
103 d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a, const unsigned char **in, long len)
104 {
105 	return (ASN1_ENUMERATED *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
106 	    &ASN1_ENUMERATED_it);
107 }
108 
109 int
110 i2d_ASN1_ENUMERATED(ASN1_ENUMERATED *a, unsigned char **out)
111 {
112 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_ENUMERATED_it);
113 }
114 
115 ASN1_ENUMERATED *
116 ASN1_ENUMERATED_new(void)
117 {
118 	return (ASN1_ENUMERATED *)ASN1_item_new(&ASN1_ENUMERATED_it);
119 }
120 
121 void
122 ASN1_ENUMERATED_free(ASN1_ENUMERATED *a)
123 {
124 	ASN1_item_free((ASN1_VALUE *)a, &ASN1_ENUMERATED_it);
125 }
126 
127 
128 const ASN1_ITEM ASN1_BIT_STRING_it = {
129 	.itype = ASN1_ITYPE_PRIMITIVE,
130 	.utype = V_ASN1_BIT_STRING,
131 	.sname = "ASN1_BIT_STRING",
132 };
133 
134 ASN1_BIT_STRING *
135 d2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, const unsigned char **in, long len)
136 {
137 	return (ASN1_BIT_STRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
138 	    &ASN1_BIT_STRING_it);
139 }
140 
141 int
142 i2d_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **out)
143 {
144 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_BIT_STRING_it);
145 }
146 
147 ASN1_BIT_STRING *
148 ASN1_BIT_STRING_new(void)
149 {
150 	return (ASN1_BIT_STRING *)ASN1_item_new(&ASN1_BIT_STRING_it);
151 }
152 
153 void
154 ASN1_BIT_STRING_free(ASN1_BIT_STRING *a)
155 {
156 	ASN1_item_free((ASN1_VALUE *)a, &ASN1_BIT_STRING_it);
157 }
158 
159 
160 const ASN1_ITEM ASN1_OCTET_STRING_it = {
161 	.itype = ASN1_ITYPE_PRIMITIVE,
162 	.utype = V_ASN1_OCTET_STRING,
163 	.sname = "ASN1_OCTET_STRING",
164 };
165 
166 ASN1_OCTET_STRING *
167 d2i_ASN1_OCTET_STRING(ASN1_OCTET_STRING **a, const unsigned char **in, long len)
168 {
169 	return (ASN1_OCTET_STRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
170 	    &ASN1_OCTET_STRING_it);
171 }
172 
173 int
174 i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a, unsigned char **out)
175 {
176 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_OCTET_STRING_it);
177 }
178 
179 ASN1_OCTET_STRING *
180 ASN1_OCTET_STRING_new(void)
181 {
182 	return (ASN1_OCTET_STRING *)ASN1_item_new(&ASN1_OCTET_STRING_it);
183 }
184 
185 void
186 ASN1_OCTET_STRING_free(ASN1_OCTET_STRING *a)
187 {
188 	ASN1_item_free((ASN1_VALUE *)a, &ASN1_OCTET_STRING_it);
189 }
190 
191 
192 const ASN1_ITEM ASN1_NULL_it = {
193 	.itype = ASN1_ITYPE_PRIMITIVE,
194 	.utype = V_ASN1_NULL,
195 	.sname = "ASN1_NULL",
196 };
197 
198 ASN1_NULL *
199 d2i_ASN1_NULL(ASN1_NULL **a, const unsigned char **in, long len)
200 {
201 	return (ASN1_NULL *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
202 	    &ASN1_NULL_it);
203 }
204 
205 int
206 i2d_ASN1_NULL(ASN1_NULL *a, unsigned char **out)
207 {
208 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_NULL_it);
209 }
210 
211 ASN1_NULL *
212 ASN1_NULL_new(void)
213 {
214 	return (ASN1_NULL *)ASN1_item_new(&ASN1_NULL_it);
215 }
216 
217 void
218 ASN1_NULL_free(ASN1_NULL *a)
219 {
220 	ASN1_item_free((ASN1_VALUE *)a, &ASN1_NULL_it);
221 }
222 
223 
224 const ASN1_ITEM ASN1_OBJECT_it = {
225 	.itype = ASN1_ITYPE_PRIMITIVE,
226 	.utype = V_ASN1_OBJECT,
227 	.sname = "ASN1_OBJECT",
228 };
229 
230 
231 const ASN1_ITEM ASN1_UTF8STRING_it = {
232 	.itype = ASN1_ITYPE_PRIMITIVE,
233 	.utype = V_ASN1_UTF8STRING,
234 	.sname = "ASN1_UTF8STRING",
235 };
236 
237 ASN1_UTF8STRING *
238 d2i_ASN1_UTF8STRING(ASN1_UTF8STRING **a, const unsigned char **in, long len)
239 {
240 	return (ASN1_UTF8STRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
241 	    &ASN1_UTF8STRING_it);
242 }
243 
244 int
245 i2d_ASN1_UTF8STRING(ASN1_UTF8STRING *a, unsigned char **out)
246 {
247 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_UTF8STRING_it);
248 }
249 
250 ASN1_UTF8STRING *
251 ASN1_UTF8STRING_new(void)
252 {
253 	return (ASN1_UTF8STRING *)ASN1_item_new(&ASN1_UTF8STRING_it);
254 }
255 
256 void
257 ASN1_UTF8STRING_free(ASN1_UTF8STRING *a)
258 {
259 	ASN1_item_free((ASN1_VALUE *)a, &ASN1_UTF8STRING_it);
260 }
261 
262 
263 const ASN1_ITEM ASN1_PRINTABLESTRING_it = {
264 	.itype = ASN1_ITYPE_PRIMITIVE,
265 	.utype = V_ASN1_PRINTABLESTRING,
266 	.sname = "ASN1_PRINTABLESTRING",
267 };
268 
269 ASN1_PRINTABLESTRING *
270 d2i_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING **a, const unsigned char **in,
271     long len)
272 {
273 	return (ASN1_PRINTABLESTRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
274 	    &ASN1_PRINTABLESTRING_it);
275 }
276 
277 int
278 i2d_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING *a, unsigned char **out)
279 {
280 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_PRINTABLESTRING_it);
281 }
282 
283 ASN1_PRINTABLESTRING *
284 ASN1_PRINTABLESTRING_new(void)
285 {
286 	return (ASN1_PRINTABLESTRING *)ASN1_item_new(&ASN1_PRINTABLESTRING_it);
287 }
288 
289 void
290 ASN1_PRINTABLESTRING_free(ASN1_PRINTABLESTRING *a)
291 {
292 	ASN1_item_free((ASN1_VALUE *)a, &ASN1_PRINTABLESTRING_it);
293 }
294 
295 
296 const ASN1_ITEM ASN1_T61STRING_it = {
297 	.itype = ASN1_ITYPE_PRIMITIVE,
298 	.utype = V_ASN1_T61STRING,
299 	.sname = "ASN1_T61STRING",
300 };
301 
302 ASN1_T61STRING *
303 d2i_ASN1_T61STRING(ASN1_T61STRING **a, const unsigned char **in, long len)
304 {
305 	return (ASN1_T61STRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
306 	    &ASN1_T61STRING_it);
307 }
308 
309 int
310 i2d_ASN1_T61STRING(ASN1_T61STRING *a, unsigned char **out)
311 {
312 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_T61STRING_it);
313 }
314 
315 ASN1_T61STRING *
316 ASN1_T61STRING_new(void)
317 {
318 	return (ASN1_T61STRING *)ASN1_item_new(&ASN1_T61STRING_it);
319 }
320 
321 void
322 ASN1_T61STRING_free(ASN1_T61STRING *a)
323 {
324 	ASN1_item_free((ASN1_VALUE *)a, &ASN1_T61STRING_it);
325 }
326 
327 
328 const ASN1_ITEM ASN1_IA5STRING_it = {
329 	.itype = ASN1_ITYPE_PRIMITIVE,
330 	.utype = V_ASN1_IA5STRING,
331 	.sname = "ASN1_IA5STRING",
332 };
333 
334 ASN1_IA5STRING *
335 d2i_ASN1_IA5STRING(ASN1_IA5STRING **a, const unsigned char **in, long len)
336 {
337 	return (ASN1_IA5STRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
338 	    &ASN1_IA5STRING_it);
339 }
340 
341 int
342 i2d_ASN1_IA5STRING(ASN1_IA5STRING *a, unsigned char **out)
343 {
344 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_IA5STRING_it);
345 }
346 
347 ASN1_IA5STRING *
348 ASN1_IA5STRING_new(void)
349 {
350 	return (ASN1_IA5STRING *)ASN1_item_new(&ASN1_IA5STRING_it);
351 }
352 
353 void
354 ASN1_IA5STRING_free(ASN1_IA5STRING *a)
355 {
356 	ASN1_item_free((ASN1_VALUE *)a, &ASN1_IA5STRING_it);
357 }
358 
359 
360 const ASN1_ITEM ASN1_GENERALSTRING_it = {
361 	.itype = ASN1_ITYPE_PRIMITIVE,
362 	.utype = V_ASN1_GENERALSTRING,
363 	.sname = "ASN1_GENERALSTRING",
364 };
365 
366 ASN1_GENERALSTRING *
367 d2i_ASN1_GENERALSTRING(ASN1_GENERALSTRING **a, const unsigned char **in,
368     long len)
369 {
370 	return (ASN1_GENERALSTRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
371 	    &ASN1_GENERALSTRING_it);
372 }
373 
374 int
375 i2d_ASN1_GENERALSTRING(ASN1_GENERALSTRING *a, unsigned char **out)
376 {
377 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_GENERALSTRING_it);
378 }
379 
380 ASN1_GENERALSTRING *
381 ASN1_GENERALSTRING_new(void)
382 {
383 	return (ASN1_GENERALSTRING *)ASN1_item_new(&ASN1_GENERALSTRING_it);
384 }
385 
386 void
387 ASN1_GENERALSTRING_free(ASN1_GENERALSTRING *a)
388 {
389 	ASN1_item_free((ASN1_VALUE *)a, &ASN1_GENERALSTRING_it);
390 }
391 
392 
393 const ASN1_ITEM ASN1_UTCTIME_it = {
394 	.itype = ASN1_ITYPE_PRIMITIVE,
395 	.utype = V_ASN1_UTCTIME,
396 	.sname = "ASN1_UTCTIME",
397 };
398 
399 ASN1_UTCTIME *
400 d2i_ASN1_UTCTIME(ASN1_UTCTIME **a, const unsigned char **in, long len)
401 {
402 	return (ASN1_UTCTIME *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
403 	    &ASN1_UTCTIME_it);
404 }
405 
406 int
407 i2d_ASN1_UTCTIME(ASN1_UTCTIME *a, unsigned char **out)
408 {
409 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_UTCTIME_it);
410 }
411 
412 ASN1_UTCTIME *
413 ASN1_UTCTIME_new(void)
414 {
415 	return (ASN1_UTCTIME *)ASN1_item_new(&ASN1_UTCTIME_it);
416 }
417 
418 void
419 ASN1_UTCTIME_free(ASN1_UTCTIME *a)
420 {
421 	ASN1_item_free((ASN1_VALUE *)a, &ASN1_UTCTIME_it);
422 }
423 
424 
425 const ASN1_ITEM ASN1_GENERALIZEDTIME_it = {
426 	.itype = ASN1_ITYPE_PRIMITIVE,
427 	.utype = V_ASN1_GENERALIZEDTIME,
428 	.sname = "ASN1_GENERALIZEDTIME",
429 };
430 
431 ASN1_GENERALIZEDTIME *
432 d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a, const unsigned char **in,
433     long len)
434 {
435 	return (ASN1_GENERALIZEDTIME *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
436 	    &ASN1_GENERALIZEDTIME_it);
437 }
438 
439 int
440 i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **out)
441 {
442 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_GENERALIZEDTIME_it);
443 }
444 
445 ASN1_GENERALIZEDTIME *
446 ASN1_GENERALIZEDTIME_new(void)
447 {
448 	return (ASN1_GENERALIZEDTIME *)ASN1_item_new(&ASN1_GENERALIZEDTIME_it);
449 }
450 
451 void
452 ASN1_GENERALIZEDTIME_free(ASN1_GENERALIZEDTIME *a)
453 {
454 	ASN1_item_free((ASN1_VALUE *)a, &ASN1_GENERALIZEDTIME_it);
455 }
456 
457 
458 const ASN1_ITEM ASN1_VISIBLESTRING_it = {
459 	.itype = ASN1_ITYPE_PRIMITIVE,
460 	.utype = V_ASN1_VISIBLESTRING,
461 	.sname = "ASN1_VISIBLESTRING",
462 };
463 
464 ASN1_VISIBLESTRING *
465 d2i_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING **a, const unsigned char **in,
466     long len)
467 {
468 	return (ASN1_VISIBLESTRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
469 	    &ASN1_VISIBLESTRING_it);
470 }
471 
472 int
473 i2d_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING *a, unsigned char **out)
474 {
475 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_VISIBLESTRING_it);
476 }
477 
478 ASN1_VISIBLESTRING *
479 ASN1_VISIBLESTRING_new(void)
480 {
481 	return (ASN1_VISIBLESTRING *)ASN1_item_new(&ASN1_VISIBLESTRING_it);
482 }
483 
484 void
485 ASN1_VISIBLESTRING_free(ASN1_VISIBLESTRING *a)
486 {
487 	ASN1_item_free((ASN1_VALUE *)a, &ASN1_VISIBLESTRING_it);
488 }
489 
490 
491 const ASN1_ITEM ASN1_UNIVERSALSTRING_it = {
492 	.itype = ASN1_ITYPE_PRIMITIVE,
493 	.utype = V_ASN1_UNIVERSALSTRING,
494 	.sname = "ASN1_UNIVERSALSTRING",
495 };
496 
497 ASN1_UNIVERSALSTRING *
498 d2i_ASN1_UNIVERSALSTRING(ASN1_UNIVERSALSTRING **a, const unsigned char **in,
499     long len)
500 {
501 	return (ASN1_UNIVERSALSTRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
502 	    &ASN1_UNIVERSALSTRING_it);
503 }
504 
505 int
506 i2d_ASN1_UNIVERSALSTRING(ASN1_UNIVERSALSTRING *a, unsigned char **out)
507 {
508 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_UNIVERSALSTRING_it);
509 }
510 
511 ASN1_UNIVERSALSTRING *
512 ASN1_UNIVERSALSTRING_new(void)
513 {
514 	return (ASN1_UNIVERSALSTRING *)ASN1_item_new(&ASN1_UNIVERSALSTRING_it);
515 }
516 
517 void
518 ASN1_UNIVERSALSTRING_free(ASN1_UNIVERSALSTRING *a)
519 {
520 	ASN1_item_free((ASN1_VALUE *)a, &ASN1_UNIVERSALSTRING_it);
521 }
522 
523 
524 const ASN1_ITEM ASN1_BMPSTRING_it = {
525 	.itype = ASN1_ITYPE_PRIMITIVE,
526 	.utype = V_ASN1_BMPSTRING,
527 	.sname = "ASN1_BMPSTRING",
528 };
529 
530 ASN1_BMPSTRING *
531 d2i_ASN1_BMPSTRING(ASN1_BMPSTRING **a, const unsigned char **in, long len)
532 {
533 	return (ASN1_BMPSTRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
534 	    &ASN1_BMPSTRING_it);
535 }
536 
537 int
538 i2d_ASN1_BMPSTRING(ASN1_BMPSTRING *a, unsigned char **out)
539 {
540 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_BMPSTRING_it);
541 }
542 
543 ASN1_BMPSTRING *
544 ASN1_BMPSTRING_new(void)
545 {
546 	return (ASN1_BMPSTRING *)ASN1_item_new(&ASN1_BMPSTRING_it);
547 }
548 
549 void
550 ASN1_BMPSTRING_free(ASN1_BMPSTRING *a)
551 {
552 	ASN1_item_free((ASN1_VALUE *)a, &ASN1_BMPSTRING_it);
553 }
554 
555 
556 const ASN1_ITEM ASN1_ANY_it = {
557 	.itype = ASN1_ITYPE_PRIMITIVE,
558 	.utype = V_ASN1_ANY,
559 	.sname = "ASN1_ANY",
560 };
561 
562 /* Just swallow an ASN1_SEQUENCE in an ASN1_STRING */
563 
564 const ASN1_ITEM ASN1_SEQUENCE_it = {
565 	.itype = ASN1_ITYPE_PRIMITIVE,
566 	.utype = V_ASN1_SEQUENCE,
567 	.sname = "ASN1_SEQUENCE",
568 };
569 
570 
571 ASN1_TYPE *
572 d2i_ASN1_TYPE(ASN1_TYPE **a, const unsigned char **in, long len)
573 {
574 	return (ASN1_TYPE *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
575 	    &ASN1_ANY_it);
576 }
577 
578 int
579 i2d_ASN1_TYPE(ASN1_TYPE *a, unsigned char **out)
580 {
581 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_ANY_it);
582 }
583 
584 ASN1_TYPE *
585 ASN1_TYPE_new(void)
586 {
587 	return (ASN1_TYPE *)ASN1_item_new(&ASN1_ANY_it);
588 }
589 
590 void
591 ASN1_TYPE_free(ASN1_TYPE *a)
592 {
593 	ASN1_item_free((ASN1_VALUE *)a, &ASN1_ANY_it);
594 }
595 
596 /* Multistring types */
597 
598 
599 const ASN1_ITEM ASN1_PRINTABLE_it = {
600 	.itype = ASN1_ITYPE_MSTRING,
601 	.utype = B_ASN1_PRINTABLE,
602 	.templates = NULL,
603 	.tcount = 0,
604 	.funcs = NULL,
605 	.size = sizeof(ASN1_STRING),
606 	.sname = "ASN1_PRINTABLE",
607 };
608 
609 ASN1_STRING *
610 d2i_ASN1_PRINTABLE(ASN1_STRING **a, const unsigned char **in, long len)
611 {
612 	return (ASN1_STRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
613 	    &ASN1_PRINTABLE_it);
614 }
615 
616 int
617 i2d_ASN1_PRINTABLE(ASN1_STRING *a, unsigned char **out)
618 {
619 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_PRINTABLE_it);
620 }
621 
622 ASN1_STRING *
623 ASN1_PRINTABLE_new(void)
624 {
625 	return (ASN1_STRING *)ASN1_item_new(&ASN1_PRINTABLE_it);
626 }
627 
628 void
629 ASN1_PRINTABLE_free(ASN1_STRING *a)
630 {
631 	ASN1_item_free((ASN1_VALUE *)a, &ASN1_PRINTABLE_it);
632 }
633 
634 
635 const ASN1_ITEM DISPLAYTEXT_it = {
636 	.itype = ASN1_ITYPE_MSTRING,
637 	.utype = B_ASN1_DISPLAYTEXT,
638 	.templates = NULL,
639 	.tcount = 0,
640 	.funcs = NULL,
641 	.size = sizeof(ASN1_STRING),
642 	.sname = "DISPLAYTEXT",
643 };
644 
645 ASN1_STRING *
646 d2i_DISPLAYTEXT(ASN1_STRING **a, const unsigned char **in, long len)
647 {
648 	return (ASN1_STRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
649 	    &DISPLAYTEXT_it);
650 }
651 
652 int
653 i2d_DISPLAYTEXT(ASN1_STRING *a, unsigned char **out)
654 {
655 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &DISPLAYTEXT_it);
656 }
657 
658 ASN1_STRING *
659 DISPLAYTEXT_new(void)
660 {
661 	return (ASN1_STRING *)ASN1_item_new(&DISPLAYTEXT_it);
662 }
663 
664 void
665 DISPLAYTEXT_free(ASN1_STRING *a)
666 {
667 	ASN1_item_free((ASN1_VALUE *)a, &DISPLAYTEXT_it);
668 }
669 
670 
671 const ASN1_ITEM DIRECTORYSTRING_it = {
672 	.itype = ASN1_ITYPE_MSTRING,
673 	.utype = B_ASN1_DIRECTORYSTRING,
674 	.templates = NULL,
675 	.tcount = 0,
676 	.funcs = NULL,
677 	.size = sizeof(ASN1_STRING),
678 	.sname = "DIRECTORYSTRING",
679 };
680 
681 ASN1_STRING *
682 d2i_DIRECTORYSTRING(ASN1_STRING **a, const unsigned char **in, long len)
683 {
684 	return (ASN1_STRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
685 	    &DIRECTORYSTRING_it);
686 }
687 
688 int
689 i2d_DIRECTORYSTRING(ASN1_STRING *a, unsigned char **out)
690 {
691 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &DIRECTORYSTRING_it);
692 }
693 
694 ASN1_STRING *
695 DIRECTORYSTRING_new(void)
696 {
697 	return (ASN1_STRING *)ASN1_item_new(&DIRECTORYSTRING_it);
698 }
699 
700 void
701 DIRECTORYSTRING_free(ASN1_STRING *a)
702 {
703 	ASN1_item_free((ASN1_VALUE *)a, &DIRECTORYSTRING_it);
704 }
705 
706 /* Three separate BOOLEAN type: normal, DEFAULT TRUE and DEFAULT FALSE */
707 
708 const ASN1_ITEM ASN1_BOOLEAN_it = {
709 	.itype = ASN1_ITYPE_PRIMITIVE,
710 	.utype = V_ASN1_BOOLEAN,
711 	.size = -1,
712 	.sname = "ASN1_BOOLEAN",
713 };
714 
715 const ASN1_ITEM ASN1_TBOOLEAN_it = {
716 	.itype = ASN1_ITYPE_PRIMITIVE,
717 	.utype = V_ASN1_BOOLEAN,
718 	.size = 1,
719 	.sname = "ASN1_TBOOLEAN",
720 };
721 
722 const ASN1_ITEM ASN1_FBOOLEAN_it = {
723 	.itype = ASN1_ITYPE_PRIMITIVE,
724 	.utype = V_ASN1_BOOLEAN,
725 	.size = 0,
726 	.sname = "ASN1_FBOOLEAN",
727 };
728 
729 /* Special, OCTET STRING with indefinite length constructed support */
730 
731 const ASN1_ITEM ASN1_OCTET_STRING_NDEF_it = {
732 	.itype = ASN1_ITYPE_PRIMITIVE,
733 	.utype = V_ASN1_OCTET_STRING,
734 	.size = ASN1_TFLG_NDEF,
735 	.sname = "ASN1_OCTET_STRING_NDEF",
736 };
737 
738 static const ASN1_TEMPLATE ASN1_SEQUENCE_ANY_item_tt = {
739 	.flags = ASN1_TFLG_SEQUENCE_OF,
740 	.tag = 0,
741 	.offset = 0,
742 	.field_name = "ASN1_SEQUENCE_ANY",
743 	.item = &ASN1_ANY_it,
744 };
745 
746 const ASN1_ITEM ASN1_SEQUENCE_ANY_it = {
747 	.itype = ASN1_ITYPE_PRIMITIVE,
748 	.utype = -1,
749 	.templates = &ASN1_SEQUENCE_ANY_item_tt,
750 	.tcount = 0,
751 	.funcs = NULL,
752 	.size = 0,
753 	.sname = "ASN1_SEQUENCE_ANY",
754 };
755 
756 static const ASN1_TEMPLATE ASN1_SET_ANY_item_tt = {
757 	.flags = ASN1_TFLG_SET_OF,
758 	.tag = 0,
759 	.offset = 0,
760 	.field_name = "ASN1_SET_ANY",
761 	.item = &ASN1_ANY_it,
762 };
763 
764 const ASN1_ITEM ASN1_SET_ANY_it = {
765 	.itype = ASN1_ITYPE_PRIMITIVE,
766 	.utype = -1,
767 	.templates = &ASN1_SET_ANY_item_tt,
768 	.tcount = 0,
769 	.funcs = NULL,
770 	.size = 0,
771 	.sname = "ASN1_SET_ANY",
772 };
773 
774 
775 ASN1_SEQUENCE_ANY *
776 d2i_ASN1_SEQUENCE_ANY(ASN1_SEQUENCE_ANY **a, const unsigned char **in, long len)
777 {
778 	return (ASN1_SEQUENCE_ANY *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
779 	    &ASN1_SEQUENCE_ANY_it);
780 }
781 
782 int
783 i2d_ASN1_SEQUENCE_ANY(const ASN1_SEQUENCE_ANY *a, unsigned char **out)
784 {
785 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_SEQUENCE_ANY_it);
786 }
787 
788 ASN1_SEQUENCE_ANY *
789 d2i_ASN1_SET_ANY(ASN1_SEQUENCE_ANY **a, const unsigned char **in, long len)
790 {
791 	return (ASN1_SEQUENCE_ANY *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
792 	    &ASN1_SET_ANY_it);
793 }
794 
795 int
796 i2d_ASN1_SET_ANY(const ASN1_SEQUENCE_ANY *a, unsigned char **out)
797 {
798 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_SET_ANY_it);
799 }
800