xref: /dragonfly/crypto/libressl/crypto/asn1/tasn_typ.c (revision 961e30ea7dc61d1112b778ea4981eac68129fb86)
1 /* $OpenBSD: tasn_typ.c,v 1.17 2021/12/26 15:20:21 tb 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_NULL_it = {
65           .itype = ASN1_ITYPE_PRIMITIVE,
66           .utype = V_ASN1_NULL,
67           .sname = "ASN1_NULL",
68 };
69 
70 ASN1_NULL *
d2i_ASN1_NULL(ASN1_NULL ** a,const unsigned char ** in,long len)71 d2i_ASN1_NULL(ASN1_NULL **a, const unsigned char **in, long len)
72 {
73           return (ASN1_NULL *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
74               &ASN1_NULL_it);
75 }
76 
77 int
i2d_ASN1_NULL(ASN1_NULL * a,unsigned char ** out)78 i2d_ASN1_NULL(ASN1_NULL *a, unsigned char **out)
79 {
80           return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_NULL_it);
81 }
82 
83 ASN1_NULL *
ASN1_NULL_new(void)84 ASN1_NULL_new(void)
85 {
86           return (ASN1_NULL *)ASN1_item_new(&ASN1_NULL_it);
87 }
88 
89 void
ASN1_NULL_free(ASN1_NULL * a)90 ASN1_NULL_free(ASN1_NULL *a)
91 {
92           ASN1_item_free((ASN1_VALUE *)a, &ASN1_NULL_it);
93 }
94 
95 
96 const ASN1_ITEM ASN1_UTF8STRING_it = {
97           .itype = ASN1_ITYPE_PRIMITIVE,
98           .utype = V_ASN1_UTF8STRING,
99           .sname = "ASN1_UTF8STRING",
100 };
101 
102 ASN1_UTF8STRING *
d2i_ASN1_UTF8STRING(ASN1_UTF8STRING ** a,const unsigned char ** in,long len)103 d2i_ASN1_UTF8STRING(ASN1_UTF8STRING **a, const unsigned char **in, long len)
104 {
105           return (ASN1_UTF8STRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
106               &ASN1_UTF8STRING_it);
107 }
108 
109 int
i2d_ASN1_UTF8STRING(ASN1_UTF8STRING * a,unsigned char ** out)110 i2d_ASN1_UTF8STRING(ASN1_UTF8STRING *a, unsigned char **out)
111 {
112           return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_UTF8STRING_it);
113 }
114 
115 ASN1_UTF8STRING *
ASN1_UTF8STRING_new(void)116 ASN1_UTF8STRING_new(void)
117 {
118           return (ASN1_UTF8STRING *)ASN1_item_new(&ASN1_UTF8STRING_it);
119 }
120 
121 void
ASN1_UTF8STRING_free(ASN1_UTF8STRING * a)122 ASN1_UTF8STRING_free(ASN1_UTF8STRING *a)
123 {
124           ASN1_item_free((ASN1_VALUE *)a, &ASN1_UTF8STRING_it);
125 }
126 
127 
128 const ASN1_ITEM ASN1_PRINTABLESTRING_it = {
129           .itype = ASN1_ITYPE_PRIMITIVE,
130           .utype = V_ASN1_PRINTABLESTRING,
131           .sname = "ASN1_PRINTABLESTRING",
132 };
133 
134 ASN1_PRINTABLESTRING *
d2i_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING ** a,const unsigned char ** in,long len)135 d2i_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING **a, const unsigned char **in,
136     long len)
137 {
138           return (ASN1_PRINTABLESTRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
139               &ASN1_PRINTABLESTRING_it);
140 }
141 
142 int
i2d_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING * a,unsigned char ** out)143 i2d_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING *a, unsigned char **out)
144 {
145           return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_PRINTABLESTRING_it);
146 }
147 
148 ASN1_PRINTABLESTRING *
ASN1_PRINTABLESTRING_new(void)149 ASN1_PRINTABLESTRING_new(void)
150 {
151           return (ASN1_PRINTABLESTRING *)ASN1_item_new(&ASN1_PRINTABLESTRING_it);
152 }
153 
154 void
ASN1_PRINTABLESTRING_free(ASN1_PRINTABLESTRING * a)155 ASN1_PRINTABLESTRING_free(ASN1_PRINTABLESTRING *a)
156 {
157           ASN1_item_free((ASN1_VALUE *)a, &ASN1_PRINTABLESTRING_it);
158 }
159 
160 
161 const ASN1_ITEM ASN1_T61STRING_it = {
162           .itype = ASN1_ITYPE_PRIMITIVE,
163           .utype = V_ASN1_T61STRING,
164           .sname = "ASN1_T61STRING",
165 };
166 
167 ASN1_T61STRING *
d2i_ASN1_T61STRING(ASN1_T61STRING ** a,const unsigned char ** in,long len)168 d2i_ASN1_T61STRING(ASN1_T61STRING **a, const unsigned char **in, long len)
169 {
170           return (ASN1_T61STRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
171               &ASN1_T61STRING_it);
172 }
173 
174 int
i2d_ASN1_T61STRING(ASN1_T61STRING * a,unsigned char ** out)175 i2d_ASN1_T61STRING(ASN1_T61STRING *a, unsigned char **out)
176 {
177           return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_T61STRING_it);
178 }
179 
180 ASN1_T61STRING *
ASN1_T61STRING_new(void)181 ASN1_T61STRING_new(void)
182 {
183           return (ASN1_T61STRING *)ASN1_item_new(&ASN1_T61STRING_it);
184 }
185 
186 void
ASN1_T61STRING_free(ASN1_T61STRING * a)187 ASN1_T61STRING_free(ASN1_T61STRING *a)
188 {
189           ASN1_item_free((ASN1_VALUE *)a, &ASN1_T61STRING_it);
190 }
191 
192 
193 const ASN1_ITEM ASN1_IA5STRING_it = {
194           .itype = ASN1_ITYPE_PRIMITIVE,
195           .utype = V_ASN1_IA5STRING,
196           .sname = "ASN1_IA5STRING",
197 };
198 
199 ASN1_IA5STRING *
d2i_ASN1_IA5STRING(ASN1_IA5STRING ** a,const unsigned char ** in,long len)200 d2i_ASN1_IA5STRING(ASN1_IA5STRING **a, const unsigned char **in, long len)
201 {
202           return (ASN1_IA5STRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
203               &ASN1_IA5STRING_it);
204 }
205 
206 int
i2d_ASN1_IA5STRING(ASN1_IA5STRING * a,unsigned char ** out)207 i2d_ASN1_IA5STRING(ASN1_IA5STRING *a, unsigned char **out)
208 {
209           return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_IA5STRING_it);
210 }
211 
212 ASN1_IA5STRING *
ASN1_IA5STRING_new(void)213 ASN1_IA5STRING_new(void)
214 {
215           return (ASN1_IA5STRING *)ASN1_item_new(&ASN1_IA5STRING_it);
216 }
217 
218 void
ASN1_IA5STRING_free(ASN1_IA5STRING * a)219 ASN1_IA5STRING_free(ASN1_IA5STRING *a)
220 {
221           ASN1_item_free((ASN1_VALUE *)a, &ASN1_IA5STRING_it);
222 }
223 
224 
225 const ASN1_ITEM ASN1_GENERALSTRING_it = {
226           .itype = ASN1_ITYPE_PRIMITIVE,
227           .utype = V_ASN1_GENERALSTRING,
228           .sname = "ASN1_GENERALSTRING",
229 };
230 
231 ASN1_GENERALSTRING *
d2i_ASN1_GENERALSTRING(ASN1_GENERALSTRING ** a,const unsigned char ** in,long len)232 d2i_ASN1_GENERALSTRING(ASN1_GENERALSTRING **a, const unsigned char **in,
233     long len)
234 {
235           return (ASN1_GENERALSTRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
236               &ASN1_GENERALSTRING_it);
237 }
238 
239 int
i2d_ASN1_GENERALSTRING(ASN1_GENERALSTRING * a,unsigned char ** out)240 i2d_ASN1_GENERALSTRING(ASN1_GENERALSTRING *a, unsigned char **out)
241 {
242           return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_GENERALSTRING_it);
243 }
244 
245 ASN1_GENERALSTRING *
ASN1_GENERALSTRING_new(void)246 ASN1_GENERALSTRING_new(void)
247 {
248           return (ASN1_GENERALSTRING *)ASN1_item_new(&ASN1_GENERALSTRING_it);
249 }
250 
251 void
ASN1_GENERALSTRING_free(ASN1_GENERALSTRING * a)252 ASN1_GENERALSTRING_free(ASN1_GENERALSTRING *a)
253 {
254           ASN1_item_free((ASN1_VALUE *)a, &ASN1_GENERALSTRING_it);
255 }
256 
257 
258 const ASN1_ITEM ASN1_UTCTIME_it = {
259           .itype = ASN1_ITYPE_PRIMITIVE,
260           .utype = V_ASN1_UTCTIME,
261           .sname = "ASN1_UTCTIME",
262 };
263 
264 ASN1_UTCTIME *
d2i_ASN1_UTCTIME(ASN1_UTCTIME ** a,const unsigned char ** in,long len)265 d2i_ASN1_UTCTIME(ASN1_UTCTIME **a, const unsigned char **in, long len)
266 {
267           return (ASN1_UTCTIME *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
268               &ASN1_UTCTIME_it);
269 }
270 
271 int
i2d_ASN1_UTCTIME(ASN1_UTCTIME * a,unsigned char ** out)272 i2d_ASN1_UTCTIME(ASN1_UTCTIME *a, unsigned char **out)
273 {
274           return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_UTCTIME_it);
275 }
276 
277 ASN1_UTCTIME *
ASN1_UTCTIME_new(void)278 ASN1_UTCTIME_new(void)
279 {
280           return (ASN1_UTCTIME *)ASN1_item_new(&ASN1_UTCTIME_it);
281 }
282 
283 void
ASN1_UTCTIME_free(ASN1_UTCTIME * a)284 ASN1_UTCTIME_free(ASN1_UTCTIME *a)
285 {
286           ASN1_item_free((ASN1_VALUE *)a, &ASN1_UTCTIME_it);
287 }
288 
289 
290 const ASN1_ITEM ASN1_GENERALIZEDTIME_it = {
291           .itype = ASN1_ITYPE_PRIMITIVE,
292           .utype = V_ASN1_GENERALIZEDTIME,
293           .sname = "ASN1_GENERALIZEDTIME",
294 };
295 
296 ASN1_GENERALIZEDTIME *
d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME ** a,const unsigned char ** in,long len)297 d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a, const unsigned char **in,
298     long len)
299 {
300           return (ASN1_GENERALIZEDTIME *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
301               &ASN1_GENERALIZEDTIME_it);
302 }
303 
304 int
i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME * a,unsigned char ** out)305 i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **out)
306 {
307           return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_GENERALIZEDTIME_it);
308 }
309 
310 ASN1_GENERALIZEDTIME *
ASN1_GENERALIZEDTIME_new(void)311 ASN1_GENERALIZEDTIME_new(void)
312 {
313           return (ASN1_GENERALIZEDTIME *)ASN1_item_new(&ASN1_GENERALIZEDTIME_it);
314 }
315 
316 void
ASN1_GENERALIZEDTIME_free(ASN1_GENERALIZEDTIME * a)317 ASN1_GENERALIZEDTIME_free(ASN1_GENERALIZEDTIME *a)
318 {
319           ASN1_item_free((ASN1_VALUE *)a, &ASN1_GENERALIZEDTIME_it);
320 }
321 
322 
323 const ASN1_ITEM ASN1_VISIBLESTRING_it = {
324           .itype = ASN1_ITYPE_PRIMITIVE,
325           .utype = V_ASN1_VISIBLESTRING,
326           .sname = "ASN1_VISIBLESTRING",
327 };
328 
329 ASN1_VISIBLESTRING *
d2i_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING ** a,const unsigned char ** in,long len)330 d2i_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING **a, const unsigned char **in,
331     long len)
332 {
333           return (ASN1_VISIBLESTRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
334               &ASN1_VISIBLESTRING_it);
335 }
336 
337 int
i2d_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING * a,unsigned char ** out)338 i2d_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING *a, unsigned char **out)
339 {
340           return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_VISIBLESTRING_it);
341 }
342 
343 ASN1_VISIBLESTRING *
ASN1_VISIBLESTRING_new(void)344 ASN1_VISIBLESTRING_new(void)
345 {
346           return (ASN1_VISIBLESTRING *)ASN1_item_new(&ASN1_VISIBLESTRING_it);
347 }
348 
349 void
ASN1_VISIBLESTRING_free(ASN1_VISIBLESTRING * a)350 ASN1_VISIBLESTRING_free(ASN1_VISIBLESTRING *a)
351 {
352           ASN1_item_free((ASN1_VALUE *)a, &ASN1_VISIBLESTRING_it);
353 }
354 
355 
356 const ASN1_ITEM ASN1_UNIVERSALSTRING_it = {
357           .itype = ASN1_ITYPE_PRIMITIVE,
358           .utype = V_ASN1_UNIVERSALSTRING,
359           .sname = "ASN1_UNIVERSALSTRING",
360 };
361 
362 ASN1_UNIVERSALSTRING *
d2i_ASN1_UNIVERSALSTRING(ASN1_UNIVERSALSTRING ** a,const unsigned char ** in,long len)363 d2i_ASN1_UNIVERSALSTRING(ASN1_UNIVERSALSTRING **a, const unsigned char **in,
364     long len)
365 {
366           return (ASN1_UNIVERSALSTRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
367               &ASN1_UNIVERSALSTRING_it);
368 }
369 
370 int
i2d_ASN1_UNIVERSALSTRING(ASN1_UNIVERSALSTRING * a,unsigned char ** out)371 i2d_ASN1_UNIVERSALSTRING(ASN1_UNIVERSALSTRING *a, unsigned char **out)
372 {
373           return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_UNIVERSALSTRING_it);
374 }
375 
376 ASN1_UNIVERSALSTRING *
ASN1_UNIVERSALSTRING_new(void)377 ASN1_UNIVERSALSTRING_new(void)
378 {
379           return (ASN1_UNIVERSALSTRING *)ASN1_item_new(&ASN1_UNIVERSALSTRING_it);
380 }
381 
382 void
ASN1_UNIVERSALSTRING_free(ASN1_UNIVERSALSTRING * a)383 ASN1_UNIVERSALSTRING_free(ASN1_UNIVERSALSTRING *a)
384 {
385           ASN1_item_free((ASN1_VALUE *)a, &ASN1_UNIVERSALSTRING_it);
386 }
387 
388 
389 const ASN1_ITEM ASN1_BMPSTRING_it = {
390           .itype = ASN1_ITYPE_PRIMITIVE,
391           .utype = V_ASN1_BMPSTRING,
392           .sname = "ASN1_BMPSTRING",
393 };
394 
395 ASN1_BMPSTRING *
d2i_ASN1_BMPSTRING(ASN1_BMPSTRING ** a,const unsigned char ** in,long len)396 d2i_ASN1_BMPSTRING(ASN1_BMPSTRING **a, const unsigned char **in, long len)
397 {
398           return (ASN1_BMPSTRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
399               &ASN1_BMPSTRING_it);
400 }
401 
402 int
i2d_ASN1_BMPSTRING(ASN1_BMPSTRING * a,unsigned char ** out)403 i2d_ASN1_BMPSTRING(ASN1_BMPSTRING *a, unsigned char **out)
404 {
405           return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_BMPSTRING_it);
406 }
407 
408 ASN1_BMPSTRING *
ASN1_BMPSTRING_new(void)409 ASN1_BMPSTRING_new(void)
410 {
411           return (ASN1_BMPSTRING *)ASN1_item_new(&ASN1_BMPSTRING_it);
412 }
413 
414 void
ASN1_BMPSTRING_free(ASN1_BMPSTRING * a)415 ASN1_BMPSTRING_free(ASN1_BMPSTRING *a)
416 {
417           ASN1_item_free((ASN1_VALUE *)a, &ASN1_BMPSTRING_it);
418 }
419 
420 const ASN1_ITEM ASN1_ANY_it = {
421           .itype = ASN1_ITYPE_PRIMITIVE,
422           .utype = V_ASN1_ANY,
423           .sname = "ASN1_ANY",
424 };
425 
426 
427 /* Just swallow an ASN1_SEQUENCE in an ASN1_STRING */
428 
429 const ASN1_ITEM ASN1_SEQUENCE_it = {
430           .itype = ASN1_ITYPE_PRIMITIVE,
431           .utype = V_ASN1_SEQUENCE,
432           .sname = "ASN1_SEQUENCE",
433 };
434 
435 
436 /* Multistring types */
437 
438 
439 const ASN1_ITEM ASN1_PRINTABLE_it = {
440           .itype = ASN1_ITYPE_MSTRING,
441           .utype = B_ASN1_PRINTABLE,
442           .templates = NULL,
443           .tcount = 0,
444           .funcs = NULL,
445           .size = sizeof(ASN1_STRING),
446           .sname = "ASN1_PRINTABLE",
447 };
448 
449 ASN1_STRING *
d2i_ASN1_PRINTABLE(ASN1_STRING ** a,const unsigned char ** in,long len)450 d2i_ASN1_PRINTABLE(ASN1_STRING **a, const unsigned char **in, long len)
451 {
452           return (ASN1_STRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
453               &ASN1_PRINTABLE_it);
454 }
455 
456 int
i2d_ASN1_PRINTABLE(ASN1_STRING * a,unsigned char ** out)457 i2d_ASN1_PRINTABLE(ASN1_STRING *a, unsigned char **out)
458 {
459           return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_PRINTABLE_it);
460 }
461 
462 ASN1_STRING *
ASN1_PRINTABLE_new(void)463 ASN1_PRINTABLE_new(void)
464 {
465           return (ASN1_STRING *)ASN1_item_new(&ASN1_PRINTABLE_it);
466 }
467 
468 void
ASN1_PRINTABLE_free(ASN1_STRING * a)469 ASN1_PRINTABLE_free(ASN1_STRING *a)
470 {
471           ASN1_item_free((ASN1_VALUE *)a, &ASN1_PRINTABLE_it);
472 }
473 
474 
475 const ASN1_ITEM DISPLAYTEXT_it = {
476           .itype = ASN1_ITYPE_MSTRING,
477           .utype = B_ASN1_DISPLAYTEXT,
478           .templates = NULL,
479           .tcount = 0,
480           .funcs = NULL,
481           .size = sizeof(ASN1_STRING),
482           .sname = "DISPLAYTEXT",
483 };
484 
485 ASN1_STRING *
d2i_DISPLAYTEXT(ASN1_STRING ** a,const unsigned char ** in,long len)486 d2i_DISPLAYTEXT(ASN1_STRING **a, const unsigned char **in, long len)
487 {
488           return (ASN1_STRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
489               &DISPLAYTEXT_it);
490 }
491 
492 int
i2d_DISPLAYTEXT(ASN1_STRING * a,unsigned char ** out)493 i2d_DISPLAYTEXT(ASN1_STRING *a, unsigned char **out)
494 {
495           return ASN1_item_i2d((ASN1_VALUE *)a, out, &DISPLAYTEXT_it);
496 }
497 
498 ASN1_STRING *
DISPLAYTEXT_new(void)499 DISPLAYTEXT_new(void)
500 {
501           return (ASN1_STRING *)ASN1_item_new(&DISPLAYTEXT_it);
502 }
503 
504 void
DISPLAYTEXT_free(ASN1_STRING * a)505 DISPLAYTEXT_free(ASN1_STRING *a)
506 {
507           ASN1_item_free((ASN1_VALUE *)a, &DISPLAYTEXT_it);
508 }
509 
510 
511 const ASN1_ITEM DIRECTORYSTRING_it = {
512           .itype = ASN1_ITYPE_MSTRING,
513           .utype = B_ASN1_DIRECTORYSTRING,
514           .templates = NULL,
515           .tcount = 0,
516           .funcs = NULL,
517           .size = sizeof(ASN1_STRING),
518           .sname = "DIRECTORYSTRING",
519 };
520 
521 ASN1_STRING *
d2i_DIRECTORYSTRING(ASN1_STRING ** a,const unsigned char ** in,long len)522 d2i_DIRECTORYSTRING(ASN1_STRING **a, const unsigned char **in, long len)
523 {
524           return (ASN1_STRING *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
525               &DIRECTORYSTRING_it);
526 }
527 
528 int
i2d_DIRECTORYSTRING(ASN1_STRING * a,unsigned char ** out)529 i2d_DIRECTORYSTRING(ASN1_STRING *a, unsigned char **out)
530 {
531           return ASN1_item_i2d((ASN1_VALUE *)a, out, &DIRECTORYSTRING_it);
532 }
533 
534 ASN1_STRING *
DIRECTORYSTRING_new(void)535 DIRECTORYSTRING_new(void)
536 {
537           return (ASN1_STRING *)ASN1_item_new(&DIRECTORYSTRING_it);
538 }
539 
540 void
DIRECTORYSTRING_free(ASN1_STRING * a)541 DIRECTORYSTRING_free(ASN1_STRING *a)
542 {
543           ASN1_item_free((ASN1_VALUE *)a, &DIRECTORYSTRING_it);
544 }
545 
546 /* Three separate BOOLEAN type: normal, DEFAULT TRUE and DEFAULT FALSE */
547 
548 const ASN1_ITEM ASN1_BOOLEAN_it = {
549           .itype = ASN1_ITYPE_PRIMITIVE,
550           .utype = V_ASN1_BOOLEAN,
551           .size = -1,
552           .sname = "ASN1_BOOLEAN",
553 };
554 
555 int
i2d_ASN1_BOOLEAN(int a,unsigned char ** out)556 i2d_ASN1_BOOLEAN(int a, unsigned char **out)
557 {
558           return ASN1_item_ex_i2d((ASN1_VALUE **)&a, out,
559               &ASN1_BOOLEAN_it, -1, 0);
560 }
561 
562 int
d2i_ASN1_BOOLEAN(int * a,const unsigned char ** in,long len)563 d2i_ASN1_BOOLEAN(int *a, const unsigned char **in, long len)
564 {
565           ASN1_BOOLEAN abool;
566 
567           if (ASN1_item_ex_d2i((ASN1_VALUE **)&abool, in, len, &ASN1_BOOLEAN_it,
568               -1, 0, 0, NULL) <= 0)
569                     return -1;
570 
571           if (a != NULL)
572                     *a = abool;
573 
574           return abool;
575 }
576 
577 const ASN1_ITEM ASN1_TBOOLEAN_it = {
578           .itype = ASN1_ITYPE_PRIMITIVE,
579           .utype = V_ASN1_BOOLEAN,
580           .size = 1,
581           .sname = "ASN1_TBOOLEAN",
582 };
583 
584 const ASN1_ITEM ASN1_FBOOLEAN_it = {
585           .itype = ASN1_ITYPE_PRIMITIVE,
586           .utype = V_ASN1_BOOLEAN,
587           .size = 0,
588           .sname = "ASN1_FBOOLEAN",
589 };
590 
591 /* Special, OCTET STRING with indefinite length constructed support */
592 
593 const ASN1_ITEM ASN1_OCTET_STRING_NDEF_it = {
594           .itype = ASN1_ITYPE_PRIMITIVE,
595           .utype = V_ASN1_OCTET_STRING,
596           .size = ASN1_TFLG_NDEF,
597           .sname = "ASN1_OCTET_STRING_NDEF",
598 };
599 
600 static const ASN1_TEMPLATE ASN1_SEQUENCE_ANY_item_tt = {
601           .flags = ASN1_TFLG_SEQUENCE_OF,
602           .tag = 0,
603           .offset = 0,
604           .field_name = "ASN1_SEQUENCE_ANY",
605           .item = &ASN1_ANY_it,
606 };
607 
608 const ASN1_ITEM ASN1_SEQUENCE_ANY_it = {
609           .itype = ASN1_ITYPE_PRIMITIVE,
610           .utype = -1,
611           .templates = &ASN1_SEQUENCE_ANY_item_tt,
612           .tcount = 0,
613           .funcs = NULL,
614           .size = 0,
615           .sname = "ASN1_SEQUENCE_ANY",
616 };
617 
618 static const ASN1_TEMPLATE ASN1_SET_ANY_item_tt = {
619           .flags = ASN1_TFLG_SET_OF,
620           .tag = 0,
621           .offset = 0,
622           .field_name = "ASN1_SET_ANY",
623           .item = &ASN1_ANY_it,
624 };
625 
626 const ASN1_ITEM ASN1_SET_ANY_it = {
627           .itype = ASN1_ITYPE_PRIMITIVE,
628           .utype = -1,
629           .templates = &ASN1_SET_ANY_item_tt,
630           .tcount = 0,
631           .funcs = NULL,
632           .size = 0,
633           .sname = "ASN1_SET_ANY",
634 };
635 
636 
637 ASN1_SEQUENCE_ANY *
d2i_ASN1_SEQUENCE_ANY(ASN1_SEQUENCE_ANY ** a,const unsigned char ** in,long len)638 d2i_ASN1_SEQUENCE_ANY(ASN1_SEQUENCE_ANY **a, const unsigned char **in, long len)
639 {
640           return (ASN1_SEQUENCE_ANY *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
641               &ASN1_SEQUENCE_ANY_it);
642 }
643 
644 int
i2d_ASN1_SEQUENCE_ANY(const ASN1_SEQUENCE_ANY * a,unsigned char ** out)645 i2d_ASN1_SEQUENCE_ANY(const ASN1_SEQUENCE_ANY *a, unsigned char **out)
646 {
647           return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_SEQUENCE_ANY_it);
648 }
649 
650 ASN1_SEQUENCE_ANY *
d2i_ASN1_SET_ANY(ASN1_SEQUENCE_ANY ** a,const unsigned char ** in,long len)651 d2i_ASN1_SET_ANY(ASN1_SEQUENCE_ANY **a, const unsigned char **in, long len)
652 {
653           return (ASN1_SEQUENCE_ANY *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
654               &ASN1_SET_ANY_it);
655 }
656 
657 int
i2d_ASN1_SET_ANY(const ASN1_SEQUENCE_ANY * a,unsigned char ** out)658 i2d_ASN1_SET_ANY(const ASN1_SEQUENCE_ANY *a, unsigned char **out)
659 {
660           return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_SET_ANY_it);
661 }
662