155714Skris/* crypto/asn1/asn1.h */
255714Skris/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
355714Skris * All rights reserved.
455714Skris *
555714Skris * This package is an SSL implementation written
655714Skris * by Eric Young (eay@cryptsoft.com).
755714Skris * The implementation was written so as to conform with Netscapes SSL.
8280297Sjkim *
955714Skris * This library is free for commercial and non-commercial use as long as
1055714Skris * the following conditions are aheared to.  The following conditions
1155714Skris * apply to all code found in this distribution, be it the RC4, RSA,
1255714Skris * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
1355714Skris * included with this distribution is covered by the same copyright terms
1455714Skris * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15280297Sjkim *
1655714Skris * Copyright remains Eric Young's, and as such any Copyright notices in
1755714Skris * the code are not to be removed.
1855714Skris * If this package is used in a product, Eric Young should be given attribution
1955714Skris * as the author of the parts of the library used.
2055714Skris * This can be in the form of a textual message at program startup or
2155714Skris * in documentation (online or textual) provided with the package.
22280297Sjkim *
2355714Skris * Redistribution and use in source and binary forms, with or without
2455714Skris * modification, are permitted provided that the following conditions
2555714Skris * are met:
2655714Skris * 1. Redistributions of source code must retain the copyright
2755714Skris *    notice, this list of conditions and the following disclaimer.
2855714Skris * 2. Redistributions in binary form must reproduce the above copyright
2955714Skris *    notice, this list of conditions and the following disclaimer in the
3055714Skris *    documentation and/or other materials provided with the distribution.
3155714Skris * 3. All advertising materials mentioning features or use of this software
3255714Skris *    must display the following acknowledgement:
3355714Skris *    "This product includes cryptographic software written by
3455714Skris *     Eric Young (eay@cryptsoft.com)"
3555714Skris *    The word 'cryptographic' can be left out if the rouines from the library
3655714Skris *    being used are not cryptographic related :-).
37280297Sjkim * 4. If you include any Windows specific code (or a derivative thereof) from
3855714Skris *    the apps directory (application code) you must include an acknowledgement:
3955714Skris *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40280297Sjkim *
4155714Skris * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
4255714Skris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4355714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4455714Skris * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
4555714Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
4655714Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
4755714Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4855714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4955714Skris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5055714Skris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5155714Skris * SUCH DAMAGE.
52280297Sjkim *
5355714Skris * The licence and distribution terms for any publically available version or
5455714Skris * derivative of this code cannot be changed.  i.e. this code cannot simply be
5555714Skris * copied and put under another distribution licence
5655714Skris * [including the GNU Public Licence.]
5755714Skris */
5855714Skris
5955714Skris#ifndef HEADER_ASN1_H
60280297Sjkim# define HEADER_ASN1_H
6155714Skris
62280297Sjkim# include <time.h>
63280297Sjkim# include <openssl/e_os2.h>
64280297Sjkim# ifndef OPENSSL_NO_BIO
65280297Sjkim#  include <openssl/bio.h>
66280297Sjkim# endif
67280297Sjkim# include <openssl/stack.h>
68280297Sjkim# include <openssl/safestack.h>
6955714Skris
70280297Sjkim# include <openssl/symhacks.h>
7168651Skris
72280297Sjkim# include <openssl/ossl_typ.h>
73280297Sjkim# ifndef OPENSSL_NO_DEPRECATED
74280297Sjkim#  include <openssl/bn.h>
75280297Sjkim# endif
76109998Smarkm
77280297Sjkim# ifdef OPENSSL_BUILD_SHLIBCRYPTO
78280297Sjkim#  undef OPENSSL_EXTERN
79280297Sjkim#  define OPENSSL_EXTERN OPENSSL_EXPORT
80280297Sjkim# endif
81109998Smarkm
8268651Skris#ifdef  __cplusplus
8368651Skrisextern "C" {
8459191Skris#endif
8559191Skris
86280297Sjkim# define V_ASN1_UNIVERSAL                0x00
87280297Sjkim# define V_ASN1_APPLICATION              0x40
88280297Sjkim# define V_ASN1_CONTEXT_SPECIFIC         0x80
89280297Sjkim# define V_ASN1_PRIVATE                  0xc0
9055714Skris
91280297Sjkim# define V_ASN1_CONSTRUCTED              0x20
92280297Sjkim# define V_ASN1_PRIMITIVE_TAG            0x1f
93280297Sjkim# define V_ASN1_PRIMATIVE_TAG            0x1f
9455714Skris
95280297Sjkim# define V_ASN1_APP_CHOOSE               -2/* let the recipient choose */
96280297Sjkim# define V_ASN1_OTHER                    -3/* used in ASN1_TYPE */
97280297Sjkim# define V_ASN1_ANY                      -4/* used in ASN1 template code */
9855714Skris
99280297Sjkim# define V_ASN1_NEG                      0x100/* negative flag */
10068651Skris
101280297Sjkim# define V_ASN1_UNDEF                    -1
102280297Sjkim# define V_ASN1_EOC                      0
103280297Sjkim# define V_ASN1_BOOLEAN                  1 /**/
104280297Sjkim# define V_ASN1_INTEGER                  2
105280297Sjkim# define V_ASN1_NEG_INTEGER              (2 | V_ASN1_NEG)
106280297Sjkim# define V_ASN1_BIT_STRING               3
107280297Sjkim# define V_ASN1_OCTET_STRING             4
108280297Sjkim# define V_ASN1_NULL                     5
109280297Sjkim# define V_ASN1_OBJECT                   6
110280297Sjkim# define V_ASN1_OBJECT_DESCRIPTOR        7
111280297Sjkim# define V_ASN1_EXTERNAL                 8
112280297Sjkim# define V_ASN1_REAL                     9
113280297Sjkim# define V_ASN1_ENUMERATED               10
114280297Sjkim# define V_ASN1_NEG_ENUMERATED           (10 | V_ASN1_NEG)
115280297Sjkim# define V_ASN1_UTF8STRING               12
116280297Sjkim# define V_ASN1_SEQUENCE                 16
117280297Sjkim# define V_ASN1_SET                      17
118280297Sjkim# define V_ASN1_NUMERICSTRING            18 /**/
119280297Sjkim# define V_ASN1_PRINTABLESTRING          19
120280297Sjkim# define V_ASN1_T61STRING                20
121280297Sjkim# define V_ASN1_TELETEXSTRING            20/* alias */
122280297Sjkim# define V_ASN1_VIDEOTEXSTRING           21 /**/
123280297Sjkim# define V_ASN1_IA5STRING                22
124280297Sjkim# define V_ASN1_UTCTIME                  23
125280297Sjkim# define V_ASN1_GENERALIZEDTIME          24 /**/
126280297Sjkim# define V_ASN1_GRAPHICSTRING            25 /**/
127280297Sjkim# define V_ASN1_ISO64STRING              26 /**/
128280297Sjkim# define V_ASN1_VISIBLESTRING            26/* alias */
129280297Sjkim# define V_ASN1_GENERALSTRING            27 /**/
130280297Sjkim# define V_ASN1_UNIVERSALSTRING          28 /**/
131280297Sjkim# define V_ASN1_BMPSTRING                30
13255714Skris/* For use with d2i_ASN1_type_bytes() */
133280297Sjkim# define B_ASN1_NUMERICSTRING    0x0001
134280297Sjkim# define B_ASN1_PRINTABLESTRING  0x0002
135280297Sjkim# define B_ASN1_T61STRING        0x0004
136280297Sjkim# define B_ASN1_TELETEXSTRING    0x0004
137280297Sjkim# define B_ASN1_VIDEOTEXSTRING   0x0008
138280297Sjkim# define B_ASN1_IA5STRING        0x0010
139280297Sjkim# define B_ASN1_GRAPHICSTRING    0x0020
140280297Sjkim# define B_ASN1_ISO64STRING      0x0040
141280297Sjkim# define B_ASN1_VISIBLESTRING    0x0040
142280297Sjkim# define B_ASN1_GENERALSTRING    0x0080
143280297Sjkim# define B_ASN1_UNIVERSALSTRING  0x0100
144280297Sjkim# define B_ASN1_OCTET_STRING     0x0200
145280297Sjkim# define B_ASN1_BIT_STRING       0x0400
146280297Sjkim# define B_ASN1_BMPSTRING        0x0800
147280297Sjkim# define B_ASN1_UNKNOWN          0x1000
148280297Sjkim# define B_ASN1_UTF8STRING       0x2000
149280297Sjkim# define B_ASN1_UTCTIME          0x4000
150280297Sjkim# define B_ASN1_GENERALIZEDTIME  0x8000
151280297Sjkim# define B_ASN1_SEQUENCE         0x10000
15259191Skris/* For use with ASN1_mbstring_copy() */
153280297Sjkim# define MBSTRING_FLAG           0x1000
154280297Sjkim# define MBSTRING_UTF8           (MBSTRING_FLAG)
155280297Sjkim# define MBSTRING_ASC            (MBSTRING_FLAG|1)
156280297Sjkim# define MBSTRING_BMP            (MBSTRING_FLAG|2)
157280297Sjkim# define MBSTRING_UNIV           (MBSTRING_FLAG|4)
158280297Sjkim# define SMIME_OLDMIME           0x400
159280297Sjkim# define SMIME_CRLFEOL           0x800
160280297Sjkim# define SMIME_STREAM            0x1000
161280297Sjkim    struct X509_algor_st;
162194206SsimonDECLARE_STACK_OF(X509_ALGOR)
16355714Skris
164280297Sjkim# define DECLARE_ASN1_SET_OF(type)/* filled in by mkstack.pl */
165280297Sjkim# define IMPLEMENT_ASN1_SET_OF(type)/* nothing, no longer needed */
16655714Skris
167280297Sjkim/*
168280297Sjkim * We MUST make sure that, except for constness, asn1_ctx_st and
169280297Sjkim * asn1_const_ctx are exactly the same.  Fortunately, as soon as the old ASN1
170280297Sjkim * parsing macros are gone, we can throw this away as well...
171280297Sjkim */
172280297Sjkimtypedef struct asn1_ctx_st {
173280297Sjkim    unsigned char *p;           /* work char pointer */
174280297Sjkim    int eos;                    /* end of sequence read for indefinite
175280297Sjkim                                 * encoding */
176280297Sjkim    int error;                  /* error code to use when returning an error */
177280297Sjkim    int inf;                    /* constructed if 0x20, indefinite is 0x21 */
178280297Sjkim    int tag;                    /* tag from last 'get object' */
179280297Sjkim    int xclass;                 /* class from last 'get object' */
180280297Sjkim    long slen;                  /* length of last 'get object' */
181280297Sjkim    unsigned char *max;         /* largest value of p allowed */
182280297Sjkim    unsigned char *q;           /* temporary variable */
183280297Sjkim    unsigned char **pp;         /* variable */
184280297Sjkim    int line;                   /* used in error processing */
185280297Sjkim} ASN1_CTX;
18655714Skris
187280297Sjkimtypedef struct asn1_const_ctx_st {
188280297Sjkim    const unsigned char *p;     /* work char pointer */
189280297Sjkim    int eos;                    /* end of sequence read for indefinite
190280297Sjkim                                 * encoding */
191280297Sjkim    int error;                  /* error code to use when returning an error */
192280297Sjkim    int inf;                    /* constructed if 0x20, indefinite is 0x21 */
193280297Sjkim    int tag;                    /* tag from last 'get object' */
194280297Sjkim    int xclass;                 /* class from last 'get object' */
195280297Sjkim    long slen;                  /* length of last 'get object' */
196280297Sjkim    const unsigned char *max;   /* largest value of p allowed */
197280297Sjkim    const unsigned char *q;     /* temporary variable */
198280297Sjkim    const unsigned char **pp;   /* variable */
199280297Sjkim    int line;                   /* used in error processing */
200280297Sjkim} ASN1_const_CTX;
201160814Ssimon
202280297Sjkim/*
203280297Sjkim * These are used internally in the ASN1_OBJECT to keep track of whether the
204280297Sjkim * names and data need to be free()ed
205280297Sjkim */
206280297Sjkim# define ASN1_OBJECT_FLAG_DYNAMIC         0x01/* internal use */
207280297Sjkim# define ASN1_OBJECT_FLAG_CRITICAL        0x02/* critical x509v3 object id */
208280297Sjkim# define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04/* internal use */
209280297Sjkim# define ASN1_OBJECT_FLAG_DYNAMIC_DATA    0x08/* internal use */
210290207Sjkimstruct asn1_object_st {
211280297Sjkim    const char *sn, *ln;
212280297Sjkim    int nid;
213280297Sjkim    int length;
214280297Sjkim    const unsigned char *data;  /* data remains const after init */
215280297Sjkim    int flags;                  /* Should we free this one */
216290207Sjkim};
21755714Skris
218280297Sjkim# define ASN1_STRING_FLAG_BITS_LEFT 0x08/* Set if 0x07 has bits left value */
219280297Sjkim/*
220280297Sjkim * This indicates that the ASN1_STRING is not a real value but just a place
221280297Sjkim * holder for the location where indefinite length constructed data should be
222280297Sjkim * inserted in the memory buffer
223160814Ssimon */
224280297Sjkim# define ASN1_STRING_FLAG_NDEF 0x010
225194206Ssimon
226280297Sjkim/*
227280297Sjkim * This flag is used by the CMS code to indicate that a string is not
228280297Sjkim * complete and is a place holder for content when it had all been accessed.
229280297Sjkim * The flag will be reset when content has been written to it.
230194206Ssimon */
231238405Sjkim
232280297Sjkim# define ASN1_STRING_FLAG_CONT 0x020
233280297Sjkim/*
234280297Sjkim * This flag is used by ASN1 code to indicate an ASN1_STRING is an MSTRING
235238405Sjkim * type.
236238405Sjkim */
237280297Sjkim# define ASN1_STRING_FLAG_MSTRING 0x040
23855714Skris/* This is the base type that holds just about everything :-) */
239280297Sjkimstruct asn1_string_st {
240280297Sjkim    int length;
241280297Sjkim    int type;
242280297Sjkim    unsigned char *data;
243280297Sjkim    /*
244280297Sjkim     * The value of the following field depends on the type being held.  It
245280297Sjkim     * is mostly being used for BIT_STRING so if the input data has a
246280297Sjkim     * non-zero 'unused bits' value, it will be handled correctly
247280297Sjkim     */
248280297Sjkim    long flags;
249280297Sjkim};
25055714Skris
251280297Sjkim/*
252280297Sjkim * ASN1_ENCODING structure: this is used to save the received encoding of an
253280297Sjkim * ASN1 type. This is useful to get round problems with invalid encodings
254280297Sjkim * which can break signatures.
255109998Smarkm */
256109998Smarkm
257280297Sjkimtypedef struct ASN1_ENCODING_st {
258280297Sjkim    unsigned char *enc;         /* DER encoding */
259280297Sjkim    long len;                   /* Length of encoding */
260280297Sjkim    int modified;               /* set to 1 if 'enc' is invalid */
261280297Sjkim} ASN1_ENCODING;
262109998Smarkm
263109998Smarkm/* Used with ASN1 LONG type: if a long is set to this it is omitted */
264280297Sjkim# define ASN1_LONG_UNDEF 0x7fffffffL
265109998Smarkm
266280297Sjkim# define STABLE_FLAGS_MALLOC     0x01
267280297Sjkim# define STABLE_NO_MASK          0x02
268280297Sjkim# define DIRSTRING_TYPE  \
26959191Skris (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_BMPSTRING|B_ASN1_UTF8STRING)
270280297Sjkim# define PKCS9STRING_TYPE (DIRSTRING_TYPE|B_ASN1_IA5STRING)
27159191Skris
27259191Skristypedef struct asn1_string_table_st {
273280297Sjkim    int nid;
274280297Sjkim    long minsize;
275280297Sjkim    long maxsize;
276280297Sjkim    unsigned long mask;
277280297Sjkim    unsigned long flags;
27859191Skris} ASN1_STRING_TABLE;
27959191Skris
28059191SkrisDECLARE_STACK_OF(ASN1_STRING_TABLE)
28159191Skris
28259191Skris/* size limits: this stuff is taken straight from RFC2459 */
28359191Skris
284280297Sjkim# define ub_name                         32768
285280297Sjkim# define ub_common_name                  64
286280297Sjkim# define ub_locality_name                128
287280297Sjkim# define ub_state_name                   128
288280297Sjkim# define ub_organization_name            64
289280297Sjkim# define ub_organization_unit_name       64
290280297Sjkim# define ub_title                        64
291280297Sjkim# define ub_email_address                128
29259191Skris
293280297Sjkim/*
294280297Sjkim * Declarations for template structures: for full definitions see asn1t.h
295109998Smarkm */
296109998Smarkmtypedef struct ASN1_TEMPLATE_st ASN1_TEMPLATE;
297109998Smarkmtypedef struct ASN1_TLC_st ASN1_TLC;
298109998Smarkm/* This is just an opaque pointer */
299109998Smarkmtypedef struct ASN1_VALUE_st ASN1_VALUE;
300109998Smarkm
301109998Smarkm/* Declare ASN1 functions: the implement macro in in asn1t.h */
302109998Smarkm
303280297Sjkim# define DECLARE_ASN1_FUNCTIONS(type) DECLARE_ASN1_FUNCTIONS_name(type, type)
304109998Smarkm
305280297Sjkim# define DECLARE_ASN1_ALLOC_FUNCTIONS(type) \
306280297Sjkim        DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, type)
307160814Ssimon
308280297Sjkim# define DECLARE_ASN1_FUNCTIONS_name(type, name) \
309280297Sjkim        DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \
310280297Sjkim        DECLARE_ASN1_ENCODE_FUNCTIONS(type, name, name)
311109998Smarkm
312280297Sjkim# define DECLARE_ASN1_FUNCTIONS_fname(type, itname, name) \
313280297Sjkim        DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \
314280297Sjkim        DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name)
315109998Smarkm
316280297Sjkim# define DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) \
317280297Sjkim        type *d2i_##name(type **a, const unsigned char **in, long len); \
318280297Sjkim        int i2d_##name(type *a, unsigned char **out); \
319280297Sjkim        DECLARE_ASN1_ITEM(itname)
320109998Smarkm
321280297Sjkim# define DECLARE_ASN1_ENCODE_FUNCTIONS_const(type, name) \
322280297Sjkim        type *d2i_##name(type **a, const unsigned char **in, long len); \
323280297Sjkim        int i2d_##name(const type *a, unsigned char **out); \
324280297Sjkim        DECLARE_ASN1_ITEM(name)
325109998Smarkm
326280297Sjkim# define DECLARE_ASN1_NDEF_FUNCTION(name) \
327280297Sjkim        int i2d_##name##_NDEF(name *a, unsigned char **out);
328160814Ssimon
329280297Sjkim# define DECLARE_ASN1_FUNCTIONS_const(name) \
330280297Sjkim        DECLARE_ASN1_ALLOC_FUNCTIONS(name) \
331280297Sjkim        DECLARE_ASN1_ENCODE_FUNCTIONS_const(name, name)
332109998Smarkm
333280297Sjkim# define DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \
334280297Sjkim        type *name##_new(void); \
335280297Sjkim        void name##_free(type *a);
336109998Smarkm
337280297Sjkim# define DECLARE_ASN1_PRINT_FUNCTION(stname) \
338280297Sjkim        DECLARE_ASN1_PRINT_FUNCTION_fname(stname, stname)
339238405Sjkim
340280297Sjkim# define DECLARE_ASN1_PRINT_FUNCTION_fname(stname, fname) \
341280297Sjkim        int fname##_print_ctx(BIO *out, stname *x, int indent, \
342280297Sjkim                                         const ASN1_PCTX *pctx);
343238405Sjkim
344280297Sjkim# define D2I_OF(type) type *(*)(type **,const unsigned char **,long)
345280297Sjkim# define I2D_OF(type) int (*)(type *,unsigned char **)
346280297Sjkim# define I2D_OF_const(type) int (*)(const type *,unsigned char **)
347160814Ssimon
348280297Sjkim# define CHECKED_D2I_OF(type, d2i) \
349194206Ssimon    ((d2i_of_void*) (1 ? d2i : ((D2I_OF(type))0)))
350280297Sjkim# define CHECKED_I2D_OF(type, i2d) \
351194206Ssimon    ((i2d_of_void*) (1 ? i2d : ((I2D_OF(type))0)))
352280297Sjkim# define CHECKED_NEW_OF(type, xnew) \
353194206Ssimon    ((void *(*)(void)) (1 ? xnew : ((type *(*)(void))0)))
354280297Sjkim# define CHECKED_PTR_OF(type, p) \
355194206Ssimon    ((void*) (1 ? p : (type*)0))
356280297Sjkim# define CHECKED_PPTR_OF(type, p) \
357194206Ssimon    ((void**) (1 ? p : (type**)0))
358194206Ssimon
359280297Sjkim# define TYPEDEF_D2I_OF(type) typedef type *d2i_of_##type(type **,const unsigned char **,long)
360280297Sjkim# define TYPEDEF_I2D_OF(type) typedef int i2d_of_##type(type *,unsigned char **)
361280297Sjkim# define TYPEDEF_D2I2D_OF(type) TYPEDEF_D2I_OF(type); TYPEDEF_I2D_OF(type)
362160814Ssimon
363160814SsimonTYPEDEF_D2I2D_OF(void);
364160814Ssimon
365280297Sjkim/*-
366280297Sjkim * The following macros and typedefs allow an ASN1_ITEM
367109998Smarkm * to be embedded in a structure and referenced. Since
368109998Smarkm * the ASN1_ITEM pointers need to be globally accessible
369109998Smarkm * (possibly from shared libraries) they may exist in
370109998Smarkm * different forms. On platforms that support it the
371109998Smarkm * ASN1_ITEM structure itself will be globally exported.
372109998Smarkm * Other platforms will export a function that returns
373109998Smarkm * an ASN1_ITEM pointer.
374109998Smarkm *
375109998Smarkm * To handle both cases transparently the macros below
376109998Smarkm * should be used instead of hard coding an ASN1_ITEM
377109998Smarkm * pointer in a structure.
378109998Smarkm *
379109998Smarkm * The structure will look like this:
380109998Smarkm *
381109998Smarkm * typedef struct SOMETHING_st {
382109998Smarkm *      ...
383109998Smarkm *      ASN1_ITEM_EXP *iptr;
384109998Smarkm *      ...
385280297Sjkim * } SOMETHING;
386109998Smarkm *
387109998Smarkm * It would be initialised as e.g.:
388109998Smarkm *
389109998Smarkm * SOMETHING somevar = {...,ASN1_ITEM_ref(X509),...};
390109998Smarkm *
391109998Smarkm * and the actual pointer extracted with:
392109998Smarkm *
393109998Smarkm * const ASN1_ITEM *it = ASN1_ITEM_ptr(somevar.iptr);
394109998Smarkm *
395109998Smarkm * Finally an ASN1_ITEM pointer can be extracted from an
396109998Smarkm * appropriate reference with: ASN1_ITEM_rptr(X509). This
397109998Smarkm * would be used when a function takes an ASN1_ITEM * argument.
398109998Smarkm *
399109998Smarkm */
400109998Smarkm
401280297Sjkim# ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
402109998Smarkm
403109998Smarkm/* ASN1_ITEM pointer exported type */
404109998Smarkmtypedef const ASN1_ITEM ASN1_ITEM_EXP;
405109998Smarkm
406109998Smarkm/* Macro to obtain ASN1_ITEM pointer from exported type */
407280297Sjkim#  define ASN1_ITEM_ptr(iptr) (iptr)
408109998Smarkm
409109998Smarkm/* Macro to include ASN1_ITEM pointer from base type */
410280297Sjkim#  define ASN1_ITEM_ref(iptr) (&(iptr##_it))
411109998Smarkm
412280297Sjkim#  define ASN1_ITEM_rptr(ref) (&(ref##_it))
413109998Smarkm
414280297Sjkim#  define DECLARE_ASN1_ITEM(name) \
415280297Sjkim        OPENSSL_EXTERN const ASN1_ITEM name##_it;
416109998Smarkm
417280297Sjkim# else
418109998Smarkm
419280297Sjkim/*
420280297Sjkim * Platforms that can't easily handle shared global variables are declared as
421280297Sjkim * functions returning ASN1_ITEM pointers.
422109998Smarkm */
423109998Smarkm
424109998Smarkm/* ASN1_ITEM pointer exported type */
425280297Sjkimtypedef const ASN1_ITEM *ASN1_ITEM_EXP (void);
426109998Smarkm
427109998Smarkm/* Macro to obtain ASN1_ITEM pointer from exported type */
428280297Sjkim#  define ASN1_ITEM_ptr(iptr) (iptr())
429109998Smarkm
430109998Smarkm/* Macro to include ASN1_ITEM pointer from base type */
431280297Sjkim#  define ASN1_ITEM_ref(iptr) (iptr##_it)
432109998Smarkm
433280297Sjkim#  define ASN1_ITEM_rptr(ref) (ref##_it())
434109998Smarkm
435280297Sjkim#  define DECLARE_ASN1_ITEM(name) \
436280297Sjkim        const ASN1_ITEM * name##_it(void);
437109998Smarkm
438280297Sjkim# endif
43955714Skris
44068651Skris/* Parameters used by ASN1_STRING_print_ex() */
44168651Skris
442280297Sjkim/*
443280297Sjkim * These determine which characters to escape: RFC2253 special characters,
444280297Sjkim * control characters and MSB set characters
44568651Skris */
44668651Skris
447280297Sjkim# define ASN1_STRFLGS_ESC_2253           1
448280297Sjkim# define ASN1_STRFLGS_ESC_CTRL           2
449280297Sjkim# define ASN1_STRFLGS_ESC_MSB            4
45068651Skris
451280297Sjkim/*
452280297Sjkim * This flag determines how we do escaping: normally RC2253 backslash only,
453280297Sjkim * set this to use backslash and quote.
45468651Skris */
45568651Skris
456280297Sjkim# define ASN1_STRFLGS_ESC_QUOTE          8
45768651Skris
45868651Skris/* These three flags are internal use only. */
45968651Skris
46068651Skris/* Character is a valid PrintableString character */
461280297Sjkim# define CHARTYPE_PRINTABLESTRING        0x10
46268651Skris/* Character needs escaping if it is the first character */
463280297Sjkim# define CHARTYPE_FIRST_ESC_2253         0x20
46468651Skris/* Character needs escaping if it is the last character */
465280297Sjkim# define CHARTYPE_LAST_ESC_2253          0x40
46668651Skris
467280297Sjkim/*
468280297Sjkim * NB the internal flags are safely reused below by flags handled at the top
469280297Sjkim * level.
47068651Skris */
47168651Skris
472280297Sjkim/*
473280297Sjkim * If this is set we convert all character strings to UTF8 first
47468651Skris */
47568651Skris
476280297Sjkim# define ASN1_STRFLGS_UTF8_CONVERT       0x10
47768651Skris
478280297Sjkim/*
479280297Sjkim * If this is set we don't attempt to interpret content: just assume all
480280297Sjkim * strings are 1 byte per character. This will produce some pretty odd
481280297Sjkim * looking output!
48268651Skris */
48368651Skris
484280297Sjkim# define ASN1_STRFLGS_IGNORE_TYPE        0x20
48568651Skris
48668651Skris/* If this is set we include the string type in the output */
487280297Sjkim# define ASN1_STRFLGS_SHOW_TYPE          0x40
48868651Skris
489280297Sjkim/*
490280297Sjkim * This determines which strings to display and which to 'dump' (hex dump of
491280297Sjkim * content octets or DER encoding). We can only dump non character strings or
492280297Sjkim * everything. If we don't dump 'unknown' they are interpreted as character
493280297Sjkim * strings with 1 octet per character and are subject to the usual escaping
494280297Sjkim * options.
49568651Skris */
49668651Skris
497280297Sjkim# define ASN1_STRFLGS_DUMP_ALL           0x80
498280297Sjkim# define ASN1_STRFLGS_DUMP_UNKNOWN       0x100
49968651Skris
500280297Sjkim/*
501280297Sjkim * These determine what 'dumping' does, we can dump the content octets or the
502280297Sjkim * DER encoding: both use the RFC2253 #XXXXX notation.
50368651Skris */
50468651Skris
505280297Sjkim# define ASN1_STRFLGS_DUMP_DER           0x200
50668651Skris
507280297Sjkim/*
508280297Sjkim * All the string flags consistent with RFC2253, escaping control characters
509280297Sjkim * isn't essential in RFC2253 but it is advisable anyway.
51068651Skris */
51168651Skris
512280297Sjkim# define ASN1_STRFLGS_RFC2253    (ASN1_STRFLGS_ESC_2253 | \
513280297Sjkim                                ASN1_STRFLGS_ESC_CTRL | \
514280297Sjkim                                ASN1_STRFLGS_ESC_MSB | \
515280297Sjkim                                ASN1_STRFLGS_UTF8_CONVERT | \
516280297Sjkim                                ASN1_STRFLGS_DUMP_UNKNOWN | \
517280297Sjkim                                ASN1_STRFLGS_DUMP_DER)
51868651Skris
51968651SkrisDECLARE_STACK_OF(ASN1_INTEGER)
52068651SkrisDECLARE_ASN1_SET_OF(ASN1_INTEGER)
52168651Skris
522109998SmarkmDECLARE_STACK_OF(ASN1_GENERALSTRING)
523109998Smarkm
524280297Sjkimtypedef struct asn1_type_st {
525280297Sjkim    int type;
526280297Sjkim    union {
527280297Sjkim        char *ptr;
528280297Sjkim        ASN1_BOOLEAN boolean;
529280297Sjkim        ASN1_STRING *asn1_string;
530280297Sjkim        ASN1_OBJECT *object;
531280297Sjkim        ASN1_INTEGER *integer;
532280297Sjkim        ASN1_ENUMERATED *enumerated;
533280297Sjkim        ASN1_BIT_STRING *bit_string;
534280297Sjkim        ASN1_OCTET_STRING *octet_string;
535280297Sjkim        ASN1_PRINTABLESTRING *printablestring;
536280297Sjkim        ASN1_T61STRING *t61string;
537280297Sjkim        ASN1_IA5STRING *ia5string;
538280297Sjkim        ASN1_GENERALSTRING *generalstring;
539280297Sjkim        ASN1_BMPSTRING *bmpstring;
540280297Sjkim        ASN1_UNIVERSALSTRING *universalstring;
541280297Sjkim        ASN1_UTCTIME *utctime;
542280297Sjkim        ASN1_GENERALIZEDTIME *generalizedtime;
543280297Sjkim        ASN1_VISIBLESTRING *visiblestring;
544280297Sjkim        ASN1_UTF8STRING *utf8string;
545280297Sjkim        /*
546280297Sjkim         * set and sequence are left complete and still contain the set or
547280297Sjkim         * sequence bytes
548280297Sjkim         */
549280297Sjkim        ASN1_STRING *set;
550280297Sjkim        ASN1_STRING *sequence;
551280297Sjkim        ASN1_VALUE *asn1_value;
552280297Sjkim    } value;
553280297Sjkim} ASN1_TYPE;
55455714Skris
55555714SkrisDECLARE_STACK_OF(ASN1_TYPE)
55655714SkrisDECLARE_ASN1_SET_OF(ASN1_TYPE)
55755714Skris
558238405Sjkimtypedef STACK_OF(ASN1_TYPE) ASN1_SEQUENCE_ANY;
55955714Skris
560238405SjkimDECLARE_ASN1_ENCODE_FUNCTIONS_const(ASN1_SEQUENCE_ANY, ASN1_SEQUENCE_ANY)
561238405SjkimDECLARE_ASN1_ENCODE_FUNCTIONS_const(ASN1_SEQUENCE_ANY, ASN1_SET_ANY)
562238405Sjkim
563280297Sjkimtypedef struct NETSCAPE_X509_st {
564280297Sjkim    ASN1_OCTET_STRING *header;
565280297Sjkim    X509 *cert;
566280297Sjkim} NETSCAPE_X509;
56755714Skris
56859191Skris/* This is used to contain a list of bit names */
56959191Skristypedef struct BIT_STRING_BITNAME_st {
570280297Sjkim    int bitnum;
571280297Sjkim    const char *lname;
572280297Sjkim    const char *sname;
57359191Skris} BIT_STRING_BITNAME;
57455714Skris
575280297Sjkim# define M_ASN1_STRING_length(x) ((x)->length)
576280297Sjkim# define M_ASN1_STRING_length_set(x, n)  ((x)->length = (n))
577280297Sjkim# define M_ASN1_STRING_type(x)   ((x)->type)
578280297Sjkim# define M_ASN1_STRING_data(x)   ((x)->data)
57959191Skris
58055714Skris/* Macros for string operations */
581280297Sjkim# define M_ASN1_BIT_STRING_new() (ASN1_BIT_STRING *)\
582280297Sjkim                ASN1_STRING_type_new(V_ASN1_BIT_STRING)
583280297Sjkim# define M_ASN1_BIT_STRING_free(a)       ASN1_STRING_free((ASN1_STRING *)a)
584280297Sjkim# define M_ASN1_BIT_STRING_dup(a) (ASN1_BIT_STRING *)\
585280297Sjkim                ASN1_STRING_dup((const ASN1_STRING *)a)
586280297Sjkim# define M_ASN1_BIT_STRING_cmp(a,b) ASN1_STRING_cmp(\
587280297Sjkim                (const ASN1_STRING *)a,(const ASN1_STRING *)b)
588280297Sjkim# define M_ASN1_BIT_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
58955714Skris
590280297Sjkim# define M_ASN1_INTEGER_new()    (ASN1_INTEGER *)\
591280297Sjkim                ASN1_STRING_type_new(V_ASN1_INTEGER)
592280297Sjkim# define M_ASN1_INTEGER_free(a)          ASN1_STRING_free((ASN1_STRING *)a)
593280297Sjkim# define M_ASN1_INTEGER_dup(a) (ASN1_INTEGER *)\
594280297Sjkim                ASN1_STRING_dup((const ASN1_STRING *)a)
595280297Sjkim# define M_ASN1_INTEGER_cmp(a,b) ASN1_STRING_cmp(\
596280297Sjkim                (const ASN1_STRING *)a,(const ASN1_STRING *)b)
59755714Skris
598280297Sjkim# define M_ASN1_ENUMERATED_new() (ASN1_ENUMERATED *)\
599280297Sjkim                ASN1_STRING_type_new(V_ASN1_ENUMERATED)
600280297Sjkim# define M_ASN1_ENUMERATED_free(a)       ASN1_STRING_free((ASN1_STRING *)a)
601280297Sjkim# define M_ASN1_ENUMERATED_dup(a) (ASN1_ENUMERATED *)\
602280297Sjkim                ASN1_STRING_dup((const ASN1_STRING *)a)
603280297Sjkim# define M_ASN1_ENUMERATED_cmp(a,b)      ASN1_STRING_cmp(\
604280297Sjkim                (const ASN1_STRING *)a,(const ASN1_STRING *)b)
60555714Skris
606280297Sjkim# define M_ASN1_OCTET_STRING_new()       (ASN1_OCTET_STRING *)\
607280297Sjkim                ASN1_STRING_type_new(V_ASN1_OCTET_STRING)
608280297Sjkim# define M_ASN1_OCTET_STRING_free(a)     ASN1_STRING_free((ASN1_STRING *)a)
609280297Sjkim# define M_ASN1_OCTET_STRING_dup(a) (ASN1_OCTET_STRING *)\
610280297Sjkim                ASN1_STRING_dup((const ASN1_STRING *)a)
611280297Sjkim# define M_ASN1_OCTET_STRING_cmp(a,b) ASN1_STRING_cmp(\
612280297Sjkim                (const ASN1_STRING *)a,(const ASN1_STRING *)b)
613280297Sjkim# define M_ASN1_OCTET_STRING_set(a,b,c)  ASN1_STRING_set((ASN1_STRING *)a,b,c)
614280297Sjkim# define M_ASN1_OCTET_STRING_print(a,b)  ASN1_STRING_print(a,(ASN1_STRING *)b)
615280297Sjkim# define M_i2d_ASN1_OCTET_STRING(a,pp) \
616280297Sjkim                i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_OCTET_STRING,\
617280297Sjkim                V_ASN1_UNIVERSAL)
61855714Skris
619280297Sjkim# define B_ASN1_TIME \
620280297Sjkim                        B_ASN1_UTCTIME | \
621280297Sjkim                        B_ASN1_GENERALIZEDTIME
622109998Smarkm
623280297Sjkim# define B_ASN1_PRINTABLE \
624280297Sjkim                        B_ASN1_NUMERICSTRING| \
625280297Sjkim                        B_ASN1_PRINTABLESTRING| \
626280297Sjkim                        B_ASN1_T61STRING| \
627280297Sjkim                        B_ASN1_IA5STRING| \
628280297Sjkim                        B_ASN1_BIT_STRING| \
629280297Sjkim                        B_ASN1_UNIVERSALSTRING|\
630280297Sjkim                        B_ASN1_BMPSTRING|\
631280297Sjkim                        B_ASN1_UTF8STRING|\
632280297Sjkim                        B_ASN1_SEQUENCE|\
633280297Sjkim                        B_ASN1_UNKNOWN
63455714Skris
635280297Sjkim# define B_ASN1_DIRECTORYSTRING \
636280297Sjkim                        B_ASN1_PRINTABLESTRING| \
637280297Sjkim                        B_ASN1_TELETEXSTRING|\
638280297Sjkim                        B_ASN1_BMPSTRING|\
639280297Sjkim                        B_ASN1_UNIVERSALSTRING|\
640280297Sjkim                        B_ASN1_UTF8STRING
641109998Smarkm
642280297Sjkim# define B_ASN1_DISPLAYTEXT \
643280297Sjkim                        B_ASN1_IA5STRING| \
644280297Sjkim                        B_ASN1_VISIBLESTRING| \
645280297Sjkim                        B_ASN1_BMPSTRING|\
646280297Sjkim                        B_ASN1_UTF8STRING
647109998Smarkm
648280297Sjkim# define M_ASN1_PRINTABLE_new()  ASN1_STRING_type_new(V_ASN1_T61STRING)
649280297Sjkim# define M_ASN1_PRINTABLE_free(a)        ASN1_STRING_free((ASN1_STRING *)a)
650280297Sjkim# define M_i2d_ASN1_PRINTABLE(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
651280297Sjkim                pp,a->type,V_ASN1_UNIVERSAL)
652280297Sjkim# define M_d2i_ASN1_PRINTABLE(a,pp,l) \
653280297Sjkim                d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
654280297Sjkim                        B_ASN1_PRINTABLE)
655109998Smarkm
656280297Sjkim# define M_DIRECTORYSTRING_new() ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
657280297Sjkim# define M_DIRECTORYSTRING_free(a)       ASN1_STRING_free((ASN1_STRING *)a)
658280297Sjkim# define M_i2d_DIRECTORYSTRING(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
659280297Sjkim                                                pp,a->type,V_ASN1_UNIVERSAL)
660280297Sjkim# define M_d2i_DIRECTORYSTRING(a,pp,l) \
661280297Sjkim                d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
662280297Sjkim                        B_ASN1_DIRECTORYSTRING)
66355714Skris
664280297Sjkim# define M_DISPLAYTEXT_new() ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
665280297Sjkim# define M_DISPLAYTEXT_free(a) ASN1_STRING_free((ASN1_STRING *)a)
666280297Sjkim# define M_i2d_DISPLAYTEXT(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
667280297Sjkim                                                pp,a->type,V_ASN1_UNIVERSAL)
668280297Sjkim# define M_d2i_DISPLAYTEXT(a,pp,l) \
669280297Sjkim                d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
670280297Sjkim                        B_ASN1_DISPLAYTEXT)
67155714Skris
672280297Sjkim# define M_ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING *)\
673280297Sjkim                ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
674280297Sjkim# define M_ASN1_PRINTABLESTRING_free(a)  ASN1_STRING_free((ASN1_STRING *)a)
675280297Sjkim# define M_i2d_ASN1_PRINTABLESTRING(a,pp) \
676280297Sjkim                i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_PRINTABLESTRING,\
677280297Sjkim                V_ASN1_UNIVERSAL)
678280297Sjkim# define M_d2i_ASN1_PRINTABLESTRING(a,pp,l) \
679280297Sjkim                (ASN1_PRINTABLESTRING *)d2i_ASN1_type_bytes\
680280297Sjkim                ((ASN1_STRING **)a,pp,l,B_ASN1_PRINTABLESTRING)
68155714Skris
682280297Sjkim# define M_ASN1_T61STRING_new()  (ASN1_T61STRING *)\
683280297Sjkim                ASN1_STRING_type_new(V_ASN1_T61STRING)
684280297Sjkim# define M_ASN1_T61STRING_free(a)        ASN1_STRING_free((ASN1_STRING *)a)
685280297Sjkim# define M_i2d_ASN1_T61STRING(a,pp) \
686280297Sjkim                i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_T61STRING,\
687280297Sjkim                V_ASN1_UNIVERSAL)
688280297Sjkim# define M_d2i_ASN1_T61STRING(a,pp,l) \
689280297Sjkim                (ASN1_T61STRING *)d2i_ASN1_type_bytes\
690280297Sjkim                ((ASN1_STRING **)a,pp,l,B_ASN1_T61STRING)
69155714Skris
692280297Sjkim# define M_ASN1_IA5STRING_new()  (ASN1_IA5STRING *)\
693280297Sjkim                ASN1_STRING_type_new(V_ASN1_IA5STRING)
694280297Sjkim# define M_ASN1_IA5STRING_free(a)        ASN1_STRING_free((ASN1_STRING *)a)
695280297Sjkim# define M_ASN1_IA5STRING_dup(a) \
696280297Sjkim                (ASN1_IA5STRING *)ASN1_STRING_dup((const ASN1_STRING *)a)
697280297Sjkim# define M_i2d_ASN1_IA5STRING(a,pp) \
698280297Sjkim                i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_IA5STRING,\
699280297Sjkim                        V_ASN1_UNIVERSAL)
700280297Sjkim# define M_d2i_ASN1_IA5STRING(a,pp,l) \
701280297Sjkim                (ASN1_IA5STRING *)d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l,\
702280297Sjkim                        B_ASN1_IA5STRING)
70355714Skris
704280297Sjkim# define M_ASN1_UTCTIME_new()    (ASN1_UTCTIME *)\
705280297Sjkim                ASN1_STRING_type_new(V_ASN1_UTCTIME)
706280297Sjkim# define M_ASN1_UTCTIME_free(a)  ASN1_STRING_free((ASN1_STRING *)a)
707280297Sjkim# define M_ASN1_UTCTIME_dup(a) (ASN1_UTCTIME *)\
708280297Sjkim                ASN1_STRING_dup((const ASN1_STRING *)a)
70955714Skris
710280297Sjkim# define M_ASN1_GENERALIZEDTIME_new()    (ASN1_GENERALIZEDTIME *)\
711280297Sjkim                ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME)
712280297Sjkim# define M_ASN1_GENERALIZEDTIME_free(a)  ASN1_STRING_free((ASN1_STRING *)a)
713280297Sjkim# define M_ASN1_GENERALIZEDTIME_dup(a) (ASN1_GENERALIZEDTIME *)ASN1_STRING_dup(\
714280297Sjkim        (const ASN1_STRING *)a)
71555714Skris
716280297Sjkim# define M_ASN1_TIME_new()       (ASN1_TIME *)\
717280297Sjkim                ASN1_STRING_type_new(V_ASN1_UTCTIME)
718280297Sjkim# define M_ASN1_TIME_free(a)     ASN1_STRING_free((ASN1_STRING *)a)
719280297Sjkim# define M_ASN1_TIME_dup(a) (ASN1_TIME *)\
720280297Sjkim        ASN1_STRING_dup((const ASN1_STRING *)a)
72155714Skris
722280297Sjkim# define M_ASN1_GENERALSTRING_new()      (ASN1_GENERALSTRING *)\
723280297Sjkim                ASN1_STRING_type_new(V_ASN1_GENERALSTRING)
724280297Sjkim# define M_ASN1_GENERALSTRING_free(a)    ASN1_STRING_free((ASN1_STRING *)a)
725280297Sjkim# define M_i2d_ASN1_GENERALSTRING(a,pp) \
726280297Sjkim                i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_GENERALSTRING,\
727280297Sjkim                        V_ASN1_UNIVERSAL)
728280297Sjkim# define M_d2i_ASN1_GENERALSTRING(a,pp,l) \
729280297Sjkim                (ASN1_GENERALSTRING *)d2i_ASN1_type_bytes\
730280297Sjkim                ((ASN1_STRING **)a,pp,l,B_ASN1_GENERALSTRING)
73155714Skris
732280297Sjkim# define M_ASN1_UNIVERSALSTRING_new()    (ASN1_UNIVERSALSTRING *)\
733280297Sjkim                ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING)
734280297Sjkim# define M_ASN1_UNIVERSALSTRING_free(a)  ASN1_STRING_free((ASN1_STRING *)a)
735280297Sjkim# define M_i2d_ASN1_UNIVERSALSTRING(a,pp) \
736280297Sjkim                i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UNIVERSALSTRING,\
737280297Sjkim                        V_ASN1_UNIVERSAL)
738280297Sjkim# define M_d2i_ASN1_UNIVERSALSTRING(a,pp,l) \
739280297Sjkim                (ASN1_UNIVERSALSTRING *)d2i_ASN1_type_bytes\
740280297Sjkim                ((ASN1_STRING **)a,pp,l,B_ASN1_UNIVERSALSTRING)
74155714Skris
742280297Sjkim# define M_ASN1_BMPSTRING_new()  (ASN1_BMPSTRING *)\
743280297Sjkim                ASN1_STRING_type_new(V_ASN1_BMPSTRING)
744280297Sjkim# define M_ASN1_BMPSTRING_free(a)        ASN1_STRING_free((ASN1_STRING *)a)
745280297Sjkim# define M_i2d_ASN1_BMPSTRING(a,pp) \
746280297Sjkim                i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_BMPSTRING,\
747280297Sjkim                        V_ASN1_UNIVERSAL)
748280297Sjkim# define M_d2i_ASN1_BMPSTRING(a,pp,l) \
749280297Sjkim                (ASN1_BMPSTRING *)d2i_ASN1_type_bytes\
750280297Sjkim                ((ASN1_STRING **)a,pp,l,B_ASN1_BMPSTRING)
75155714Skris
752280297Sjkim# define M_ASN1_VISIBLESTRING_new()      (ASN1_VISIBLESTRING *)\
753280297Sjkim                ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
754280297Sjkim# define M_ASN1_VISIBLESTRING_free(a)    ASN1_STRING_free((ASN1_STRING *)a)
755280297Sjkim# define M_i2d_ASN1_VISIBLESTRING(a,pp) \
756280297Sjkim                i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_VISIBLESTRING,\
757280297Sjkim                        V_ASN1_UNIVERSAL)
758280297Sjkim# define M_d2i_ASN1_VISIBLESTRING(a,pp,l) \
759280297Sjkim                (ASN1_VISIBLESTRING *)d2i_ASN1_type_bytes\
760280297Sjkim                ((ASN1_STRING **)a,pp,l,B_ASN1_VISIBLESTRING)
76155714Skris
762280297Sjkim# define M_ASN1_UTF8STRING_new() (ASN1_UTF8STRING *)\
763280297Sjkim                ASN1_STRING_type_new(V_ASN1_UTF8STRING)
764280297Sjkim# define M_ASN1_UTF8STRING_free(a)       ASN1_STRING_free((ASN1_STRING *)a)
765280297Sjkim# define M_i2d_ASN1_UTF8STRING(a,pp) \
766280297Sjkim                i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UTF8STRING,\
767280297Sjkim                        V_ASN1_UNIVERSAL)
768280297Sjkim# define M_d2i_ASN1_UTF8STRING(a,pp,l) \
769280297Sjkim                (ASN1_UTF8STRING *)d2i_ASN1_type_bytes\
770280297Sjkim                ((ASN1_STRING **)a,pp,l,B_ASN1_UTF8STRING)
77155714Skris
77255714Skris  /* for the is_set parameter to i2d_ASN1_SET */
773280297Sjkim# define IS_SEQUENCE     0
774280297Sjkim# define IS_SET          1
77555714Skris
776109998SmarkmDECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
777109998Smarkm
77855714Skrisint ASN1_TYPE_get(ASN1_TYPE *a);
77955714Skrisvoid ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value);
780194206Ssimonint ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value);
781280297Sjkimint ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b);
78255714Skris
783280297SjkimASN1_OBJECT *ASN1_OBJECT_new(void);
784280297Sjkimvoid ASN1_OBJECT_free(ASN1_OBJECT *a);
785280297Sjkimint i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp);
786280297SjkimASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
787280297Sjkim                             long length);
788280297SjkimASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
789280297Sjkim                             long length);
79055714Skris
791109998SmarkmDECLARE_ASN1_ITEM(ASN1_OBJECT)
792109998Smarkm
79355714SkrisDECLARE_STACK_OF(ASN1_OBJECT)
79455714SkrisDECLARE_ASN1_SET_OF(ASN1_OBJECT)
79555714Skris
796280297SjkimASN1_STRING *ASN1_STRING_new(void);
797280297Sjkimvoid ASN1_STRING_free(ASN1_STRING *a);
798280297Sjkimvoid ASN1_STRING_clear_free(ASN1_STRING *a);
799280297Sjkimint ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str);
800280297SjkimASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *a);
801280297SjkimASN1_STRING *ASN1_STRING_type_new(int type);
802280297Sjkimint ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b);
803280297Sjkim  /*
804280297Sjkim   * Since this is used to store all sorts of things, via macros, for now,
805280297Sjkim   * make its data void *
806280297Sjkim   */
807280297Sjkimint ASN1_STRING_set(ASN1_STRING *str, const void *data, int len);
808280297Sjkimvoid ASN1_STRING_set0(ASN1_STRING *str, void *data, int len);
809238405Sjkimint ASN1_STRING_length(const ASN1_STRING *x);
81059191Skrisvoid ASN1_STRING_length_set(ASN1_STRING *x, int n);
81159191Skrisint ASN1_STRING_type(ASN1_STRING *x);
812280297Sjkimunsigned char *ASN1_STRING_data(ASN1_STRING *x);
81355714Skris
814109998SmarkmDECLARE_ASN1_FUNCTIONS(ASN1_BIT_STRING)
815280297Sjkimint i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp);
816280297SjkimASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
817280297Sjkim                                     const unsigned char **pp, long length);
818280297Sjkimint ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d, int length);
819280297Sjkimint ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value);
820280297Sjkimint ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n);
821280297Sjkimint ASN1_BIT_STRING_check(ASN1_BIT_STRING *a,
822280297Sjkim                          unsigned char *flags, int flags_len);
82355714Skris
824280297Sjkim# ifndef OPENSSL_NO_BIO
82559191Skrisint ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
826280297Sjkim                               BIT_STRING_BITNAME *tbl, int indent);
827280297Sjkim# endif
82859191Skrisint ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl);
82959191Skrisint ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value,
830280297Sjkim                            BIT_STRING_BITNAME *tbl);
83155714Skris
832280297Sjkimint i2d_ASN1_BOOLEAN(int a, unsigned char **pp);
833280297Sjkimint d2i_ASN1_BOOLEAN(int *a, const unsigned char **pp, long length);
83455714Skris
835109998SmarkmDECLARE_ASN1_FUNCTIONS(ASN1_INTEGER)
836280297Sjkimint i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp);
837280297SjkimASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp,
838280297Sjkim                               long length);
839280297SjkimASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp,
840280297Sjkim                                long length);
841280297SjkimASN1_INTEGER *ASN1_INTEGER_dup(const ASN1_INTEGER *x);
842238405Sjkimint ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y);
84355714Skris
844109998SmarkmDECLARE_ASN1_FUNCTIONS(ASN1_ENUMERATED)
84555714Skris
846290207Sjkimint ASN1_UTCTIME_check(const ASN1_UTCTIME *a);
847280297SjkimASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t);
848238405SjkimASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
849280297Sjkim                               int offset_day, long offset_sec);
850160814Ssimonint ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str);
85168651Skrisint ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t);
852280297Sjkim# if 0
85368651Skristime_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s);
854280297Sjkim# endif
85555714Skris
856290207Sjkimint ASN1_GENERALIZEDTIME_check(const ASN1_GENERALIZEDTIME *a);
857280297SjkimASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
858280297Sjkim                                               time_t t);
859238405SjkimASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
860280297Sjkim                                               time_t t, int offset_day,
861280297Sjkim                                               long offset_sec);
862160814Ssimonint ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str);
863290207Sjkimint ASN1_TIME_diff(int *pday, int *psec,
864290207Sjkim                   const ASN1_TIME *from, const ASN1_TIME *to);
86555714Skris
866109998SmarkmDECLARE_ASN1_FUNCTIONS(ASN1_OCTET_STRING)
867280297SjkimASN1_OCTET_STRING *ASN1_OCTET_STRING_dup(const ASN1_OCTET_STRING *a);
868280297Sjkimint ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a,
869280297Sjkim                          const ASN1_OCTET_STRING *b);
870280297Sjkimint ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, const unsigned char *data,
871280297Sjkim                          int len);
87255714Skris
873109998SmarkmDECLARE_ASN1_FUNCTIONS(ASN1_VISIBLESTRING)
874109998SmarkmDECLARE_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING)
875109998SmarkmDECLARE_ASN1_FUNCTIONS(ASN1_UTF8STRING)
876109998SmarkmDECLARE_ASN1_FUNCTIONS(ASN1_NULL)
877109998SmarkmDECLARE_ASN1_FUNCTIONS(ASN1_BMPSTRING)
87855714Skris
87959191Skrisint UTF8_getc(const unsigned char *str, int len, unsigned long *val);
88059191Skrisint UTF8_putc(unsigned char *str, int len, unsigned long value);
88159191Skris
882109998SmarkmDECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE)
88359191Skris
884109998SmarkmDECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING)
885109998SmarkmDECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT)
886109998SmarkmDECLARE_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING)
887109998SmarkmDECLARE_ASN1_FUNCTIONS(ASN1_T61STRING)
888109998SmarkmDECLARE_ASN1_FUNCTIONS(ASN1_IA5STRING)
889109998SmarkmDECLARE_ASN1_FUNCTIONS(ASN1_GENERALSTRING)
890109998SmarkmDECLARE_ASN1_FUNCTIONS(ASN1_UTCTIME)
891109998SmarkmDECLARE_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME)
892109998SmarkmDECLARE_ASN1_FUNCTIONS(ASN1_TIME)
89355714Skris
894160814SsimonDECLARE_ASN1_ITEM(ASN1_OCTET_STRING_NDEF)
895160814Ssimon
896280297SjkimASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t);
897280297SjkimASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t,
898280297Sjkim                         int offset_day, long offset_sec);
899109998Smarkmint ASN1_TIME_check(ASN1_TIME *t);
900280297SjkimASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME
901280297Sjkim                                                   **out);
902238405Sjkimint ASN1_TIME_set_string(ASN1_TIME *s, const char *str);
90355714Skris
904238405Sjkimint i2d_ASN1_SET(STACK_OF(OPENSSL_BLOCK) *a, unsigned char **pp,
905280297Sjkim                 i2d_of_void *i2d, int ex_tag, int ex_class, int is_set);
906238405SjkimSTACK_OF(OPENSSL_BLOCK) *d2i_ASN1_SET(STACK_OF(OPENSSL_BLOCK) **a,
907280297Sjkim                                      const unsigned char **pp,
908280297Sjkim                                      long length, d2i_of_void *d2i,
909280297Sjkim                                      void (*free_func) (OPENSSL_BLOCK),
910280297Sjkim                                      int ex_tag, int ex_class);
91155714Skris
912280297Sjkim# ifndef OPENSSL_NO_BIO
91355714Skrisint i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a);
914280297Sjkimint a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size);
91555714Skrisint i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a);
916280297Sjkimint a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size);
917280297Sjkimint i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a);
918280297Sjkimint a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size);
91955714Skrisint i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type);
920280297Sjkim# endif
921280297Sjkimint i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a);
92255714Skris
923280297Sjkimint a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num);
924280297SjkimASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len,
925280297Sjkim                                const char *sn, const char *ln);
92655714Skris
92755714Skrisint ASN1_INTEGER_set(ASN1_INTEGER *a, long v);
928238405Sjkimlong ASN1_INTEGER_get(const ASN1_INTEGER *a);
929238405SjkimASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai);
930280297SjkimBIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn);
93155714Skris
93255714Skrisint ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v);
93355714Skrislong ASN1_ENUMERATED_get(ASN1_ENUMERATED *a);
93455714SkrisASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai);
935280297SjkimBIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn);
93655714Skris
93755714Skris/* General */
93855714Skris/* given a string, return the correct type, max is the maximum length */
939160814Ssimonint ASN1_PRINTABLE_type(const unsigned char *s, int max);
94055714Skris
94155714Skrisint i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass);
942160814SsimonASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, const unsigned char **pp,
943280297Sjkim                            long length, int Ptag, int Pclass);
944109998Smarkmunsigned long ASN1_tag2bit(int tag);
94555714Skris/* type is one or more of the B_ASN1_ values. */
946280297SjkimASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a, const unsigned char **pp,
947280297Sjkim                                 long length, int type);
94855714Skris
94955714Skris/* PARSING */
95055714Skrisint asn1_Finish(ASN1_CTX *c);
951160814Ssimonint asn1_const_Finish(ASN1_const_CTX *c);
95255714Skris
95355714Skris/* SPECIALS */
954160814Ssimonint ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,
955280297Sjkim                    int *pclass, long omax);
956280297Sjkimint ASN1_check_infinite_end(unsigned char **p, long len);
957280297Sjkimint ASN1_const_check_infinite_end(const unsigned char **p, long len);
95855714Skrisvoid ASN1_put_object(unsigned char **pp, int constructed, int length,
959280297Sjkim                     int tag, int xclass);
960160814Ssimonint ASN1_put_eoc(unsigned char **pp);
96155714Skrisint ASN1_object_size(int constructed, int length, int tag);
96255714Skris
96355714Skris/* Used to implement other functions */
964238405Sjkimvoid *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x);
965194206Ssimon
966280297Sjkim# define ASN1_dup_of(type,i2d,d2i,x) \
967194206Ssimon    ((type*)ASN1_dup(CHECKED_I2D_OF(type, i2d), \
968280297Sjkim                     CHECKED_D2I_OF(type, d2i), \
969280297Sjkim                     CHECKED_PTR_OF(type, x)))
970194206Ssimon
971280297Sjkim# define ASN1_dup_of_const(type,i2d,d2i,x) \
972194206Ssimon    ((type*)ASN1_dup(CHECKED_I2D_OF(const type, i2d), \
973280297Sjkim                     CHECKED_D2I_OF(type, d2i), \
974280297Sjkim                     CHECKED_PTR_OF(const type, x)))
97555714Skris
976109998Smarkmvoid *ASN1_item_dup(const ASN1_ITEM *it, void *x);
977109998Smarkm
978194206Ssimon/* ASN1 alloc/free macros for when a type is only used internally */
979194206Ssimon
980280297Sjkim# define M_ASN1_new_of(type) (type *)ASN1_item_new(ASN1_ITEM_rptr(type))
981280297Sjkim# define M_ASN1_free_of(x, type) \
982280297Sjkim                ASN1_item_free(CHECKED_PTR_OF(type, x), ASN1_ITEM_rptr(type))
983194206Ssimon
984280297Sjkim# ifndef OPENSSL_NO_FP_API
985280297Sjkimvoid *ASN1_d2i_fp(void *(*xnew) (void), d2i_of_void *d2i, FILE *in, void **x);
986194206Ssimon
987280297Sjkim#  define ASN1_d2i_fp_of(type,xnew,d2i,in,x) \
988194206Ssimon    ((type*)ASN1_d2i_fp(CHECKED_NEW_OF(type, xnew), \
989280297Sjkim                        CHECKED_D2I_OF(type, d2i), \
990280297Sjkim                        in, \
991280297Sjkim                        CHECKED_PPTR_OF(type, x)))
992194206Ssimon
993109998Smarkmvoid *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x);
994280297Sjkimint ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x);
995194206Ssimon
996280297Sjkim#  define ASN1_i2d_fp_of(type,i2d,out,x) \
997194206Ssimon    (ASN1_i2d_fp(CHECKED_I2D_OF(type, i2d), \
998280297Sjkim                 out, \
999280297Sjkim                 CHECKED_PTR_OF(type, x)))
1000194206Ssimon
1001280297Sjkim#  define ASN1_i2d_fp_of_const(type,i2d,out,x) \
1002194206Ssimon    (ASN1_i2d_fp(CHECKED_I2D_OF(const type, i2d), \
1003280297Sjkim                 out, \
1004280297Sjkim                 CHECKED_PTR_OF(const type, x)))
1005194206Ssimon
1006109998Smarkmint ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x);
100768651Skrisint ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags);
1008280297Sjkim# endif
100955714Skris
101068651Skrisint ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in);
101168651Skris
1012280297Sjkim# ifndef OPENSSL_NO_BIO
1013280297Sjkimvoid *ASN1_d2i_bio(void *(*xnew) (void), d2i_of_void *d2i, BIO *in, void **x);
1014194206Ssimon
1015280297Sjkim#  define ASN1_d2i_bio_of(type,xnew,d2i,in,x) \
1016194206Ssimon    ((type*)ASN1_d2i_bio( CHECKED_NEW_OF(type, xnew), \
1017280297Sjkim                          CHECKED_D2I_OF(type, d2i), \
1018280297Sjkim                          in, \
1019280297Sjkim                          CHECKED_PPTR_OF(type, x)))
1020194206Ssimon
1021109998Smarkmvoid *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x);
1022280297Sjkimint ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x);
1023194206Ssimon
1024280297Sjkim#  define ASN1_i2d_bio_of(type,i2d,out,x) \
1025194206Ssimon    (ASN1_i2d_bio(CHECKED_I2D_OF(type, i2d), \
1026280297Sjkim                  out, \
1027280297Sjkim                  CHECKED_PTR_OF(type, x)))
1028194206Ssimon
1029280297Sjkim#  define ASN1_i2d_bio_of_const(type,i2d,out,x) \
1030194206Ssimon    (ASN1_i2d_bio(CHECKED_I2D_OF(const type, i2d), \
1031280297Sjkim                  out, \
1032280297Sjkim                  CHECKED_PTR_OF(const type, x)))
1033194206Ssimon
1034109998Smarkmint ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x);
1035238405Sjkimint ASN1_UTCTIME_print(BIO *fp, const ASN1_UTCTIME *a);
1036238405Sjkimint ASN1_GENERALIZEDTIME_print(BIO *fp, const ASN1_GENERALIZEDTIME *a);
1037238405Sjkimint ASN1_TIME_print(BIO *fp, const ASN1_TIME *a);
1038238405Sjkimint ASN1_STRING_print(BIO *bp, const ASN1_STRING *v);
103968651Skrisint ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags);
1040238405Sjkimint ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num,
1041280297Sjkim                  unsigned char *buf, int off);
1042280297Sjkimint ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent);
1043280297Sjkimint ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent,
1044280297Sjkim                    int dump);
1045280297Sjkim# endif
104659191Skrisconst char *ASN1_tag2str(int tag);
104755714Skris
1048238405Sjkim/* Used to load and write netscape format cert */
104955714Skris
1050238405SjkimDECLARE_ASN1_FUNCTIONS(NETSCAPE_X509)
1051238405Sjkim
105255714Skrisint ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s);
105355714Skris
1054280297Sjkimint ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len);
1055280297Sjkimint ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data, int max_len);
105655714Skrisint ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num,
1057280297Sjkim                                  unsigned char *data, int len);
1058280297Sjkimint ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num,
1059280297Sjkim                                  unsigned char *data, int max_len);
106055714Skris
1061238405SjkimSTACK_OF(OPENSSL_BLOCK) *ASN1_seq_unpack(const unsigned char *buf, int len,
1062280297Sjkim                                         d2i_of_void *d2i,
1063280297Sjkim                                         void (*free_func) (OPENSSL_BLOCK));
1064238405Sjkimunsigned char *ASN1_seq_pack(STACK_OF(OPENSSL_BLOCK) *safes, i2d_of_void *i2d,
1065280297Sjkim                             unsigned char **buf, int *len);
1066160814Ssimonvoid *ASN1_unpack_string(ASN1_STRING *oct, d2i_of_void *d2i);
1067109998Smarkmvoid *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it);
1068160814SsimonASN1_STRING *ASN1_pack_string(void *obj, i2d_of_void *i2d,
1069280297Sjkim                              ASN1_OCTET_STRING **oct);
1070194206Ssimon
1071280297Sjkim# define ASN1_pack_string_of(type,obj,i2d,oct) \
1072194206Ssimon    (ASN1_pack_string(CHECKED_PTR_OF(type, obj), \
1073280297Sjkim                      CHECKED_I2D_OF(type, i2d), \
1074280297Sjkim                      oct))
1075194206Ssimon
1076280297SjkimASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it,
1077280297Sjkim                            ASN1_OCTET_STRING **oct);
107855714Skris
107959191Skrisvoid ASN1_STRING_set_default_mask(unsigned long mask);
1080237657Sjkimint ASN1_STRING_set_default_mask_asc(const char *p);
108159191Skrisunsigned long ASN1_STRING_get_default_mask(void);
108259191Skrisint ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len,
1083280297Sjkim                       int inform, unsigned long mask);
108459191Skrisint ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
1085280297Sjkim                        int inform, unsigned long mask,
1086280297Sjkim                        long minsize, long maxsize);
108759191Skris
1088280297SjkimASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out,
1089280297Sjkim                                    const unsigned char *in, int inlen,
1090280297Sjkim                                    int inform, int nid);
109159191SkrisASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid);
109259191Skrisint ASN1_STRING_TABLE_add(int, long, long, unsigned long, unsigned long);
109359191Skrisvoid ASN1_STRING_TABLE_cleanup(void);
109459191Skris
1095109998Smarkm/* ASN1 template functions */
1096109998Smarkm
1097109998Smarkm/* Old API compatible functions */
1098109998SmarkmASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it);
1099109998Smarkmvoid ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it);
1100280297SjkimASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **val, const unsigned char **in,
1101280297Sjkim                          long len, const ASN1_ITEM *it);
1102109998Smarkmint ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it);
1103280297Sjkimint ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out,
1104280297Sjkim                       const ASN1_ITEM *it);
1105109998Smarkm
1106109998Smarkmvoid ASN1_add_oid_module(void);
1107109998Smarkm
1108160814SsimonASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf);
1109160814SsimonASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf);
1110194206Ssimon
1111238405Sjkim/* ASN1 Print flags */
1112194206Ssimon
1113238405Sjkim/* Indicate missing OPTIONAL fields */
1114280297Sjkim# define ASN1_PCTX_FLAGS_SHOW_ABSENT             0x001
1115238405Sjkim/* Mark start and end of SEQUENCE */
1116280297Sjkim# define ASN1_PCTX_FLAGS_SHOW_SEQUENCE           0x002
1117238405Sjkim/* Mark start and end of SEQUENCE/SET OF */
1118280297Sjkim# define ASN1_PCTX_FLAGS_SHOW_SSOF               0x004
1119238405Sjkim/* Show the ASN1 type of primitives */
1120280297Sjkim# define ASN1_PCTX_FLAGS_SHOW_TYPE               0x008
1121238405Sjkim/* Don't show ASN1 type of ANY */
1122280297Sjkim# define ASN1_PCTX_FLAGS_NO_ANY_TYPE             0x010
1123238405Sjkim/* Don't show ASN1 type of MSTRINGs */
1124280297Sjkim# define ASN1_PCTX_FLAGS_NO_MSTRING_TYPE         0x020
1125238405Sjkim/* Don't show field names in SEQUENCE */
1126280297Sjkim# define ASN1_PCTX_FLAGS_NO_FIELD_NAME           0x040
1127238405Sjkim/* Show structure names of each SEQUENCE field */
1128280297Sjkim# define ASN1_PCTX_FLAGS_SHOW_FIELD_STRUCT_NAME  0x080
1129238405Sjkim/* Don't show structure name even at top level */
1130280297Sjkim# define ASN1_PCTX_FLAGS_NO_STRUCT_NAME          0x100
1131238405Sjkim
1132238405Sjkimint ASN1_item_print(BIO *out, ASN1_VALUE *ifld, int indent,
1133280297Sjkim                    const ASN1_ITEM *it, const ASN1_PCTX *pctx);
1134238405SjkimASN1_PCTX *ASN1_PCTX_new(void);
1135238405Sjkimvoid ASN1_PCTX_free(ASN1_PCTX *p);
1136238405Sjkimunsigned long ASN1_PCTX_get_flags(ASN1_PCTX *p);
1137238405Sjkimvoid ASN1_PCTX_set_flags(ASN1_PCTX *p, unsigned long flags);
1138238405Sjkimunsigned long ASN1_PCTX_get_nm_flags(ASN1_PCTX *p);
1139238405Sjkimvoid ASN1_PCTX_set_nm_flags(ASN1_PCTX *p, unsigned long flags);
1140238405Sjkimunsigned long ASN1_PCTX_get_cert_flags(ASN1_PCTX *p);
1141238405Sjkimvoid ASN1_PCTX_set_cert_flags(ASN1_PCTX *p, unsigned long flags);
1142238405Sjkimunsigned long ASN1_PCTX_get_oid_flags(ASN1_PCTX *p);
1143238405Sjkimvoid ASN1_PCTX_set_oid_flags(ASN1_PCTX *p, unsigned long flags);
1144238405Sjkimunsigned long ASN1_PCTX_get_str_flags(ASN1_PCTX *p);
1145238405Sjkimvoid ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags);
1146238405Sjkim
1147238405SjkimBIO_METHOD *BIO_f_asn1(void);
1148238405Sjkim
1149238405SjkimBIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it);
1150238405Sjkim
1151238405Sjkimint i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
1152280297Sjkim                        const ASN1_ITEM *it);
1153238405Sjkimint PEM_write_bio_ASN1_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
1154280297Sjkim                              const char *hdr, const ASN1_ITEM *it);
1155238405Sjkimint SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
1156280297Sjkim                     int ctype_nid, int econt_nid,
1157280297Sjkim                     STACK_OF(X509_ALGOR) *mdalgs, const ASN1_ITEM *it);
1158194206SsimonASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it);
1159238405Sjkimint SMIME_crlf_copy(BIO *in, BIO *out, int flags);
1160238405Sjkimint SMIME_text(BIO *in, BIO *out);
1161194206Ssimon
116255714Skris/* BEGIN ERROR CODES */
1163280297Sjkim/*
1164280297Sjkim * The following lines are auto generated by the script mkerr.pl. Any changes
116555714Skris * made after this point may be overwritten when the script is next run.
116655714Skris */
116789837Skrisvoid ERR_load_ASN1_strings(void);
116855714Skris
116955714Skris/* Error codes for the ASN1 functions. */
117055714Skris
117155714Skris/* Function codes. */
1172280297Sjkim# define ASN1_F_A2D_ASN1_OBJECT                           100
1173280297Sjkim# define ASN1_F_A2I_ASN1_ENUMERATED                       101
1174280297Sjkim# define ASN1_F_A2I_ASN1_INTEGER                          102
1175280297Sjkim# define ASN1_F_A2I_ASN1_STRING                           103
1176280297Sjkim# define ASN1_F_APPEND_EXP                                176
1177280297Sjkim# define ASN1_F_ASN1_BIT_STRING_SET_BIT                   183
1178280297Sjkim# define ASN1_F_ASN1_CB                                   177
1179280297Sjkim# define ASN1_F_ASN1_CHECK_TLEN                           104
1180280297Sjkim# define ASN1_F_ASN1_COLLATE_PRIMITIVE                    105
1181280297Sjkim# define ASN1_F_ASN1_COLLECT                              106
1182280297Sjkim# define ASN1_F_ASN1_D2I_EX_PRIMITIVE                     108
1183280297Sjkim# define ASN1_F_ASN1_D2I_FP                               109
1184280297Sjkim# define ASN1_F_ASN1_D2I_READ_BIO                         107
1185280297Sjkim# define ASN1_F_ASN1_DIGEST                               184
1186280297Sjkim# define ASN1_F_ASN1_DO_ADB                               110
1187280297Sjkim# define ASN1_F_ASN1_DUP                                  111
1188280297Sjkim# define ASN1_F_ASN1_ENUMERATED_SET                       112
1189280297Sjkim# define ASN1_F_ASN1_ENUMERATED_TO_BN                     113
1190280297Sjkim# define ASN1_F_ASN1_EX_C2I                               204
1191280297Sjkim# define ASN1_F_ASN1_FIND_END                             190
1192280297Sjkim# define ASN1_F_ASN1_GENERALIZEDTIME_ADJ                  216
1193280297Sjkim# define ASN1_F_ASN1_GENERALIZEDTIME_SET                  185
1194280297Sjkim# define ASN1_F_ASN1_GENERATE_V3                          178
1195280297Sjkim# define ASN1_F_ASN1_GET_OBJECT                           114
1196280297Sjkim# define ASN1_F_ASN1_HEADER_NEW                           115
1197280297Sjkim# define ASN1_F_ASN1_I2D_BIO                              116
1198280297Sjkim# define ASN1_F_ASN1_I2D_FP                               117
1199280297Sjkim# define ASN1_F_ASN1_INTEGER_SET                          118
1200280297Sjkim# define ASN1_F_ASN1_INTEGER_TO_BN                        119
1201280297Sjkim# define ASN1_F_ASN1_ITEM_D2I_FP                          206
1202280297Sjkim# define ASN1_F_ASN1_ITEM_DUP                             191
1203280297Sjkim# define ASN1_F_ASN1_ITEM_EX_COMBINE_NEW                  121
1204280297Sjkim# define ASN1_F_ASN1_ITEM_EX_D2I                          120
1205280297Sjkim# define ASN1_F_ASN1_ITEM_I2D_BIO                         192
1206280297Sjkim# define ASN1_F_ASN1_ITEM_I2D_FP                          193
1207280297Sjkim# define ASN1_F_ASN1_ITEM_PACK                            198
1208280297Sjkim# define ASN1_F_ASN1_ITEM_SIGN                            195
1209280297Sjkim# define ASN1_F_ASN1_ITEM_SIGN_CTX                        220
1210280297Sjkim# define ASN1_F_ASN1_ITEM_UNPACK                          199
1211280297Sjkim# define ASN1_F_ASN1_ITEM_VERIFY                          197
1212280297Sjkim# define ASN1_F_ASN1_MBSTRING_NCOPY                       122
1213280297Sjkim# define ASN1_F_ASN1_OBJECT_NEW                           123
1214280297Sjkim# define ASN1_F_ASN1_OUTPUT_DATA                          214
1215280297Sjkim# define ASN1_F_ASN1_PACK_STRING                          124
1216280297Sjkim# define ASN1_F_ASN1_PCTX_NEW                             205
1217280297Sjkim# define ASN1_F_ASN1_PKCS5_PBE_SET                        125
1218280297Sjkim# define ASN1_F_ASN1_SEQ_PACK                             126
1219280297Sjkim# define ASN1_F_ASN1_SEQ_UNPACK                           127
1220280297Sjkim# define ASN1_F_ASN1_SIGN                                 128
1221280297Sjkim# define ASN1_F_ASN1_STR2TYPE                             179
1222280297Sjkim# define ASN1_F_ASN1_STRING_SET                           186
1223280297Sjkim# define ASN1_F_ASN1_STRING_TABLE_ADD                     129
1224280297Sjkim# define ASN1_F_ASN1_STRING_TYPE_NEW                      130
1225280297Sjkim# define ASN1_F_ASN1_TEMPLATE_EX_D2I                      132
1226280297Sjkim# define ASN1_F_ASN1_TEMPLATE_NEW                         133
1227280297Sjkim# define ASN1_F_ASN1_TEMPLATE_NOEXP_D2I                   131
1228280297Sjkim# define ASN1_F_ASN1_TIME_ADJ                             217
1229280297Sjkim# define ASN1_F_ASN1_TIME_SET                             175
1230280297Sjkim# define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING             134
1231280297Sjkim# define ASN1_F_ASN1_TYPE_GET_OCTETSTRING                 135
1232280297Sjkim# define ASN1_F_ASN1_UNPACK_STRING                        136
1233280297Sjkim# define ASN1_F_ASN1_UTCTIME_ADJ                          218
1234280297Sjkim# define ASN1_F_ASN1_UTCTIME_SET                          187
1235280297Sjkim# define ASN1_F_ASN1_VERIFY                               137
1236280297Sjkim# define ASN1_F_B64_READ_ASN1                             209
1237280297Sjkim# define ASN1_F_B64_WRITE_ASN1                            210
1238280297Sjkim# define ASN1_F_BIO_NEW_NDEF                              208
1239280297Sjkim# define ASN1_F_BITSTR_CB                                 180
1240280297Sjkim# define ASN1_F_BN_TO_ASN1_ENUMERATED                     138
1241280297Sjkim# define ASN1_F_BN_TO_ASN1_INTEGER                        139
1242280297Sjkim# define ASN1_F_C2I_ASN1_BIT_STRING                       189
1243280297Sjkim# define ASN1_F_C2I_ASN1_INTEGER                          194
1244280297Sjkim# define ASN1_F_C2I_ASN1_OBJECT                           196
1245280297Sjkim# define ASN1_F_COLLECT_DATA                              140
1246280297Sjkim# define ASN1_F_D2I_ASN1_BIT_STRING                       141
1247280297Sjkim# define ASN1_F_D2I_ASN1_BOOLEAN                          142
1248280297Sjkim# define ASN1_F_D2I_ASN1_BYTES                            143
1249280297Sjkim# define ASN1_F_D2I_ASN1_GENERALIZEDTIME                  144
1250280297Sjkim# define ASN1_F_D2I_ASN1_HEADER                           145
1251280297Sjkim# define ASN1_F_D2I_ASN1_INTEGER                          146
1252280297Sjkim# define ASN1_F_D2I_ASN1_OBJECT                           147
1253280297Sjkim# define ASN1_F_D2I_ASN1_SET                              148
1254280297Sjkim# define ASN1_F_D2I_ASN1_TYPE_BYTES                       149
1255280297Sjkim# define ASN1_F_D2I_ASN1_UINTEGER                         150
1256280297Sjkim# define ASN1_F_D2I_ASN1_UTCTIME                          151
1257280297Sjkim# define ASN1_F_D2I_AUTOPRIVATEKEY                        207
1258280297Sjkim# define ASN1_F_D2I_NETSCAPE_RSA                          152
1259280297Sjkim# define ASN1_F_D2I_NETSCAPE_RSA_2                        153
1260280297Sjkim# define ASN1_F_D2I_PRIVATEKEY                            154
1261280297Sjkim# define ASN1_F_D2I_PUBLICKEY                             155
1262280297Sjkim# define ASN1_F_D2I_RSA_NET                               200
1263280297Sjkim# define ASN1_F_D2I_RSA_NET_2                             201
1264280297Sjkim# define ASN1_F_D2I_X509                                  156
1265280297Sjkim# define ASN1_F_D2I_X509_CINF                             157
1266280297Sjkim# define ASN1_F_D2I_X509_PKEY                             159
1267280297Sjkim# define ASN1_F_I2D_ASN1_BIO_STREAM                       211
1268280297Sjkim# define ASN1_F_I2D_ASN1_SET                              188
1269280297Sjkim# define ASN1_F_I2D_ASN1_TIME                             160
1270280297Sjkim# define ASN1_F_I2D_DSA_PUBKEY                            161
1271280297Sjkim# define ASN1_F_I2D_EC_PUBKEY                             181
1272280297Sjkim# define ASN1_F_I2D_PRIVATEKEY                            163
1273280297Sjkim# define ASN1_F_I2D_PUBLICKEY                             164
1274280297Sjkim# define ASN1_F_I2D_RSA_NET                               162
1275280297Sjkim# define ASN1_F_I2D_RSA_PUBKEY                            165
1276280297Sjkim# define ASN1_F_LONG_C2I                                  166
1277280297Sjkim# define ASN1_F_OID_MODULE_INIT                           174
1278280297Sjkim# define ASN1_F_PARSE_TAGGING                             182
1279280297Sjkim# define ASN1_F_PKCS5_PBE2_SET_IV                         167
1280280297Sjkim# define ASN1_F_PKCS5_PBE_SET                             202
1281280297Sjkim# define ASN1_F_PKCS5_PBE_SET0_ALGOR                      215
1282280297Sjkim# define ASN1_F_PKCS5_PBKDF2_SET                          219
1283280297Sjkim# define ASN1_F_SMIME_READ_ASN1                           212
1284280297Sjkim# define ASN1_F_SMIME_TEXT                                213
1285280297Sjkim# define ASN1_F_X509_CINF_NEW                             168
1286280297Sjkim# define ASN1_F_X509_CRL_ADD0_REVOKED                     169
1287280297Sjkim# define ASN1_F_X509_INFO_NEW                             170
1288280297Sjkim# define ASN1_F_X509_NAME_ENCODE                          203
1289280297Sjkim# define ASN1_F_X509_NAME_EX_D2I                          158
1290280297Sjkim# define ASN1_F_X509_NAME_EX_NEW                          171
1291280297Sjkim# define ASN1_F_X509_NEW                                  172
1292280297Sjkim# define ASN1_F_X509_PKEY_NEW                             173
129355714Skris
129455714Skris/* Reason codes. */
1295280297Sjkim# define ASN1_R_ADDING_OBJECT                             171
1296280297Sjkim# define ASN1_R_ASN1_PARSE_ERROR                          203
1297280297Sjkim# define ASN1_R_ASN1_SIG_PARSE_ERROR                      204
1298280297Sjkim# define ASN1_R_AUX_ERROR                                 100
1299280297Sjkim# define ASN1_R_BAD_CLASS                                 101
1300280297Sjkim# define ASN1_R_BAD_OBJECT_HEADER                         102
1301280297Sjkim# define ASN1_R_BAD_PASSWORD_READ                         103
1302280297Sjkim# define ASN1_R_BAD_TAG                                   104
1303280297Sjkim# define ASN1_R_BMPSTRING_IS_WRONG_LENGTH                 214
1304280297Sjkim# define ASN1_R_BN_LIB                                    105
1305280297Sjkim# define ASN1_R_BOOLEAN_IS_WRONG_LENGTH                   106
1306280297Sjkim# define ASN1_R_BUFFER_TOO_SMALL                          107
1307280297Sjkim# define ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER           108
1308280297Sjkim# define ASN1_R_CONTEXT_NOT_INITIALISED                   217
1309280297Sjkim# define ASN1_R_DATA_IS_WRONG                             109
1310280297Sjkim# define ASN1_R_DECODE_ERROR                              110
1311280297Sjkim# define ASN1_R_DECODING_ERROR                            111
1312280297Sjkim# define ASN1_R_DEPTH_EXCEEDED                            174
1313280297Sjkim# define ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED         198
1314280297Sjkim# define ASN1_R_ENCODE_ERROR                              112
1315280297Sjkim# define ASN1_R_ERROR_GETTING_TIME                        173
1316280297Sjkim# define ASN1_R_ERROR_LOADING_SECTION                     172
1317280297Sjkim# define ASN1_R_ERROR_PARSING_SET_ELEMENT                 113
1318280297Sjkim# define ASN1_R_ERROR_SETTING_CIPHER_PARAMS               114
1319280297Sjkim# define ASN1_R_EXPECTING_AN_INTEGER                      115
1320280297Sjkim# define ASN1_R_EXPECTING_AN_OBJECT                       116
1321280297Sjkim# define ASN1_R_EXPECTING_A_BOOLEAN                       117
1322280297Sjkim# define ASN1_R_EXPECTING_A_TIME                          118
1323280297Sjkim# define ASN1_R_EXPLICIT_LENGTH_MISMATCH                  119
1324280297Sjkim# define ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED              120
1325280297Sjkim# define ASN1_R_FIELD_MISSING                             121
1326280297Sjkim# define ASN1_R_FIRST_NUM_TOO_LARGE                       122
1327280297Sjkim# define ASN1_R_HEADER_TOO_LONG                           123
1328280297Sjkim# define ASN1_R_ILLEGAL_BITSTRING_FORMAT                  175
1329280297Sjkim# define ASN1_R_ILLEGAL_BOOLEAN                           176
1330280297Sjkim# define ASN1_R_ILLEGAL_CHARACTERS                        124
1331280297Sjkim# define ASN1_R_ILLEGAL_FORMAT                            177
1332280297Sjkim# define ASN1_R_ILLEGAL_HEX                               178
1333280297Sjkim# define ASN1_R_ILLEGAL_IMPLICIT_TAG                      179
1334280297Sjkim# define ASN1_R_ILLEGAL_INTEGER                           180
1335280297Sjkim# define ASN1_R_ILLEGAL_NESTED_TAGGING                    181
1336280297Sjkim# define ASN1_R_ILLEGAL_NULL                              125
1337280297Sjkim# define ASN1_R_ILLEGAL_NULL_VALUE                        182
1338280297Sjkim# define ASN1_R_ILLEGAL_OBJECT                            183
1339280297Sjkim# define ASN1_R_ILLEGAL_OPTIONAL_ANY                      126
1340280297Sjkim# define ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE          170
1341280297Sjkim# define ASN1_R_ILLEGAL_TAGGED_ANY                        127
1342280297Sjkim# define ASN1_R_ILLEGAL_TIME_VALUE                        184
1343280297Sjkim# define ASN1_R_INTEGER_NOT_ASCII_FORMAT                  185
1344280297Sjkim# define ASN1_R_INTEGER_TOO_LARGE_FOR_LONG                128
1345280297Sjkim# define ASN1_R_INVALID_BIT_STRING_BITS_LEFT              220
1346280297Sjkim# define ASN1_R_INVALID_BMPSTRING_LENGTH                  129
1347280297Sjkim# define ASN1_R_INVALID_DIGIT                             130
1348280297Sjkim# define ASN1_R_INVALID_MIME_TYPE                         205
1349280297Sjkim# define ASN1_R_INVALID_MODIFIER                          186
1350280297Sjkim# define ASN1_R_INVALID_NUMBER                            187
1351280297Sjkim# define ASN1_R_INVALID_OBJECT_ENCODING                   216
1352280297Sjkim# define ASN1_R_INVALID_SEPARATOR                         131
1353280297Sjkim# define ASN1_R_INVALID_TIME_FORMAT                       132
1354280297Sjkim# define ASN1_R_INVALID_UNIVERSALSTRING_LENGTH            133
1355280297Sjkim# define ASN1_R_INVALID_UTF8STRING                        134
1356280297Sjkim# define ASN1_R_IV_TOO_LARGE                              135
1357280297Sjkim# define ASN1_R_LENGTH_ERROR                              136
1358280297Sjkim# define ASN1_R_LIST_ERROR                                188
1359280297Sjkim# define ASN1_R_MIME_NO_CONTENT_TYPE                      206
1360280297Sjkim# define ASN1_R_MIME_PARSE_ERROR                          207
1361280297Sjkim# define ASN1_R_MIME_SIG_PARSE_ERROR                      208
1362280297Sjkim# define ASN1_R_MISSING_EOC                               137
1363280297Sjkim# define ASN1_R_MISSING_SECOND_NUMBER                     138
1364280297Sjkim# define ASN1_R_MISSING_VALUE                             189
1365280297Sjkim# define ASN1_R_MSTRING_NOT_UNIVERSAL                     139
1366280297Sjkim# define ASN1_R_MSTRING_WRONG_TAG                         140
1367280297Sjkim# define ASN1_R_NESTED_ASN1_STRING                        197
1368280297Sjkim# define ASN1_R_NON_HEX_CHARACTERS                        141
1369280297Sjkim# define ASN1_R_NOT_ASCII_FORMAT                          190
1370280297Sjkim# define ASN1_R_NOT_ENOUGH_DATA                           142
1371280297Sjkim# define ASN1_R_NO_CONTENT_TYPE                           209
1372280297Sjkim# define ASN1_R_NO_DEFAULT_DIGEST                         201
1373280297Sjkim# define ASN1_R_NO_MATCHING_CHOICE_TYPE                   143
1374280297Sjkim# define ASN1_R_NO_MULTIPART_BODY_FAILURE                 210
1375280297Sjkim# define ASN1_R_NO_MULTIPART_BOUNDARY                     211
1376280297Sjkim# define ASN1_R_NO_SIG_CONTENT_TYPE                       212
1377280297Sjkim# define ASN1_R_NULL_IS_WRONG_LENGTH                      144
1378280297Sjkim# define ASN1_R_OBJECT_NOT_ASCII_FORMAT                   191
1379280297Sjkim# define ASN1_R_ODD_NUMBER_OF_CHARS                       145
1380280297Sjkim# define ASN1_R_PRIVATE_KEY_HEADER_MISSING                146
1381280297Sjkim# define ASN1_R_SECOND_NUMBER_TOO_LARGE                   147
1382280297Sjkim# define ASN1_R_SEQUENCE_LENGTH_MISMATCH                  148
1383280297Sjkim# define ASN1_R_SEQUENCE_NOT_CONSTRUCTED                  149
1384280297Sjkim# define ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG              192
1385280297Sjkim# define ASN1_R_SHORT_LINE                                150
1386280297Sjkim# define ASN1_R_SIG_INVALID_MIME_TYPE                     213
1387280297Sjkim# define ASN1_R_STREAMING_NOT_SUPPORTED                   202
1388280297Sjkim# define ASN1_R_STRING_TOO_LONG                           151
1389280297Sjkim# define ASN1_R_STRING_TOO_SHORT                          152
1390280297Sjkim# define ASN1_R_TAG_VALUE_TOO_HIGH                        153
1391280297Sjkim# define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 154
1392280297Sjkim# define ASN1_R_TIME_NOT_ASCII_FORMAT                     193
1393280297Sjkim# define ASN1_R_TOO_LONG                                  155
1394280297Sjkim# define ASN1_R_TYPE_NOT_CONSTRUCTED                      156
1395280297Sjkim# define ASN1_R_TYPE_NOT_PRIMITIVE                        218
1396280297Sjkim# define ASN1_R_UNABLE_TO_DECODE_RSA_KEY                  157
1397280297Sjkim# define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY          158
1398280297Sjkim# define ASN1_R_UNEXPECTED_EOC                            159
1399280297Sjkim# define ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH           215
1400280297Sjkim# define ASN1_R_UNKNOWN_FORMAT                            160
1401280297Sjkim# define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM          161
1402280297Sjkim# define ASN1_R_UNKNOWN_OBJECT_TYPE                       162
1403280297Sjkim# define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE                   163
1404280297Sjkim# define ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM               199
1405280297Sjkim# define ASN1_R_UNKNOWN_TAG                               194
1406280297Sjkim# define ASN1_R_UNKOWN_FORMAT                             195
1407280297Sjkim# define ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE           164
1408280297Sjkim# define ASN1_R_UNSUPPORTED_CIPHER                        165
1409280297Sjkim# define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM          166
1410280297Sjkim# define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE               167
1411280297Sjkim# define ASN1_R_UNSUPPORTED_TYPE                          196
1412280297Sjkim# define ASN1_R_WRONG_PUBLIC_KEY_TYPE                     200
1413280297Sjkim# define ASN1_R_WRONG_TAG                                 168
1414280297Sjkim# define ASN1_R_WRONG_TYPE                                169
141555714Skris
141655714Skris#ifdef  __cplusplus
141755714Skris}
141855714Skris#endif
141955714Skris#endif
1420