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