xref: /freebsd/crypto/openssl/include/openssl/asn1.h (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
1 /*
2  * WARNING: do not edit!
3  * Generated by Makefile from include/openssl/asn1.h.in
4  *
5  * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
6  *
7  * Licensed under the Apache License 2.0 (the "License").  You may not use
8  * this file except in compliance with the License.  You can obtain a copy
9  * in the file LICENSE in the source distribution or at
10  * https://www.openssl.org/source/license.html
11  */
12 
13 
14 
15 #ifndef OPENSSL_ASN1_H
16 # define OPENSSL_ASN1_H
17 # pragma once
18 
19 # include <openssl/macros.h>
20 # ifndef OPENSSL_NO_DEPRECATED_3_0
21 #  define HEADER_ASN1_H
22 # endif
23 
24 # include <time.h>
25 # include <openssl/e_os2.h>
26 # include <openssl/opensslconf.h>
27 # include <openssl/bio.h>
28 # include <openssl/safestack.h>
29 # include <openssl/asn1err.h>
30 # include <openssl/symhacks.h>
31 
32 # include <openssl/types.h>
33 # include <openssl/bn.h>
34 
35 # ifdef OPENSSL_BUILD_SHLIBCRYPTO
36 #  undef OPENSSL_EXTERN
37 #  define OPENSSL_EXTERN OPENSSL_EXPORT
38 # endif
39 
40 #ifdef  __cplusplus
41 extern "C" {
42 #endif
43 
44 # define V_ASN1_UNIVERSAL                0x00
45 # define V_ASN1_APPLICATION              0x40
46 # define V_ASN1_CONTEXT_SPECIFIC         0x80
47 # define V_ASN1_PRIVATE                  0xc0
48 
49 # define V_ASN1_CONSTRUCTED              0x20
50 # define V_ASN1_PRIMITIVE_TAG            0x1f
51 # define V_ASN1_PRIMATIVE_TAG /*compat*/ V_ASN1_PRIMITIVE_TAG
52 
53 # define V_ASN1_APP_CHOOSE               -2/* let the recipient choose */
54 # define V_ASN1_OTHER                    -3/* used in ASN1_TYPE */
55 # define V_ASN1_ANY                      -4/* used in ASN1 template code */
56 
57 # define V_ASN1_UNDEF                    -1
58 /* ASN.1 tag values */
59 # define V_ASN1_EOC                      0
60 # define V_ASN1_BOOLEAN                  1 /**/
61 # define V_ASN1_INTEGER                  2
62 # define V_ASN1_BIT_STRING               3
63 # define V_ASN1_OCTET_STRING             4
64 # define V_ASN1_NULL                     5
65 # define V_ASN1_OBJECT                   6
66 # define V_ASN1_OBJECT_DESCRIPTOR        7
67 # define V_ASN1_EXTERNAL                 8
68 # define V_ASN1_REAL                     9
69 # define V_ASN1_ENUMERATED               10
70 # define V_ASN1_UTF8STRING               12
71 # define V_ASN1_SEQUENCE                 16
72 # define V_ASN1_SET                      17
73 # define V_ASN1_NUMERICSTRING            18 /**/
74 # define V_ASN1_PRINTABLESTRING          19
75 # define V_ASN1_T61STRING                20
76 # define V_ASN1_TELETEXSTRING            20/* alias */
77 # define V_ASN1_VIDEOTEXSTRING           21 /**/
78 # define V_ASN1_IA5STRING                22
79 # define V_ASN1_UTCTIME                  23
80 # define V_ASN1_GENERALIZEDTIME          24 /**/
81 # define V_ASN1_GRAPHICSTRING            25 /**/
82 # define V_ASN1_ISO64STRING              26 /**/
83 # define V_ASN1_VISIBLESTRING            26/* alias */
84 # define V_ASN1_GENERALSTRING            27 /**/
85 # define V_ASN1_UNIVERSALSTRING          28 /**/
86 # define V_ASN1_BMPSTRING                30
87 
88 /*
89  * NB the constants below are used internally by ASN1_INTEGER
90  * and ASN1_ENUMERATED to indicate the sign. They are *not* on
91  * the wire tag values.
92  */
93 
94 # define V_ASN1_NEG                      0x100
95 # define V_ASN1_NEG_INTEGER              (2 | V_ASN1_NEG)
96 # define V_ASN1_NEG_ENUMERATED           (10 | V_ASN1_NEG)
97 
98 /* For use with d2i_ASN1_type_bytes() */
99 # define B_ASN1_NUMERICSTRING    0x0001
100 # define B_ASN1_PRINTABLESTRING  0x0002
101 # define B_ASN1_T61STRING        0x0004
102 # define B_ASN1_TELETEXSTRING    0x0004
103 # define B_ASN1_VIDEOTEXSTRING   0x0008
104 # define B_ASN1_IA5STRING        0x0010
105 # define B_ASN1_GRAPHICSTRING    0x0020
106 # define B_ASN1_ISO64STRING      0x0040
107 # define B_ASN1_VISIBLESTRING    0x0040
108 # define B_ASN1_GENERALSTRING    0x0080
109 # define B_ASN1_UNIVERSALSTRING  0x0100
110 # define B_ASN1_OCTET_STRING     0x0200
111 # define B_ASN1_BIT_STRING       0x0400
112 # define B_ASN1_BMPSTRING        0x0800
113 # define B_ASN1_UNKNOWN          0x1000
114 # define B_ASN1_UTF8STRING       0x2000
115 # define B_ASN1_UTCTIME          0x4000
116 # define B_ASN1_GENERALIZEDTIME  0x8000
117 # define B_ASN1_SEQUENCE         0x10000
118 /* For use with ASN1_mbstring_copy() */
119 # define MBSTRING_FLAG           0x1000
120 # define MBSTRING_UTF8           (MBSTRING_FLAG)
121 # define MBSTRING_ASC            (MBSTRING_FLAG|1)
122 # define MBSTRING_BMP            (MBSTRING_FLAG|2)
123 # define MBSTRING_UNIV           (MBSTRING_FLAG|4)
124 # define SMIME_OLDMIME           0x400
125 # define SMIME_CRLFEOL           0x800
126 # define SMIME_STREAM            0x1000
127 
128 /* Stacks for types not otherwise defined in this header */
129 SKM_DEFINE_STACK_OF_INTERNAL(X509_ALGOR, X509_ALGOR, X509_ALGOR)
130 #define sk_X509_ALGOR_num(sk) OPENSSL_sk_num(ossl_check_const_X509_ALGOR_sk_type(sk))
131 #define sk_X509_ALGOR_value(sk, idx) ((X509_ALGOR *)OPENSSL_sk_value(ossl_check_const_X509_ALGOR_sk_type(sk), (idx)))
132 #define sk_X509_ALGOR_new(cmp) ((STACK_OF(X509_ALGOR) *)OPENSSL_sk_new(ossl_check_X509_ALGOR_compfunc_type(cmp)))
133 #define sk_X509_ALGOR_new_null() ((STACK_OF(X509_ALGOR) *)OPENSSL_sk_new_null())
134 #define sk_X509_ALGOR_new_reserve(cmp, n) ((STACK_OF(X509_ALGOR) *)OPENSSL_sk_new_reserve(ossl_check_X509_ALGOR_compfunc_type(cmp), (n)))
135 #define sk_X509_ALGOR_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_X509_ALGOR_sk_type(sk), (n))
136 #define sk_X509_ALGOR_free(sk) OPENSSL_sk_free(ossl_check_X509_ALGOR_sk_type(sk))
137 #define sk_X509_ALGOR_zero(sk) OPENSSL_sk_zero(ossl_check_X509_ALGOR_sk_type(sk))
138 #define sk_X509_ALGOR_delete(sk, i) ((X509_ALGOR *)OPENSSL_sk_delete(ossl_check_X509_ALGOR_sk_type(sk), (i)))
139 #define sk_X509_ALGOR_delete_ptr(sk, ptr) ((X509_ALGOR *)OPENSSL_sk_delete_ptr(ossl_check_X509_ALGOR_sk_type(sk), ossl_check_X509_ALGOR_type(ptr)))
140 #define sk_X509_ALGOR_push(sk, ptr) OPENSSL_sk_push(ossl_check_X509_ALGOR_sk_type(sk), ossl_check_X509_ALGOR_type(ptr))
141 #define sk_X509_ALGOR_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_X509_ALGOR_sk_type(sk), ossl_check_X509_ALGOR_type(ptr))
142 #define sk_X509_ALGOR_pop(sk) ((X509_ALGOR *)OPENSSL_sk_pop(ossl_check_X509_ALGOR_sk_type(sk)))
143 #define sk_X509_ALGOR_shift(sk) ((X509_ALGOR *)OPENSSL_sk_shift(ossl_check_X509_ALGOR_sk_type(sk)))
144 #define sk_X509_ALGOR_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_X509_ALGOR_sk_type(sk),ossl_check_X509_ALGOR_freefunc_type(freefunc))
145 #define sk_X509_ALGOR_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_X509_ALGOR_sk_type(sk), ossl_check_X509_ALGOR_type(ptr), (idx))
146 #define sk_X509_ALGOR_set(sk, idx, ptr) ((X509_ALGOR *)OPENSSL_sk_set(ossl_check_X509_ALGOR_sk_type(sk), (idx), ossl_check_X509_ALGOR_type(ptr)))
147 #define sk_X509_ALGOR_find(sk, ptr) OPENSSL_sk_find(ossl_check_X509_ALGOR_sk_type(sk), ossl_check_X509_ALGOR_type(ptr))
148 #define sk_X509_ALGOR_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_X509_ALGOR_sk_type(sk), ossl_check_X509_ALGOR_type(ptr))
149 #define sk_X509_ALGOR_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_X509_ALGOR_sk_type(sk), ossl_check_X509_ALGOR_type(ptr), pnum)
150 #define sk_X509_ALGOR_sort(sk) OPENSSL_sk_sort(ossl_check_X509_ALGOR_sk_type(sk))
151 #define sk_X509_ALGOR_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_X509_ALGOR_sk_type(sk))
152 #define sk_X509_ALGOR_dup(sk) ((STACK_OF(X509_ALGOR) *)OPENSSL_sk_dup(ossl_check_const_X509_ALGOR_sk_type(sk)))
153 #define sk_X509_ALGOR_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(X509_ALGOR) *)OPENSSL_sk_deep_copy(ossl_check_const_X509_ALGOR_sk_type(sk), ossl_check_X509_ALGOR_copyfunc_type(copyfunc), ossl_check_X509_ALGOR_freefunc_type(freefunc)))
154 #define sk_X509_ALGOR_set_cmp_func(sk, cmp) ((sk_X509_ALGOR_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_X509_ALGOR_sk_type(sk), ossl_check_X509_ALGOR_compfunc_type(cmp)))
155 
156 
157 
158 # define ASN1_STRING_FLAG_BITS_LEFT 0x08/* Set if 0x07 has bits left value */
159 /*
160  * This indicates that the ASN1_STRING is not a real value but just a place
161  * holder for the location where indefinite length constructed data should be
162  * inserted in the memory buffer
163  */
164 # define ASN1_STRING_FLAG_NDEF 0x010
165 
166 /*
167  * This flag is used by the CMS code to indicate that a string is not
168  * complete and is a place holder for content when it had all been accessed.
169  * The flag will be reset when content has been written to it.
170  */
171 
172 # define ASN1_STRING_FLAG_CONT 0x020
173 /*
174  * This flag is used by ASN1 code to indicate an ASN1_STRING is an MSTRING
175  * type.
176  */
177 # define ASN1_STRING_FLAG_MSTRING 0x040
178 /* String is embedded and only content should be freed */
179 # define ASN1_STRING_FLAG_EMBED 0x080
180 /* String should be parsed in RFC 5280's time format */
181 # define ASN1_STRING_FLAG_X509_TIME 0x100
182 /* This is the base type that holds just about everything :-) */
183 struct asn1_string_st {
184     int length;
185     int type;
186     unsigned char *data;
187     /*
188      * The value of the following field depends on the type being held.  It
189      * is mostly being used for BIT_STRING so if the input data has a
190      * non-zero 'unused bits' value, it will be handled correctly
191      */
192     long flags;
193 };
194 
195 /*
196  * ASN1_ENCODING structure: this is used to save the received encoding of an
197  * ASN1 type. This is useful to get round problems with invalid encodings
198  * which can break signatures.
199  */
200 
201 typedef struct ASN1_ENCODING_st {
202     unsigned char *enc;         /* DER encoding */
203     long len;                   /* Length of encoding */
204     int modified;               /* set to 1 if 'enc' is invalid */
205 } ASN1_ENCODING;
206 
207 /* Used with ASN1 LONG type: if a long is set to this it is omitted */
208 # define ASN1_LONG_UNDEF 0x7fffffffL
209 
210 # define STABLE_FLAGS_MALLOC     0x01
211 /*
212  * A zero passed to ASN1_STRING_TABLE_new_add for the flags is interpreted
213  * as "don't change" and STABLE_FLAGS_MALLOC is always set. By setting
214  * STABLE_FLAGS_MALLOC only we can clear the existing value. Use the alias
215  * STABLE_FLAGS_CLEAR to reflect this.
216  */
217 # define STABLE_FLAGS_CLEAR      STABLE_FLAGS_MALLOC
218 # define STABLE_NO_MASK          0x02
219 # define DIRSTRING_TYPE  \
220  (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_BMPSTRING|B_ASN1_UTF8STRING)
221 # define PKCS9STRING_TYPE (DIRSTRING_TYPE|B_ASN1_IA5STRING)
222 
223 struct asn1_string_table_st {
224     int nid;
225     long minsize;
226     long maxsize;
227     unsigned long mask;
228     unsigned long flags;
229 };
230 
231 SKM_DEFINE_STACK_OF_INTERNAL(ASN1_STRING_TABLE, ASN1_STRING_TABLE, ASN1_STRING_TABLE)
232 #define sk_ASN1_STRING_TABLE_num(sk) OPENSSL_sk_num(ossl_check_const_ASN1_STRING_TABLE_sk_type(sk))
233 #define sk_ASN1_STRING_TABLE_value(sk, idx) ((ASN1_STRING_TABLE *)OPENSSL_sk_value(ossl_check_const_ASN1_STRING_TABLE_sk_type(sk), (idx)))
234 #define sk_ASN1_STRING_TABLE_new(cmp) ((STACK_OF(ASN1_STRING_TABLE) *)OPENSSL_sk_new(ossl_check_ASN1_STRING_TABLE_compfunc_type(cmp)))
235 #define sk_ASN1_STRING_TABLE_new_null() ((STACK_OF(ASN1_STRING_TABLE) *)OPENSSL_sk_new_null())
236 #define sk_ASN1_STRING_TABLE_new_reserve(cmp, n) ((STACK_OF(ASN1_STRING_TABLE) *)OPENSSL_sk_new_reserve(ossl_check_ASN1_STRING_TABLE_compfunc_type(cmp), (n)))
237 #define sk_ASN1_STRING_TABLE_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_ASN1_STRING_TABLE_sk_type(sk), (n))
238 #define sk_ASN1_STRING_TABLE_free(sk) OPENSSL_sk_free(ossl_check_ASN1_STRING_TABLE_sk_type(sk))
239 #define sk_ASN1_STRING_TABLE_zero(sk) OPENSSL_sk_zero(ossl_check_ASN1_STRING_TABLE_sk_type(sk))
240 #define sk_ASN1_STRING_TABLE_delete(sk, i) ((ASN1_STRING_TABLE *)OPENSSL_sk_delete(ossl_check_ASN1_STRING_TABLE_sk_type(sk), (i)))
241 #define sk_ASN1_STRING_TABLE_delete_ptr(sk, ptr) ((ASN1_STRING_TABLE *)OPENSSL_sk_delete_ptr(ossl_check_ASN1_STRING_TABLE_sk_type(sk), ossl_check_ASN1_STRING_TABLE_type(ptr)))
242 #define sk_ASN1_STRING_TABLE_push(sk, ptr) OPENSSL_sk_push(ossl_check_ASN1_STRING_TABLE_sk_type(sk), ossl_check_ASN1_STRING_TABLE_type(ptr))
243 #define sk_ASN1_STRING_TABLE_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_ASN1_STRING_TABLE_sk_type(sk), ossl_check_ASN1_STRING_TABLE_type(ptr))
244 #define sk_ASN1_STRING_TABLE_pop(sk) ((ASN1_STRING_TABLE *)OPENSSL_sk_pop(ossl_check_ASN1_STRING_TABLE_sk_type(sk)))
245 #define sk_ASN1_STRING_TABLE_shift(sk) ((ASN1_STRING_TABLE *)OPENSSL_sk_shift(ossl_check_ASN1_STRING_TABLE_sk_type(sk)))
246 #define sk_ASN1_STRING_TABLE_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_ASN1_STRING_TABLE_sk_type(sk),ossl_check_ASN1_STRING_TABLE_freefunc_type(freefunc))
247 #define sk_ASN1_STRING_TABLE_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_ASN1_STRING_TABLE_sk_type(sk), ossl_check_ASN1_STRING_TABLE_type(ptr), (idx))
248 #define sk_ASN1_STRING_TABLE_set(sk, idx, ptr) ((ASN1_STRING_TABLE *)OPENSSL_sk_set(ossl_check_ASN1_STRING_TABLE_sk_type(sk), (idx), ossl_check_ASN1_STRING_TABLE_type(ptr)))
249 #define sk_ASN1_STRING_TABLE_find(sk, ptr) OPENSSL_sk_find(ossl_check_ASN1_STRING_TABLE_sk_type(sk), ossl_check_ASN1_STRING_TABLE_type(ptr))
250 #define sk_ASN1_STRING_TABLE_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_ASN1_STRING_TABLE_sk_type(sk), ossl_check_ASN1_STRING_TABLE_type(ptr))
251 #define sk_ASN1_STRING_TABLE_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_ASN1_STRING_TABLE_sk_type(sk), ossl_check_ASN1_STRING_TABLE_type(ptr), pnum)
252 #define sk_ASN1_STRING_TABLE_sort(sk) OPENSSL_sk_sort(ossl_check_ASN1_STRING_TABLE_sk_type(sk))
253 #define sk_ASN1_STRING_TABLE_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_ASN1_STRING_TABLE_sk_type(sk))
254 #define sk_ASN1_STRING_TABLE_dup(sk) ((STACK_OF(ASN1_STRING_TABLE) *)OPENSSL_sk_dup(ossl_check_const_ASN1_STRING_TABLE_sk_type(sk)))
255 #define sk_ASN1_STRING_TABLE_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(ASN1_STRING_TABLE) *)OPENSSL_sk_deep_copy(ossl_check_const_ASN1_STRING_TABLE_sk_type(sk), ossl_check_ASN1_STRING_TABLE_copyfunc_type(copyfunc), ossl_check_ASN1_STRING_TABLE_freefunc_type(freefunc)))
256 #define sk_ASN1_STRING_TABLE_set_cmp_func(sk, cmp) ((sk_ASN1_STRING_TABLE_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_ASN1_STRING_TABLE_sk_type(sk), ossl_check_ASN1_STRING_TABLE_compfunc_type(cmp)))
257 
258 
259 /* size limits: this stuff is taken straight from RFC2459 */
260 
261 # define ub_name                         32768
262 # define ub_common_name                  64
263 # define ub_locality_name                128
264 # define ub_state_name                   128
265 # define ub_organization_name            64
266 # define ub_organization_unit_name       64
267 # define ub_title                        64
268 # define ub_email_address                128
269 
270 /*
271  * Declarations for template structures: for full definitions see asn1t.h
272  */
273 typedef struct ASN1_TEMPLATE_st ASN1_TEMPLATE;
274 typedef struct ASN1_TLC_st ASN1_TLC;
275 /* This is just an opaque pointer */
276 typedef struct ASN1_VALUE_st ASN1_VALUE;
277 
278 /* Declare ASN1 functions: the implement macro in in asn1t.h */
279 
280 /*
281  * The mysterious 'extern' that's passed to some macros is innocuous,
282  * and is there to quiet pre-C99 compilers that may complain about empty
283  * arguments in macro calls.
284  */
285 
286 # define DECLARE_ASN1_FUNCTIONS_attr(attr, type)                            \
287     DECLARE_ASN1_FUNCTIONS_name_attr(attr, type, type)
288 # define DECLARE_ASN1_FUNCTIONS(type)                                       \
289     DECLARE_ASN1_FUNCTIONS_attr(extern, type)
290 
291 # define DECLARE_ASN1_ALLOC_FUNCTIONS_attr(attr, type)                      \
292     DECLARE_ASN1_ALLOC_FUNCTIONS_name_attr(attr, type, type)
293 # define DECLARE_ASN1_ALLOC_FUNCTIONS(type)                                 \
294     DECLARE_ASN1_ALLOC_FUNCTIONS_attr(extern, type)
295 
296 # define DECLARE_ASN1_FUNCTIONS_name_attr(attr, type, name)                 \
297     DECLARE_ASN1_ALLOC_FUNCTIONS_name_attr(attr, type, name)                \
298     DECLARE_ASN1_ENCODE_FUNCTIONS_name_attr(attr, type, name)
299 # define DECLARE_ASN1_FUNCTIONS_name(type, name)                            \
300     DECLARE_ASN1_FUNCTIONS_name_attr(extern, type, name)
301 
302 # define DECLARE_ASN1_ENCODE_FUNCTIONS_attr(attr, type, itname, name)       \
303     DECLARE_ASN1_ENCODE_FUNCTIONS_only_attr(attr, type, name)               \
304     DECLARE_ASN1_ITEM_attr(attr, itname)
305 # define DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name)                  \
306     DECLARE_ASN1_ENCODE_FUNCTIONS_attr(extern, type, itname, name)
307 
308 # define DECLARE_ASN1_ENCODE_FUNCTIONS_name_attr(attr, type, name)          \
309     DECLARE_ASN1_ENCODE_FUNCTIONS_attr(attr, type, name, name)
310 # define DECLARE_ASN1_ENCODE_FUNCTIONS_name(type, name) \
311     DECLARE_ASN1_ENCODE_FUNCTIONS_name_attr(extern, type, name)
312 
313 # define DECLARE_ASN1_ENCODE_FUNCTIONS_only_attr(attr, type, name)          \
314     attr type *d2i_##name(type **a, const unsigned char **in, long len);    \
315     attr int i2d_##name(const type *a, unsigned char **out);
316 # define DECLARE_ASN1_ENCODE_FUNCTIONS_only(type, name)                     \
317     DECLARE_ASN1_ENCODE_FUNCTIONS_only_attr(extern, type, name)
318 
319 # define DECLARE_ASN1_NDEF_FUNCTION_attr(attr, name)                        \
320     attr int i2d_##name##_NDEF(const name *a, unsigned char **out);
321 # define DECLARE_ASN1_NDEF_FUNCTION(name)                                   \
322     DECLARE_ASN1_NDEF_FUNCTION_attr(extern, name)
323 
324 # define DECLARE_ASN1_ALLOC_FUNCTIONS_name_attr(attr, type, name)           \
325     attr type *name##_new(void);                                            \
326     attr void name##_free(type *a);
327 # define DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name)                      \
328     DECLARE_ASN1_ALLOC_FUNCTIONS_name_attr(extern, type, name)
329 
330 # define DECLARE_ASN1_DUP_FUNCTION_attr(attr, type)                         \
331     DECLARE_ASN1_DUP_FUNCTION_name_attr(attr, type, type)
332 # define DECLARE_ASN1_DUP_FUNCTION(type)                                    \
333     DECLARE_ASN1_DUP_FUNCTION_attr(extern, type)
334 
335 # define DECLARE_ASN1_DUP_FUNCTION_name_attr(attr, type, name)              \
336     attr type *name##_dup(const type *a);
337 # define DECLARE_ASN1_DUP_FUNCTION_name(type, name)                         \
338     DECLARE_ASN1_DUP_FUNCTION_name_attr(extern, type, name)
339 
340 # define DECLARE_ASN1_PRINT_FUNCTION_attr(attr, stname)                     \
341     DECLARE_ASN1_PRINT_FUNCTION_fname_attr(attr, stname, stname)
342 # define DECLARE_ASN1_PRINT_FUNCTION(stname)                                \
343     DECLARE_ASN1_PRINT_FUNCTION_attr(extern, stname)
344 
345 # define DECLARE_ASN1_PRINT_FUNCTION_fname_attr(attr, stname, fname)        \
346     attr int fname##_print_ctx(BIO *out, const stname *x, int indent,       \
347                                const ASN1_PCTX *pctx);
348 # define DECLARE_ASN1_PRINT_FUNCTION_fname(stname, fname)                   \
349     DECLARE_ASN1_PRINT_FUNCTION_fname_attr(extern, stname, fname)
350 
351 # define D2I_OF(type) type *(*)(type **,const unsigned char **,long)
352 # define I2D_OF(type) int (*)(const type *,unsigned char **)
353 
354 # define CHECKED_D2I_OF(type, d2i) \
355     ((d2i_of_void*) (1 ? d2i : ((D2I_OF(type))0)))
356 # define CHECKED_I2D_OF(type, i2d) \
357     ((i2d_of_void*) (1 ? i2d : ((I2D_OF(type))0)))
358 # define CHECKED_NEW_OF(type, xnew) \
359     ((void *(*)(void)) (1 ? xnew : ((type *(*)(void))0)))
360 # define CHECKED_PTR_OF(type, p) \
361     ((void*) (1 ? p : (type*)0))
362 # define CHECKED_PPTR_OF(type, p) \
363     ((void**) (1 ? p : (type**)0))
364 
365 # define TYPEDEF_D2I_OF(type) typedef type *d2i_of_##type(type **,const unsigned char **,long)
366 # define TYPEDEF_I2D_OF(type) typedef int i2d_of_##type(const type *,unsigned char **)
367 # define TYPEDEF_D2I2D_OF(type) TYPEDEF_D2I_OF(type); TYPEDEF_I2D_OF(type)
368 
369 typedef void *d2i_of_void(void **, const unsigned char **, long);
370 typedef int i2d_of_void(const void *, unsigned char **);
371 
372 /*-
373  * The following macros and typedefs allow an ASN1_ITEM
374  * to be embedded in a structure and referenced. Since
375  * the ASN1_ITEM pointers need to be globally accessible
376  * (possibly from shared libraries) they may exist in
377  * different forms. On platforms that support it the
378  * ASN1_ITEM structure itself will be globally exported.
379  * Other platforms will export a function that returns
380  * an ASN1_ITEM pointer.
381  *
382  * To handle both cases transparently the macros below
383  * should be used instead of hard coding an ASN1_ITEM
384  * pointer in a structure.
385  *
386  * The structure will look like this:
387  *
388  * typedef struct SOMETHING_st {
389  *      ...
390  *      ASN1_ITEM_EXP *iptr;
391  *      ...
392  * } SOMETHING;
393  *
394  * It would be initialised as e.g.:
395  *
396  * SOMETHING somevar = {...,ASN1_ITEM_ref(X509),...};
397  *
398  * and the actual pointer extracted with:
399  *
400  * const ASN1_ITEM *it = ASN1_ITEM_ptr(somevar.iptr);
401  *
402  * Finally an ASN1_ITEM pointer can be extracted from an
403  * appropriate reference with: ASN1_ITEM_rptr(X509). This
404  * would be used when a function takes an ASN1_ITEM * argument.
405  *
406  */
407 
408 
409 /*
410  * Platforms that can't easily handle shared global variables are declared as
411  * functions returning ASN1_ITEM pointers.
412  */
413 
414 /* ASN1_ITEM pointer exported type */
415 typedef const ASN1_ITEM *ASN1_ITEM_EXP (void);
416 
417 /* Macro to obtain ASN1_ITEM pointer from exported type */
418 # define ASN1_ITEM_ptr(iptr) (iptr())
419 
420 /* Macro to include ASN1_ITEM pointer from base type */
421 # define ASN1_ITEM_ref(iptr) (iptr##_it)
422 
423 # define ASN1_ITEM_rptr(ref) (ref##_it())
424 
425 # define DECLARE_ASN1_ITEM_attr(attr, name)                                 \
426     attr const ASN1_ITEM * name##_it(void);
427 # define DECLARE_ASN1_ITEM(name)                                            \
428     DECLARE_ASN1_ITEM_attr(extern, name)
429 
430 /* Parameters used by ASN1_STRING_print_ex() */
431 
432 /*
433  * These determine which characters to escape: RFC2253 special characters,
434  * control characters and MSB set characters
435  */
436 
437 # define ASN1_STRFLGS_ESC_2253           1
438 # define ASN1_STRFLGS_ESC_CTRL           2
439 # define ASN1_STRFLGS_ESC_MSB            4
440 
441 /* Lower 8 bits are reserved as an output type specifier */
442 # define ASN1_DTFLGS_TYPE_MASK    0x0FUL
443 # define ASN1_DTFLGS_RFC822       0x00UL
444 # define ASN1_DTFLGS_ISO8601      0x01UL
445 
446 /*
447  * This flag determines how we do escaping: normally RC2253 backslash only,
448  * set this to use backslash and quote.
449  */
450 
451 # define ASN1_STRFLGS_ESC_QUOTE          8
452 
453 /* These three flags are internal use only. */
454 
455 /* Character is a valid PrintableString character */
456 # define CHARTYPE_PRINTABLESTRING        0x10
457 /* Character needs escaping if it is the first character */
458 # define CHARTYPE_FIRST_ESC_2253         0x20
459 /* Character needs escaping if it is the last character */
460 # define CHARTYPE_LAST_ESC_2253          0x40
461 
462 /*
463  * NB the internal flags are safely reused below by flags handled at the top
464  * level.
465  */
466 
467 /*
468  * If this is set we convert all character strings to UTF8 first
469  */
470 
471 # define ASN1_STRFLGS_UTF8_CONVERT       0x10
472 
473 /*
474  * If this is set we don't attempt to interpret content: just assume all
475  * strings are 1 byte per character. This will produce some pretty odd
476  * looking output!
477  */
478 
479 # define ASN1_STRFLGS_IGNORE_TYPE        0x20
480 
481 /* If this is set we include the string type in the output */
482 # define ASN1_STRFLGS_SHOW_TYPE          0x40
483 
484 /*
485  * This determines which strings to display and which to 'dump' (hex dump of
486  * content octets or DER encoding). We can only dump non character strings or
487  * everything. If we don't dump 'unknown' they are interpreted as character
488  * strings with 1 octet per character and are subject to the usual escaping
489  * options.
490  */
491 
492 # define ASN1_STRFLGS_DUMP_ALL           0x80
493 # define ASN1_STRFLGS_DUMP_UNKNOWN       0x100
494 
495 /*
496  * These determine what 'dumping' does, we can dump the content octets or the
497  * DER encoding: both use the RFC2253 #XXXXX notation.
498  */
499 
500 # define ASN1_STRFLGS_DUMP_DER           0x200
501 
502 /*
503  * This flag specifies that RC2254 escaping shall be performed.
504  */
505 #define ASN1_STRFLGS_ESC_2254           0x400
506 
507 /*
508  * All the string flags consistent with RFC2253, escaping control characters
509  * isn't essential in RFC2253 but it is advisable anyway.
510  */
511 
512 # define ASN1_STRFLGS_RFC2253    (ASN1_STRFLGS_ESC_2253 | \
513                                 ASN1_STRFLGS_ESC_CTRL | \
514                                 ASN1_STRFLGS_ESC_MSB | \
515                                 ASN1_STRFLGS_UTF8_CONVERT | \
516                                 ASN1_STRFLGS_DUMP_UNKNOWN | \
517                                 ASN1_STRFLGS_DUMP_DER)
518 
519 
520 struct asn1_type_st {
521     int type;
522     union {
523         char *ptr;
524         ASN1_BOOLEAN boolean;
525         ASN1_STRING *asn1_string;
526         ASN1_OBJECT *object;
527         ASN1_INTEGER *integer;
528         ASN1_ENUMERATED *enumerated;
529         ASN1_BIT_STRING *bit_string;
530         ASN1_OCTET_STRING *octet_string;
531         ASN1_PRINTABLESTRING *printablestring;
532         ASN1_T61STRING *t61string;
533         ASN1_IA5STRING *ia5string;
534         ASN1_GENERALSTRING *generalstring;
535         ASN1_BMPSTRING *bmpstring;
536         ASN1_UNIVERSALSTRING *universalstring;
537         ASN1_UTCTIME *utctime;
538         ASN1_GENERALIZEDTIME *generalizedtime;
539         ASN1_VISIBLESTRING *visiblestring;
540         ASN1_UTF8STRING *utf8string;
541         /*
542          * set and sequence are left complete and still contain the set or
543          * sequence bytes
544          */
545         ASN1_STRING *set;
546         ASN1_STRING *sequence;
547         ASN1_VALUE *asn1_value;
548     } value;
549 };
550 
551 SKM_DEFINE_STACK_OF_INTERNAL(ASN1_TYPE, ASN1_TYPE, ASN1_TYPE)
552 #define sk_ASN1_TYPE_num(sk) OPENSSL_sk_num(ossl_check_const_ASN1_TYPE_sk_type(sk))
553 #define sk_ASN1_TYPE_value(sk, idx) ((ASN1_TYPE *)OPENSSL_sk_value(ossl_check_const_ASN1_TYPE_sk_type(sk), (idx)))
554 #define sk_ASN1_TYPE_new(cmp) ((STACK_OF(ASN1_TYPE) *)OPENSSL_sk_new(ossl_check_ASN1_TYPE_compfunc_type(cmp)))
555 #define sk_ASN1_TYPE_new_null() ((STACK_OF(ASN1_TYPE) *)OPENSSL_sk_new_null())
556 #define sk_ASN1_TYPE_new_reserve(cmp, n) ((STACK_OF(ASN1_TYPE) *)OPENSSL_sk_new_reserve(ossl_check_ASN1_TYPE_compfunc_type(cmp), (n)))
557 #define sk_ASN1_TYPE_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_ASN1_TYPE_sk_type(sk), (n))
558 #define sk_ASN1_TYPE_free(sk) OPENSSL_sk_free(ossl_check_ASN1_TYPE_sk_type(sk))
559 #define sk_ASN1_TYPE_zero(sk) OPENSSL_sk_zero(ossl_check_ASN1_TYPE_sk_type(sk))
560 #define sk_ASN1_TYPE_delete(sk, i) ((ASN1_TYPE *)OPENSSL_sk_delete(ossl_check_ASN1_TYPE_sk_type(sk), (i)))
561 #define sk_ASN1_TYPE_delete_ptr(sk, ptr) ((ASN1_TYPE *)OPENSSL_sk_delete_ptr(ossl_check_ASN1_TYPE_sk_type(sk), ossl_check_ASN1_TYPE_type(ptr)))
562 #define sk_ASN1_TYPE_push(sk, ptr) OPENSSL_sk_push(ossl_check_ASN1_TYPE_sk_type(sk), ossl_check_ASN1_TYPE_type(ptr))
563 #define sk_ASN1_TYPE_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_ASN1_TYPE_sk_type(sk), ossl_check_ASN1_TYPE_type(ptr))
564 #define sk_ASN1_TYPE_pop(sk) ((ASN1_TYPE *)OPENSSL_sk_pop(ossl_check_ASN1_TYPE_sk_type(sk)))
565 #define sk_ASN1_TYPE_shift(sk) ((ASN1_TYPE *)OPENSSL_sk_shift(ossl_check_ASN1_TYPE_sk_type(sk)))
566 #define sk_ASN1_TYPE_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_ASN1_TYPE_sk_type(sk),ossl_check_ASN1_TYPE_freefunc_type(freefunc))
567 #define sk_ASN1_TYPE_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_ASN1_TYPE_sk_type(sk), ossl_check_ASN1_TYPE_type(ptr), (idx))
568 #define sk_ASN1_TYPE_set(sk, idx, ptr) ((ASN1_TYPE *)OPENSSL_sk_set(ossl_check_ASN1_TYPE_sk_type(sk), (idx), ossl_check_ASN1_TYPE_type(ptr)))
569 #define sk_ASN1_TYPE_find(sk, ptr) OPENSSL_sk_find(ossl_check_ASN1_TYPE_sk_type(sk), ossl_check_ASN1_TYPE_type(ptr))
570 #define sk_ASN1_TYPE_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_ASN1_TYPE_sk_type(sk), ossl_check_ASN1_TYPE_type(ptr))
571 #define sk_ASN1_TYPE_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_ASN1_TYPE_sk_type(sk), ossl_check_ASN1_TYPE_type(ptr), pnum)
572 #define sk_ASN1_TYPE_sort(sk) OPENSSL_sk_sort(ossl_check_ASN1_TYPE_sk_type(sk))
573 #define sk_ASN1_TYPE_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_ASN1_TYPE_sk_type(sk))
574 #define sk_ASN1_TYPE_dup(sk) ((STACK_OF(ASN1_TYPE) *)OPENSSL_sk_dup(ossl_check_const_ASN1_TYPE_sk_type(sk)))
575 #define sk_ASN1_TYPE_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(ASN1_TYPE) *)OPENSSL_sk_deep_copy(ossl_check_const_ASN1_TYPE_sk_type(sk), ossl_check_ASN1_TYPE_copyfunc_type(copyfunc), ossl_check_ASN1_TYPE_freefunc_type(freefunc)))
576 #define sk_ASN1_TYPE_set_cmp_func(sk, cmp) ((sk_ASN1_TYPE_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_ASN1_TYPE_sk_type(sk), ossl_check_ASN1_TYPE_compfunc_type(cmp)))
577 
578 
579 typedef STACK_OF(ASN1_TYPE) ASN1_SEQUENCE_ANY;
580 
581 DECLARE_ASN1_ENCODE_FUNCTIONS_name(ASN1_SEQUENCE_ANY, ASN1_SEQUENCE_ANY)
582 DECLARE_ASN1_ENCODE_FUNCTIONS_name(ASN1_SEQUENCE_ANY, ASN1_SET_ANY)
583 
584 /* This is used to contain a list of bit names */
585 typedef struct BIT_STRING_BITNAME_st {
586     int bitnum;
587     const char *lname;
588     const char *sname;
589 } BIT_STRING_BITNAME;
590 
591 # define B_ASN1_TIME \
592                         B_ASN1_UTCTIME | \
593                         B_ASN1_GENERALIZEDTIME
594 
595 # define B_ASN1_PRINTABLE \
596                         B_ASN1_NUMERICSTRING| \
597                         B_ASN1_PRINTABLESTRING| \
598                         B_ASN1_T61STRING| \
599                         B_ASN1_IA5STRING| \
600                         B_ASN1_BIT_STRING| \
601                         B_ASN1_UNIVERSALSTRING|\
602                         B_ASN1_BMPSTRING|\
603                         B_ASN1_UTF8STRING|\
604                         B_ASN1_SEQUENCE|\
605                         B_ASN1_UNKNOWN
606 
607 # define B_ASN1_DIRECTORYSTRING \
608                         B_ASN1_PRINTABLESTRING| \
609                         B_ASN1_TELETEXSTRING|\
610                         B_ASN1_BMPSTRING|\
611                         B_ASN1_UNIVERSALSTRING|\
612                         B_ASN1_UTF8STRING
613 
614 # define B_ASN1_DISPLAYTEXT \
615                         B_ASN1_IA5STRING| \
616                         B_ASN1_VISIBLESTRING| \
617                         B_ASN1_BMPSTRING|\
618                         B_ASN1_UTF8STRING
619 
620 DECLARE_ASN1_ALLOC_FUNCTIONS_name(ASN1_TYPE, ASN1_TYPE)
621 DECLARE_ASN1_ENCODE_FUNCTIONS(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
622 
623 int ASN1_TYPE_get(const ASN1_TYPE *a);
624 void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value);
625 int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value);
626 int ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b);
627 
628 ASN1_TYPE *ASN1_TYPE_pack_sequence(const ASN1_ITEM *it, void *s, ASN1_TYPE **t);
629 void *ASN1_TYPE_unpack_sequence(const ASN1_ITEM *it, const ASN1_TYPE *t);
630 
631 SKM_DEFINE_STACK_OF_INTERNAL(ASN1_OBJECT, ASN1_OBJECT, ASN1_OBJECT)
632 #define sk_ASN1_OBJECT_num(sk) OPENSSL_sk_num(ossl_check_const_ASN1_OBJECT_sk_type(sk))
633 #define sk_ASN1_OBJECT_value(sk, idx) ((ASN1_OBJECT *)OPENSSL_sk_value(ossl_check_const_ASN1_OBJECT_sk_type(sk), (idx)))
634 #define sk_ASN1_OBJECT_new(cmp) ((STACK_OF(ASN1_OBJECT) *)OPENSSL_sk_new(ossl_check_ASN1_OBJECT_compfunc_type(cmp)))
635 #define sk_ASN1_OBJECT_new_null() ((STACK_OF(ASN1_OBJECT) *)OPENSSL_sk_new_null())
636 #define sk_ASN1_OBJECT_new_reserve(cmp, n) ((STACK_OF(ASN1_OBJECT) *)OPENSSL_sk_new_reserve(ossl_check_ASN1_OBJECT_compfunc_type(cmp), (n)))
637 #define sk_ASN1_OBJECT_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_ASN1_OBJECT_sk_type(sk), (n))
638 #define sk_ASN1_OBJECT_free(sk) OPENSSL_sk_free(ossl_check_ASN1_OBJECT_sk_type(sk))
639 #define sk_ASN1_OBJECT_zero(sk) OPENSSL_sk_zero(ossl_check_ASN1_OBJECT_sk_type(sk))
640 #define sk_ASN1_OBJECT_delete(sk, i) ((ASN1_OBJECT *)OPENSSL_sk_delete(ossl_check_ASN1_OBJECT_sk_type(sk), (i)))
641 #define sk_ASN1_OBJECT_delete_ptr(sk, ptr) ((ASN1_OBJECT *)OPENSSL_sk_delete_ptr(ossl_check_ASN1_OBJECT_sk_type(sk), ossl_check_ASN1_OBJECT_type(ptr)))
642 #define sk_ASN1_OBJECT_push(sk, ptr) OPENSSL_sk_push(ossl_check_ASN1_OBJECT_sk_type(sk), ossl_check_ASN1_OBJECT_type(ptr))
643 #define sk_ASN1_OBJECT_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_ASN1_OBJECT_sk_type(sk), ossl_check_ASN1_OBJECT_type(ptr))
644 #define sk_ASN1_OBJECT_pop(sk) ((ASN1_OBJECT *)OPENSSL_sk_pop(ossl_check_ASN1_OBJECT_sk_type(sk)))
645 #define sk_ASN1_OBJECT_shift(sk) ((ASN1_OBJECT *)OPENSSL_sk_shift(ossl_check_ASN1_OBJECT_sk_type(sk)))
646 #define sk_ASN1_OBJECT_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_ASN1_OBJECT_sk_type(sk),ossl_check_ASN1_OBJECT_freefunc_type(freefunc))
647 #define sk_ASN1_OBJECT_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_ASN1_OBJECT_sk_type(sk), ossl_check_ASN1_OBJECT_type(ptr), (idx))
648 #define sk_ASN1_OBJECT_set(sk, idx, ptr) ((ASN1_OBJECT *)OPENSSL_sk_set(ossl_check_ASN1_OBJECT_sk_type(sk), (idx), ossl_check_ASN1_OBJECT_type(ptr)))
649 #define sk_ASN1_OBJECT_find(sk, ptr) OPENSSL_sk_find(ossl_check_ASN1_OBJECT_sk_type(sk), ossl_check_ASN1_OBJECT_type(ptr))
650 #define sk_ASN1_OBJECT_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_ASN1_OBJECT_sk_type(sk), ossl_check_ASN1_OBJECT_type(ptr))
651 #define sk_ASN1_OBJECT_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_ASN1_OBJECT_sk_type(sk), ossl_check_ASN1_OBJECT_type(ptr), pnum)
652 #define sk_ASN1_OBJECT_sort(sk) OPENSSL_sk_sort(ossl_check_ASN1_OBJECT_sk_type(sk))
653 #define sk_ASN1_OBJECT_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_ASN1_OBJECT_sk_type(sk))
654 #define sk_ASN1_OBJECT_dup(sk) ((STACK_OF(ASN1_OBJECT) *)OPENSSL_sk_dup(ossl_check_const_ASN1_OBJECT_sk_type(sk)))
655 #define sk_ASN1_OBJECT_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(ASN1_OBJECT) *)OPENSSL_sk_deep_copy(ossl_check_const_ASN1_OBJECT_sk_type(sk), ossl_check_ASN1_OBJECT_copyfunc_type(copyfunc), ossl_check_ASN1_OBJECT_freefunc_type(freefunc)))
656 #define sk_ASN1_OBJECT_set_cmp_func(sk, cmp) ((sk_ASN1_OBJECT_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_ASN1_OBJECT_sk_type(sk), ossl_check_ASN1_OBJECT_compfunc_type(cmp)))
657 
658 
659 DECLARE_ASN1_FUNCTIONS(ASN1_OBJECT)
660 
661 ASN1_STRING *ASN1_STRING_new(void);
662 void ASN1_STRING_free(ASN1_STRING *a);
663 void ASN1_STRING_clear_free(ASN1_STRING *a);
664 int ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str);
665 DECLARE_ASN1_DUP_FUNCTION(ASN1_STRING)
666 ASN1_STRING *ASN1_STRING_type_new(int type);
667 int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b);
668   /*
669    * Since this is used to store all sorts of things, via macros, for now,
670    * make its data void *
671    */
672 int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len);
673 void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len);
674 int ASN1_STRING_length(const ASN1_STRING *x);
675 # ifndef OPENSSL_NO_DEPRECATED_3_0
676 OSSL_DEPRECATEDIN_3_0 void ASN1_STRING_length_set(ASN1_STRING *x, int n);
677 # endif
678 int ASN1_STRING_type(const ASN1_STRING *x);
679 # ifndef OPENSSL_NO_DEPRECATED_1_1_0
680 OSSL_DEPRECATEDIN_1_1_0 unsigned char *ASN1_STRING_data(ASN1_STRING *x);
681 # endif
682 const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *x);
683 
684 DECLARE_ASN1_FUNCTIONS(ASN1_BIT_STRING)
685 int ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d, int length);
686 int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value);
687 int ASN1_BIT_STRING_get_bit(const ASN1_BIT_STRING *a, int n);
688 int ASN1_BIT_STRING_check(const ASN1_BIT_STRING *a,
689                           const unsigned char *flags, int flags_len);
690 
691 int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
692                                BIT_STRING_BITNAME *tbl, int indent);
693 int ASN1_BIT_STRING_num_asc(const char *name, BIT_STRING_BITNAME *tbl);
694 int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, const char *name, int value,
695                             BIT_STRING_BITNAME *tbl);
696 
697 SKM_DEFINE_STACK_OF_INTERNAL(ASN1_INTEGER, ASN1_INTEGER, ASN1_INTEGER)
698 #define sk_ASN1_INTEGER_num(sk) OPENSSL_sk_num(ossl_check_const_ASN1_INTEGER_sk_type(sk))
699 #define sk_ASN1_INTEGER_value(sk, idx) ((ASN1_INTEGER *)OPENSSL_sk_value(ossl_check_const_ASN1_INTEGER_sk_type(sk), (idx)))
700 #define sk_ASN1_INTEGER_new(cmp) ((STACK_OF(ASN1_INTEGER) *)OPENSSL_sk_new(ossl_check_ASN1_INTEGER_compfunc_type(cmp)))
701 #define sk_ASN1_INTEGER_new_null() ((STACK_OF(ASN1_INTEGER) *)OPENSSL_sk_new_null())
702 #define sk_ASN1_INTEGER_new_reserve(cmp, n) ((STACK_OF(ASN1_INTEGER) *)OPENSSL_sk_new_reserve(ossl_check_ASN1_INTEGER_compfunc_type(cmp), (n)))
703 #define sk_ASN1_INTEGER_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_ASN1_INTEGER_sk_type(sk), (n))
704 #define sk_ASN1_INTEGER_free(sk) OPENSSL_sk_free(ossl_check_ASN1_INTEGER_sk_type(sk))
705 #define sk_ASN1_INTEGER_zero(sk) OPENSSL_sk_zero(ossl_check_ASN1_INTEGER_sk_type(sk))
706 #define sk_ASN1_INTEGER_delete(sk, i) ((ASN1_INTEGER *)OPENSSL_sk_delete(ossl_check_ASN1_INTEGER_sk_type(sk), (i)))
707 #define sk_ASN1_INTEGER_delete_ptr(sk, ptr) ((ASN1_INTEGER *)OPENSSL_sk_delete_ptr(ossl_check_ASN1_INTEGER_sk_type(sk), ossl_check_ASN1_INTEGER_type(ptr)))
708 #define sk_ASN1_INTEGER_push(sk, ptr) OPENSSL_sk_push(ossl_check_ASN1_INTEGER_sk_type(sk), ossl_check_ASN1_INTEGER_type(ptr))
709 #define sk_ASN1_INTEGER_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_ASN1_INTEGER_sk_type(sk), ossl_check_ASN1_INTEGER_type(ptr))
710 #define sk_ASN1_INTEGER_pop(sk) ((ASN1_INTEGER *)OPENSSL_sk_pop(ossl_check_ASN1_INTEGER_sk_type(sk)))
711 #define sk_ASN1_INTEGER_shift(sk) ((ASN1_INTEGER *)OPENSSL_sk_shift(ossl_check_ASN1_INTEGER_sk_type(sk)))
712 #define sk_ASN1_INTEGER_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_ASN1_INTEGER_sk_type(sk),ossl_check_ASN1_INTEGER_freefunc_type(freefunc))
713 #define sk_ASN1_INTEGER_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_ASN1_INTEGER_sk_type(sk), ossl_check_ASN1_INTEGER_type(ptr), (idx))
714 #define sk_ASN1_INTEGER_set(sk, idx, ptr) ((ASN1_INTEGER *)OPENSSL_sk_set(ossl_check_ASN1_INTEGER_sk_type(sk), (idx), ossl_check_ASN1_INTEGER_type(ptr)))
715 #define sk_ASN1_INTEGER_find(sk, ptr) OPENSSL_sk_find(ossl_check_ASN1_INTEGER_sk_type(sk), ossl_check_ASN1_INTEGER_type(ptr))
716 #define sk_ASN1_INTEGER_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_ASN1_INTEGER_sk_type(sk), ossl_check_ASN1_INTEGER_type(ptr))
717 #define sk_ASN1_INTEGER_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_ASN1_INTEGER_sk_type(sk), ossl_check_ASN1_INTEGER_type(ptr), pnum)
718 #define sk_ASN1_INTEGER_sort(sk) OPENSSL_sk_sort(ossl_check_ASN1_INTEGER_sk_type(sk))
719 #define sk_ASN1_INTEGER_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_ASN1_INTEGER_sk_type(sk))
720 #define sk_ASN1_INTEGER_dup(sk) ((STACK_OF(ASN1_INTEGER) *)OPENSSL_sk_dup(ossl_check_const_ASN1_INTEGER_sk_type(sk)))
721 #define sk_ASN1_INTEGER_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(ASN1_INTEGER) *)OPENSSL_sk_deep_copy(ossl_check_const_ASN1_INTEGER_sk_type(sk), ossl_check_ASN1_INTEGER_copyfunc_type(copyfunc), ossl_check_ASN1_INTEGER_freefunc_type(freefunc)))
722 #define sk_ASN1_INTEGER_set_cmp_func(sk, cmp) ((sk_ASN1_INTEGER_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_ASN1_INTEGER_sk_type(sk), ossl_check_ASN1_INTEGER_compfunc_type(cmp)))
723 
724 
725 
726 DECLARE_ASN1_FUNCTIONS(ASN1_INTEGER)
727 ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp,
728                                 long length);
729 DECLARE_ASN1_DUP_FUNCTION(ASN1_INTEGER)
730 int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y);
731 
732 DECLARE_ASN1_FUNCTIONS(ASN1_ENUMERATED)
733 
734 int ASN1_UTCTIME_check(const ASN1_UTCTIME *a);
735 ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t);
736 ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
737                                int offset_day, long offset_sec);
738 int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str);
739 int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t);
740 
741 int ASN1_GENERALIZEDTIME_check(const ASN1_GENERALIZEDTIME *a);
742 ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
743                                                time_t t);
744 ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
745                                                time_t t, int offset_day,
746                                                long offset_sec);
747 int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str);
748 
749 int ASN1_TIME_diff(int *pday, int *psec,
750                    const ASN1_TIME *from, const ASN1_TIME *to);
751 
752 DECLARE_ASN1_FUNCTIONS(ASN1_OCTET_STRING)
753 DECLARE_ASN1_DUP_FUNCTION(ASN1_OCTET_STRING)
754 int ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a,
755                           const ASN1_OCTET_STRING *b);
756 int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, const unsigned char *data,
757                           int len);
758 
759 SKM_DEFINE_STACK_OF_INTERNAL(ASN1_UTF8STRING, ASN1_UTF8STRING, ASN1_UTF8STRING)
760 #define sk_ASN1_UTF8STRING_num(sk) OPENSSL_sk_num(ossl_check_const_ASN1_UTF8STRING_sk_type(sk))
761 #define sk_ASN1_UTF8STRING_value(sk, idx) ((ASN1_UTF8STRING *)OPENSSL_sk_value(ossl_check_const_ASN1_UTF8STRING_sk_type(sk), (idx)))
762 #define sk_ASN1_UTF8STRING_new(cmp) ((STACK_OF(ASN1_UTF8STRING) *)OPENSSL_sk_new(ossl_check_ASN1_UTF8STRING_compfunc_type(cmp)))
763 #define sk_ASN1_UTF8STRING_new_null() ((STACK_OF(ASN1_UTF8STRING) *)OPENSSL_sk_new_null())
764 #define sk_ASN1_UTF8STRING_new_reserve(cmp, n) ((STACK_OF(ASN1_UTF8STRING) *)OPENSSL_sk_new_reserve(ossl_check_ASN1_UTF8STRING_compfunc_type(cmp), (n)))
765 #define sk_ASN1_UTF8STRING_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_ASN1_UTF8STRING_sk_type(sk), (n))
766 #define sk_ASN1_UTF8STRING_free(sk) OPENSSL_sk_free(ossl_check_ASN1_UTF8STRING_sk_type(sk))
767 #define sk_ASN1_UTF8STRING_zero(sk) OPENSSL_sk_zero(ossl_check_ASN1_UTF8STRING_sk_type(sk))
768 #define sk_ASN1_UTF8STRING_delete(sk, i) ((ASN1_UTF8STRING *)OPENSSL_sk_delete(ossl_check_ASN1_UTF8STRING_sk_type(sk), (i)))
769 #define sk_ASN1_UTF8STRING_delete_ptr(sk, ptr) ((ASN1_UTF8STRING *)OPENSSL_sk_delete_ptr(ossl_check_ASN1_UTF8STRING_sk_type(sk), ossl_check_ASN1_UTF8STRING_type(ptr)))
770 #define sk_ASN1_UTF8STRING_push(sk, ptr) OPENSSL_sk_push(ossl_check_ASN1_UTF8STRING_sk_type(sk), ossl_check_ASN1_UTF8STRING_type(ptr))
771 #define sk_ASN1_UTF8STRING_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_ASN1_UTF8STRING_sk_type(sk), ossl_check_ASN1_UTF8STRING_type(ptr))
772 #define sk_ASN1_UTF8STRING_pop(sk) ((ASN1_UTF8STRING *)OPENSSL_sk_pop(ossl_check_ASN1_UTF8STRING_sk_type(sk)))
773 #define sk_ASN1_UTF8STRING_shift(sk) ((ASN1_UTF8STRING *)OPENSSL_sk_shift(ossl_check_ASN1_UTF8STRING_sk_type(sk)))
774 #define sk_ASN1_UTF8STRING_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_ASN1_UTF8STRING_sk_type(sk),ossl_check_ASN1_UTF8STRING_freefunc_type(freefunc))
775 #define sk_ASN1_UTF8STRING_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_ASN1_UTF8STRING_sk_type(sk), ossl_check_ASN1_UTF8STRING_type(ptr), (idx))
776 #define sk_ASN1_UTF8STRING_set(sk, idx, ptr) ((ASN1_UTF8STRING *)OPENSSL_sk_set(ossl_check_ASN1_UTF8STRING_sk_type(sk), (idx), ossl_check_ASN1_UTF8STRING_type(ptr)))
777 #define sk_ASN1_UTF8STRING_find(sk, ptr) OPENSSL_sk_find(ossl_check_ASN1_UTF8STRING_sk_type(sk), ossl_check_ASN1_UTF8STRING_type(ptr))
778 #define sk_ASN1_UTF8STRING_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_ASN1_UTF8STRING_sk_type(sk), ossl_check_ASN1_UTF8STRING_type(ptr))
779 #define sk_ASN1_UTF8STRING_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_ASN1_UTF8STRING_sk_type(sk), ossl_check_ASN1_UTF8STRING_type(ptr), pnum)
780 #define sk_ASN1_UTF8STRING_sort(sk) OPENSSL_sk_sort(ossl_check_ASN1_UTF8STRING_sk_type(sk))
781 #define sk_ASN1_UTF8STRING_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_ASN1_UTF8STRING_sk_type(sk))
782 #define sk_ASN1_UTF8STRING_dup(sk) ((STACK_OF(ASN1_UTF8STRING) *)OPENSSL_sk_dup(ossl_check_const_ASN1_UTF8STRING_sk_type(sk)))
783 #define sk_ASN1_UTF8STRING_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(ASN1_UTF8STRING) *)OPENSSL_sk_deep_copy(ossl_check_const_ASN1_UTF8STRING_sk_type(sk), ossl_check_ASN1_UTF8STRING_copyfunc_type(copyfunc), ossl_check_ASN1_UTF8STRING_freefunc_type(freefunc)))
784 #define sk_ASN1_UTF8STRING_set_cmp_func(sk, cmp) ((sk_ASN1_UTF8STRING_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_ASN1_UTF8STRING_sk_type(sk), ossl_check_ASN1_UTF8STRING_compfunc_type(cmp)))
785 
786 
787 DECLARE_ASN1_FUNCTIONS(ASN1_VISIBLESTRING)
788 DECLARE_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING)
789 DECLARE_ASN1_FUNCTIONS(ASN1_UTF8STRING)
790 DECLARE_ASN1_FUNCTIONS(ASN1_NULL)
791 DECLARE_ASN1_FUNCTIONS(ASN1_BMPSTRING)
792 
793 int UTF8_getc(const unsigned char *str, int len, unsigned long *val);
794 int UTF8_putc(unsigned char *str, int len, unsigned long value);
795 
796 SKM_DEFINE_STACK_OF_INTERNAL(ASN1_GENERALSTRING, ASN1_GENERALSTRING, ASN1_GENERALSTRING)
797 #define sk_ASN1_GENERALSTRING_num(sk) OPENSSL_sk_num(ossl_check_const_ASN1_GENERALSTRING_sk_type(sk))
798 #define sk_ASN1_GENERALSTRING_value(sk, idx) ((ASN1_GENERALSTRING *)OPENSSL_sk_value(ossl_check_const_ASN1_GENERALSTRING_sk_type(sk), (idx)))
799 #define sk_ASN1_GENERALSTRING_new(cmp) ((STACK_OF(ASN1_GENERALSTRING) *)OPENSSL_sk_new(ossl_check_ASN1_GENERALSTRING_compfunc_type(cmp)))
800 #define sk_ASN1_GENERALSTRING_new_null() ((STACK_OF(ASN1_GENERALSTRING) *)OPENSSL_sk_new_null())
801 #define sk_ASN1_GENERALSTRING_new_reserve(cmp, n) ((STACK_OF(ASN1_GENERALSTRING) *)OPENSSL_sk_new_reserve(ossl_check_ASN1_GENERALSTRING_compfunc_type(cmp), (n)))
802 #define sk_ASN1_GENERALSTRING_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_ASN1_GENERALSTRING_sk_type(sk), (n))
803 #define sk_ASN1_GENERALSTRING_free(sk) OPENSSL_sk_free(ossl_check_ASN1_GENERALSTRING_sk_type(sk))
804 #define sk_ASN1_GENERALSTRING_zero(sk) OPENSSL_sk_zero(ossl_check_ASN1_GENERALSTRING_sk_type(sk))
805 #define sk_ASN1_GENERALSTRING_delete(sk, i) ((ASN1_GENERALSTRING *)OPENSSL_sk_delete(ossl_check_ASN1_GENERALSTRING_sk_type(sk), (i)))
806 #define sk_ASN1_GENERALSTRING_delete_ptr(sk, ptr) ((ASN1_GENERALSTRING *)OPENSSL_sk_delete_ptr(ossl_check_ASN1_GENERALSTRING_sk_type(sk), ossl_check_ASN1_GENERALSTRING_type(ptr)))
807 #define sk_ASN1_GENERALSTRING_push(sk, ptr) OPENSSL_sk_push(ossl_check_ASN1_GENERALSTRING_sk_type(sk), ossl_check_ASN1_GENERALSTRING_type(ptr))
808 #define sk_ASN1_GENERALSTRING_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_ASN1_GENERALSTRING_sk_type(sk), ossl_check_ASN1_GENERALSTRING_type(ptr))
809 #define sk_ASN1_GENERALSTRING_pop(sk) ((ASN1_GENERALSTRING *)OPENSSL_sk_pop(ossl_check_ASN1_GENERALSTRING_sk_type(sk)))
810 #define sk_ASN1_GENERALSTRING_shift(sk) ((ASN1_GENERALSTRING *)OPENSSL_sk_shift(ossl_check_ASN1_GENERALSTRING_sk_type(sk)))
811 #define sk_ASN1_GENERALSTRING_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_ASN1_GENERALSTRING_sk_type(sk),ossl_check_ASN1_GENERALSTRING_freefunc_type(freefunc))
812 #define sk_ASN1_GENERALSTRING_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_ASN1_GENERALSTRING_sk_type(sk), ossl_check_ASN1_GENERALSTRING_type(ptr), (idx))
813 #define sk_ASN1_GENERALSTRING_set(sk, idx, ptr) ((ASN1_GENERALSTRING *)OPENSSL_sk_set(ossl_check_ASN1_GENERALSTRING_sk_type(sk), (idx), ossl_check_ASN1_GENERALSTRING_type(ptr)))
814 #define sk_ASN1_GENERALSTRING_find(sk, ptr) OPENSSL_sk_find(ossl_check_ASN1_GENERALSTRING_sk_type(sk), ossl_check_ASN1_GENERALSTRING_type(ptr))
815 #define sk_ASN1_GENERALSTRING_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_ASN1_GENERALSTRING_sk_type(sk), ossl_check_ASN1_GENERALSTRING_type(ptr))
816 #define sk_ASN1_GENERALSTRING_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_ASN1_GENERALSTRING_sk_type(sk), ossl_check_ASN1_GENERALSTRING_type(ptr), pnum)
817 #define sk_ASN1_GENERALSTRING_sort(sk) OPENSSL_sk_sort(ossl_check_ASN1_GENERALSTRING_sk_type(sk))
818 #define sk_ASN1_GENERALSTRING_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_ASN1_GENERALSTRING_sk_type(sk))
819 #define sk_ASN1_GENERALSTRING_dup(sk) ((STACK_OF(ASN1_GENERALSTRING) *)OPENSSL_sk_dup(ossl_check_const_ASN1_GENERALSTRING_sk_type(sk)))
820 #define sk_ASN1_GENERALSTRING_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(ASN1_GENERALSTRING) *)OPENSSL_sk_deep_copy(ossl_check_const_ASN1_GENERALSTRING_sk_type(sk), ossl_check_ASN1_GENERALSTRING_copyfunc_type(copyfunc), ossl_check_ASN1_GENERALSTRING_freefunc_type(freefunc)))
821 #define sk_ASN1_GENERALSTRING_set_cmp_func(sk, cmp) ((sk_ASN1_GENERALSTRING_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_ASN1_GENERALSTRING_sk_type(sk), ossl_check_ASN1_GENERALSTRING_compfunc_type(cmp)))
822 
823 
824 DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE)
825 
826 DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING)
827 DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT)
828 DECLARE_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING)
829 DECLARE_ASN1_FUNCTIONS(ASN1_T61STRING)
830 DECLARE_ASN1_FUNCTIONS(ASN1_IA5STRING)
831 DECLARE_ASN1_FUNCTIONS(ASN1_GENERALSTRING)
832 DECLARE_ASN1_FUNCTIONS(ASN1_UTCTIME)
833 DECLARE_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME)
834 DECLARE_ASN1_FUNCTIONS(ASN1_TIME)
835 
836 DECLARE_ASN1_DUP_FUNCTION(ASN1_TIME)
837 DECLARE_ASN1_DUP_FUNCTION(ASN1_UTCTIME)
838 DECLARE_ASN1_DUP_FUNCTION(ASN1_GENERALIZEDTIME)
839 
840 DECLARE_ASN1_ITEM(ASN1_OCTET_STRING_NDEF)
841 
842 ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t);
843 ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t,
844                          int offset_day, long offset_sec);
845 int ASN1_TIME_check(const ASN1_TIME *t);
846 ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(const ASN1_TIME *t,
847                                                    ASN1_GENERALIZEDTIME **out);
848 int ASN1_TIME_set_string(ASN1_TIME *s, const char *str);
849 int ASN1_TIME_set_string_X509(ASN1_TIME *s, const char *str);
850 int ASN1_TIME_to_tm(const ASN1_TIME *s, struct tm *tm);
851 int ASN1_TIME_normalize(ASN1_TIME *s);
852 int ASN1_TIME_cmp_time_t(const ASN1_TIME *s, time_t t);
853 int ASN1_TIME_compare(const ASN1_TIME *a, const ASN1_TIME *b);
854 
855 int i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a);
856 int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size);
857 int i2a_ASN1_ENUMERATED(BIO *bp, const ASN1_ENUMERATED *a);
858 int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size);
859 int i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *a);
860 int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size);
861 int i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *a, int type);
862 int i2t_ASN1_OBJECT(char *buf, int buf_len, const ASN1_OBJECT *a);
863 
864 int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num);
865 ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len,
866                                 const char *sn, const char *ln);
867 
868 int ASN1_INTEGER_get_int64(int64_t *pr, const ASN1_INTEGER *a);
869 int ASN1_INTEGER_set_int64(ASN1_INTEGER *a, int64_t r);
870 int ASN1_INTEGER_get_uint64(uint64_t *pr, const ASN1_INTEGER *a);
871 int ASN1_INTEGER_set_uint64(ASN1_INTEGER *a, uint64_t r);
872 
873 int ASN1_INTEGER_set(ASN1_INTEGER *a, long v);
874 long ASN1_INTEGER_get(const ASN1_INTEGER *a);
875 ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai);
876 BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn);
877 
878 int ASN1_ENUMERATED_get_int64(int64_t *pr, const ASN1_ENUMERATED *a);
879 int ASN1_ENUMERATED_set_int64(ASN1_ENUMERATED *a, int64_t r);
880 
881 
882 int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v);
883 long ASN1_ENUMERATED_get(const ASN1_ENUMERATED *a);
884 ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(const BIGNUM *bn, ASN1_ENUMERATED *ai);
885 BIGNUM *ASN1_ENUMERATED_to_BN(const ASN1_ENUMERATED *ai, BIGNUM *bn);
886 
887 /* General */
888 /* given a string, return the correct type, max is the maximum length */
889 int ASN1_PRINTABLE_type(const unsigned char *s, int max);
890 
891 unsigned long ASN1_tag2bit(int tag);
892 
893 /* SPECIALS */
894 int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,
895                     int *pclass, long omax);
896 int ASN1_check_infinite_end(unsigned char **p, long len);
897 int ASN1_const_check_infinite_end(const unsigned char **p, long len);
898 void ASN1_put_object(unsigned char **pp, int constructed, int length,
899                      int tag, int xclass);
900 int ASN1_put_eoc(unsigned char **pp);
901 int ASN1_object_size(int constructed, int length, int tag);
902 
903 /* Used to implement other functions */
904 void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, const void *x);
905 
906 # define ASN1_dup_of(type,i2d,d2i,x) \
907     ((type*)ASN1_dup(CHECKED_I2D_OF(type, i2d), \
908                      CHECKED_D2I_OF(type, d2i), \
909                      CHECKED_PTR_OF(const type, x)))
910 
911 void *ASN1_item_dup(const ASN1_ITEM *it, const void *x);
912 int ASN1_item_sign_ex(const ASN1_ITEM *it, X509_ALGOR *algor1,
913                       X509_ALGOR *algor2, ASN1_BIT_STRING *signature,
914                       const void *data, const ASN1_OCTET_STRING *id,
915                       EVP_PKEY *pkey, const EVP_MD *md, OSSL_LIB_CTX *libctx,
916                       const char *propq);
917 int ASN1_item_verify_ex(const ASN1_ITEM *it, const X509_ALGOR *alg,
918                         const ASN1_BIT_STRING *signature, const void *data,
919                         const ASN1_OCTET_STRING *id, EVP_PKEY *pkey,
920                         OSSL_LIB_CTX *libctx, const char *propq);
921 
922 /* ASN1 alloc/free macros for when a type is only used internally */
923 
924 # define M_ASN1_new_of(type) (type *)ASN1_item_new(ASN1_ITEM_rptr(type))
925 # define M_ASN1_free_of(x, type) \
926                 ASN1_item_free(CHECKED_PTR_OF(type, x), ASN1_ITEM_rptr(type))
927 
928 # ifndef OPENSSL_NO_STDIO
929 void *ASN1_d2i_fp(void *(*xnew) (void), d2i_of_void *d2i, FILE *in, void **x);
930 
931 #  define ASN1_d2i_fp_of(type,xnew,d2i,in,x) \
932     ((type*)ASN1_d2i_fp(CHECKED_NEW_OF(type, xnew), \
933                         CHECKED_D2I_OF(type, d2i), \
934                         in, \
935                         CHECKED_PPTR_OF(type, x)))
936 
937 void *ASN1_item_d2i_fp_ex(const ASN1_ITEM *it, FILE *in, void *x,
938                           OSSL_LIB_CTX *libctx, const char *propq);
939 void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x);
940 int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, const void *x);
941 
942 #  define ASN1_i2d_fp_of(type,i2d,out,x) \
943     (ASN1_i2d_fp(CHECKED_I2D_OF(type, i2d), \
944                  out, \
945                  CHECKED_PTR_OF(const type, x)))
946 
947 int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, const void *x);
948 int ASN1_STRING_print_ex_fp(FILE *fp, const ASN1_STRING *str, unsigned long flags);
949 # endif
950 
951 int ASN1_STRING_to_UTF8(unsigned char **out, const ASN1_STRING *in);
952 
953 void *ASN1_d2i_bio(void *(*xnew) (void), d2i_of_void *d2i, BIO *in, void **x);
954 
955 #  define ASN1_d2i_bio_of(type,xnew,d2i,in,x) \
956     ((type*)ASN1_d2i_bio( CHECKED_NEW_OF(type, xnew), \
957                           CHECKED_D2I_OF(type, d2i), \
958                           in, \
959                           CHECKED_PPTR_OF(type, x)))
960 
961 void *ASN1_item_d2i_bio_ex(const ASN1_ITEM *it, BIO *in, void *pval,
962                            OSSL_LIB_CTX *libctx, const char *propq);
963 void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *pval);
964 int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, const void *x);
965 
966 #  define ASN1_i2d_bio_of(type,i2d,out,x) \
967     (ASN1_i2d_bio(CHECKED_I2D_OF(type, i2d), \
968                   out, \
969                   CHECKED_PTR_OF(const type, x)))
970 
971 int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, const void *x);
972 BIO *ASN1_item_i2d_mem_bio(const ASN1_ITEM *it, const ASN1_VALUE *val);
973 int ASN1_UTCTIME_print(BIO *fp, const ASN1_UTCTIME *a);
974 int ASN1_GENERALIZEDTIME_print(BIO *fp, const ASN1_GENERALIZEDTIME *a);
975 int ASN1_TIME_print(BIO *bp, const ASN1_TIME *tm);
976 int ASN1_TIME_print_ex(BIO *bp, const ASN1_TIME *tm, unsigned long flags);
977 int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v);
978 int ASN1_STRING_print_ex(BIO *out, const ASN1_STRING *str, unsigned long flags);
979 int ASN1_buf_print(BIO *bp, const unsigned char *buf, size_t buflen, int off);
980 int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num,
981                   unsigned char *buf, int off);
982 int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent);
983 int ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent,
984                     int dump);
985 const char *ASN1_tag2str(int tag);
986 
987 /* Used to load and write Netscape format cert */
988 
989 int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s);
990 
991 int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len);
992 int ASN1_TYPE_get_octetstring(const ASN1_TYPE *a, unsigned char *data, int max_len);
993 int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num,
994                                   unsigned char *data, int len);
995 int ASN1_TYPE_get_int_octetstring(const ASN1_TYPE *a, long *num,
996                                   unsigned char *data, int max_len);
997 
998 void *ASN1_item_unpack(const ASN1_STRING *oct, const ASN1_ITEM *it);
999 
1000 ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it,
1001                             ASN1_OCTET_STRING **oct);
1002 
1003 void ASN1_STRING_set_default_mask(unsigned long mask);
1004 int ASN1_STRING_set_default_mask_asc(const char *p);
1005 unsigned long ASN1_STRING_get_default_mask(void);
1006 int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len,
1007                        int inform, unsigned long mask);
1008 int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
1009                         int inform, unsigned long mask,
1010                         long minsize, long maxsize);
1011 
1012 ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out,
1013                                     const unsigned char *in, int inlen,
1014                                     int inform, int nid);
1015 ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid);
1016 int ASN1_STRING_TABLE_add(int, long, long, unsigned long, unsigned long);
1017 void ASN1_STRING_TABLE_cleanup(void);
1018 
1019 /* ASN1 template functions */
1020 
1021 /* Old API compatible functions */
1022 ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it);
1023 ASN1_VALUE *ASN1_item_new_ex(const ASN1_ITEM *it, OSSL_LIB_CTX *libctx,
1024                              const char *propq);
1025 void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it);
1026 ASN1_VALUE *ASN1_item_d2i_ex(ASN1_VALUE **val, const unsigned char **in,
1027                              long len, const ASN1_ITEM *it,
1028                              OSSL_LIB_CTX *libctx, const char *propq);
1029 ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **val, const unsigned char **in,
1030                           long len, const ASN1_ITEM *it);
1031 int ASN1_item_i2d(const ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it);
1032 int ASN1_item_ndef_i2d(const ASN1_VALUE *val, unsigned char **out,
1033                        const ASN1_ITEM *it);
1034 
1035 void ASN1_add_oid_module(void);
1036 void ASN1_add_stable_module(void);
1037 
1038 ASN1_TYPE *ASN1_generate_nconf(const char *str, CONF *nconf);
1039 ASN1_TYPE *ASN1_generate_v3(const char *str, X509V3_CTX *cnf);
1040 int ASN1_str2mask(const char *str, unsigned long *pmask);
1041 
1042 /* ASN1 Print flags */
1043 
1044 /* Indicate missing OPTIONAL fields */
1045 # define ASN1_PCTX_FLAGS_SHOW_ABSENT             0x001
1046 /* Mark start and end of SEQUENCE */
1047 # define ASN1_PCTX_FLAGS_SHOW_SEQUENCE           0x002
1048 /* Mark start and end of SEQUENCE/SET OF */
1049 # define ASN1_PCTX_FLAGS_SHOW_SSOF               0x004
1050 /* Show the ASN1 type of primitives */
1051 # define ASN1_PCTX_FLAGS_SHOW_TYPE               0x008
1052 /* Don't show ASN1 type of ANY */
1053 # define ASN1_PCTX_FLAGS_NO_ANY_TYPE             0x010
1054 /* Don't show ASN1 type of MSTRINGs */
1055 # define ASN1_PCTX_FLAGS_NO_MSTRING_TYPE         0x020
1056 /* Don't show field names in SEQUENCE */
1057 # define ASN1_PCTX_FLAGS_NO_FIELD_NAME           0x040
1058 /* Show structure names of each SEQUENCE field */
1059 # define ASN1_PCTX_FLAGS_SHOW_FIELD_STRUCT_NAME  0x080
1060 /* Don't show structure name even at top level */
1061 # define ASN1_PCTX_FLAGS_NO_STRUCT_NAME          0x100
1062 
1063 int ASN1_item_print(BIO *out, const ASN1_VALUE *ifld, int indent,
1064                     const ASN1_ITEM *it, const ASN1_PCTX *pctx);
1065 ASN1_PCTX *ASN1_PCTX_new(void);
1066 void ASN1_PCTX_free(ASN1_PCTX *p);
1067 unsigned long ASN1_PCTX_get_flags(const ASN1_PCTX *p);
1068 void ASN1_PCTX_set_flags(ASN1_PCTX *p, unsigned long flags);
1069 unsigned long ASN1_PCTX_get_nm_flags(const ASN1_PCTX *p);
1070 void ASN1_PCTX_set_nm_flags(ASN1_PCTX *p, unsigned long flags);
1071 unsigned long ASN1_PCTX_get_cert_flags(const ASN1_PCTX *p);
1072 void ASN1_PCTX_set_cert_flags(ASN1_PCTX *p, unsigned long flags);
1073 unsigned long ASN1_PCTX_get_oid_flags(const ASN1_PCTX *p);
1074 void ASN1_PCTX_set_oid_flags(ASN1_PCTX *p, unsigned long flags);
1075 unsigned long ASN1_PCTX_get_str_flags(const ASN1_PCTX *p);
1076 void ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags);
1077 
1078 ASN1_SCTX *ASN1_SCTX_new(int (*scan_cb) (ASN1_SCTX *ctx));
1079 void ASN1_SCTX_free(ASN1_SCTX *p);
1080 const ASN1_ITEM *ASN1_SCTX_get_item(ASN1_SCTX *p);
1081 const ASN1_TEMPLATE *ASN1_SCTX_get_template(ASN1_SCTX *p);
1082 unsigned long ASN1_SCTX_get_flags(ASN1_SCTX *p);
1083 void ASN1_SCTX_set_app_data(ASN1_SCTX *p, void *data);
1084 void *ASN1_SCTX_get_app_data(ASN1_SCTX *p);
1085 
1086 const BIO_METHOD *BIO_f_asn1(void);
1087 
1088 /* cannot constify val because of CMS_stream() */
1089 BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it);
1090 
1091 int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
1092                         const ASN1_ITEM *it);
1093 int PEM_write_bio_ASN1_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
1094                               const char *hdr, const ASN1_ITEM *it);
1095 /* cannot constify val because of CMS_dataFinal() */
1096 int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
1097                      int ctype_nid, int econt_nid,
1098                      STACK_OF(X509_ALGOR) *mdalgs, const ASN1_ITEM *it);
1099 int SMIME_write_ASN1_ex(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
1100                         int ctype_nid, int econt_nid,
1101                         STACK_OF(X509_ALGOR) *mdalgs, const ASN1_ITEM *it,
1102                         OSSL_LIB_CTX *libctx, const char *propq);
1103 ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it);
1104 ASN1_VALUE *SMIME_read_ASN1_ex(BIO *bio, int flags, BIO **bcont,
1105                                const ASN1_ITEM *it, ASN1_VALUE **x,
1106                                OSSL_LIB_CTX *libctx, const char *propq);
1107 int SMIME_crlf_copy(BIO *in, BIO *out, int flags);
1108 int SMIME_text(BIO *in, BIO *out);
1109 
1110 const ASN1_ITEM *ASN1_ITEM_lookup(const char *name);
1111 const ASN1_ITEM *ASN1_ITEM_get(size_t i);
1112 
1113 /* Legacy compatibility */
1114 # define DECLARE_ASN1_FUNCTIONS_fname(type, itname, name) \
1115          DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \
1116          DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name)
1117 # define DECLARE_ASN1_FUNCTIONS_const(type) DECLARE_ASN1_FUNCTIONS(type)
1118 # define DECLARE_ASN1_ENCODE_FUNCTIONS_const(type, name) \
1119          DECLARE_ASN1_ENCODE_FUNCTIONS(type, name)
1120 # define I2D_OF_const(type) I2D_OF(type)
1121 # define ASN1_dup_of_const(type,i2d,d2i,x) ASN1_dup_of(type,i2d,d2i,x)
1122 # define ASN1_i2d_fp_of_const(type,i2d,out,x) ASN1_i2d_fp_of(type,i2d,out,x)
1123 # define ASN1_i2d_bio_of_const(type,i2d,out,x) ASN1_i2d_bio_of(type,i2d,out,x)
1124 
1125 # ifdef  __cplusplus
1126 }
1127 # endif
1128 #endif
1129