asn1.h revision 296341
125450Speter/* crypto/asn1/asn1.h */
250476Speter/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
325450Speter * All rights reserved.
425450Speter *
525450Speter * This package is an SSL implementation written
625450Speter * by Eric Young (eay@cryptsoft.com).
725450Speter * The implementation was written so as to conform with Netscapes SSL.
825450Speter *
925450Speter * This library is free for commercial and non-commercial use as long as
1025450Speter * the following conditions are aheared to.  The following conditions
1125450Speter * apply to all code found in this distribution, be it the RC4, RSA,
1225450Speter * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
1325450Speter * included with this distribution is covered by the same copyright terms
1425450Speter * except that the holder is Tim Hudson (tjh@cryptsoft.com).
1525450Speter *
1625450Speter * Copyright remains Eric Young's, and as such any Copyright notices in
1725450Speter * the code are not to be removed.
1825450Speter * If this package is used in a product, Eric Young should be given attribution
1925450Speter * as the author of the parts of the library used.
2025450Speter * This can be in the form of a textual message at program startup or
2125450Speter * in documentation (online or textual) provided with the package.
2225450Speter *
2325450Speter * Redistribution and use in source and binary forms, with or without
2425450Speter * modification, are permitted provided that the following conditions
2525450Speter * are met:
2625450Speter * 1. Redistributions of source code must retain the copyright
2725450Speter *    notice, this list of conditions and the following disclaimer.
2825450Speter * 2. Redistributions in binary form must reproduce the above copyright
2925450Speter *    notice, this list of conditions and the following disclaimer in the
3025450Speter *    documentation and/or other materials provided with the distribution.
3125450Speter * 3. All advertising materials mentioning features or use of this software
3225450Speter *    must display the following acknowledgement:
3325450Speter *    "This product includes cryptographic software written by
3425450Speter *     Eric Young (eay@cryptsoft.com)"
3525450Speter *    The word 'cryptographic' can be left out if the rouines from the library
3625450Speter *    being used are not cryptographic related :-).
3725450Speter * 4. If you include any Windows specific code (or a derivative thereof) from
3825450Speter *    the apps directory (application code) you must include an acknowledgement:
3925450Speter *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
4025450Speter *
4125450Speter * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
4225450Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4325450Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4425450Speter * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
4525450Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
4625450Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
4725450Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4825450Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4925450Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5025450Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5125450Speter * SUCH DAMAGE.
5225450Speter *
5325450Speter * The licence and distribution terms for any publically available version or
5425450Speter * derivative of this code cannot be changed.  i.e. this code cannot simply be
5525450Speter * copied and put under another distribution licence
5625450Speter * [including the GNU Public Licence.]
5725450Speter */
5825450Speter
5925450Speter#ifndef HEADER_ASN1_H
6025450Speter# define HEADER_ASN1_H
6125450Speter
6225450Speter# include <time.h>
6325450Speter# include <openssl/e_os2.h>
6425450Speter# ifndef OPENSSL_NO_BIO
6525450Speter#  include <openssl/bio.h>
6625450Speter# endif
6725450Speter# include <openssl/stack.h>
6825450Speter# include <openssl/safestack.h>
6925450Speter
7025450Speter# include <openssl/symhacks.h>
7125450Speter
7225450Speter# include <openssl/ossl_typ.h>
7325450Speter# ifndef OPENSSL_NO_DEPRECATED
7425450Speter#  include <openssl/bn.h>
7525450Speter# endif
7625450Speter
7725450Speter# ifdef OPENSSL_BUILD_SHLIBCRYPTO
7825450Speter#  undef OPENSSL_EXTERN
7925450Speter#  define OPENSSL_EXTERN OPENSSL_EXPORT
8025450Speter# endif
8125450Speter
8225450Speter#ifdef  __cplusplus
8325450Speterextern "C" {
8425450Speter#endif
8525450Speter
8625450Speter# define V_ASN1_UNIVERSAL                0x00
8725450Speter# define V_ASN1_APPLICATION              0x40
8825450Speter# define V_ASN1_CONTEXT_SPECIFIC         0x80
8925450Speter# define V_ASN1_PRIVATE                  0xc0
9025450Speter
9125450Speter# define V_ASN1_CONSTRUCTED              0x20
9295005Simp# define V_ASN1_PRIMITIVE_TAG            0x1f
9395005Simp# define V_ASN1_PRIMATIVE_TAG            0x1f
94114164Ssam
9595005Simp# define V_ASN1_APP_CHOOSE               -2/* let the recipient choose */
9695005Simp# define V_ASN1_OTHER                    -3/* used in ASN1_TYPE */
9795005Simp# define V_ASN1_ANY                      -4/* used in ASN1 template code */
9895005Simp
9925450Speter# define V_ASN1_NEG                      0x100/* negative flag */
10095005Simp
10195005Simp# define V_ASN1_UNDEF                    -1
10295005Simp# define V_ASN1_EOC                      0
10395005Simp# define V_ASN1_BOOLEAN                  1 /**/
10477385Sphk# define V_ASN1_INTEGER                  2
105178354Ssam# define V_ASN1_NEG_INTEGER              (2 | V_ASN1_NEG)
106178354Ssam# define V_ASN1_BIT_STRING               3
107178354Ssam# define V_ASN1_OCTET_STRING             4
108178354Ssam# define V_ASN1_NULL                     5
109178354Ssam# define V_ASN1_OBJECT                   6
110138593Ssam# define V_ASN1_OBJECT_DESCRIPTOR        7
111139494Ssam# define V_ASN1_EXTERNAL                 8
11225450Speter# define V_ASN1_REAL                     9
11325450Speter# define V_ASN1_ENUMERATED               10
11425450Speter# define V_ASN1_NEG_ENUMERATED           (10 | V_ASN1_NEG)
11525450Speter# define V_ASN1_UTF8STRING               12
11625450Speter# define V_ASN1_SEQUENCE                 16
11725450Speter# define V_ASN1_SET                      17
11825450Speter# define V_ASN1_NUMERICSTRING            18 /**/
11925450Speter# define V_ASN1_PRINTABLESTRING          19
12025450Speter# define V_ASN1_T61STRING                20
12125450Speter# define V_ASN1_TELETEXSTRING            20/* alias */
12225450Speter# define V_ASN1_VIDEOTEXSTRING           21 /**/
12325450Speter# define V_ASN1_IA5STRING                22
12425450Speter# define V_ASN1_UTCTIME                  23
12525450Speter# define V_ASN1_GENERALIZEDTIME          24 /**/
12625450Speter# define V_ASN1_GRAPHICSTRING            25 /**/
12725450Speter# define V_ASN1_ISO64STRING              26 /**/
12825450Speter# define V_ASN1_VISIBLESTRING            26/* alias */
12925450Speter# define V_ASN1_GENERALSTRING            27 /**/
13025450Speter# define V_ASN1_UNIVERSALSTRING          28 /**/
13125450Speter# define V_ASN1_BMPSTRING                30
13225450Speter/* For use with d2i_ASN1_type_bytes() */
13325450Speter# define B_ASN1_NUMERICSTRING    0x0001
13425450Speter# define B_ASN1_PRINTABLESTRING  0x0002
13525450Speter# define B_ASN1_T61STRING        0x0004
13625450Speter# define B_ASN1_TELETEXSTRING    0x0004
13725450Speter# define B_ASN1_VIDEOTEXSTRING   0x0008
13825450Speter# define B_ASN1_IA5STRING        0x0010
13925450Speter# define B_ASN1_GRAPHICSTRING    0x0020
14077385Sphk# define B_ASN1_ISO64STRING      0x0040
14125450Speter# define B_ASN1_VISIBLESTRING    0x0040
14225450Speter# define B_ASN1_GENERALSTRING    0x0080
14325450Speter# define B_ASN1_UNIVERSALSTRING  0x0100
14477385Sphk# define B_ASN1_OCTET_STRING     0x0200
14525450Speter# define B_ASN1_BIT_STRING       0x0400
14625450Speter# define B_ASN1_BMPSTRING        0x0800
14725450Speter# define B_ASN1_UNKNOWN          0x1000
14877385Sphk# define B_ASN1_UTF8STRING       0x2000
14977385Sphk# define B_ASN1_UTCTIME          0x4000
15025450Speter# define B_ASN1_GENERALIZEDTIME  0x8000
15177385Sphk# define B_ASN1_SEQUENCE         0x10000
15225450Speter/* For use with ASN1_mbstring_copy() */
15325450Speter# define MBSTRING_FLAG           0x1000
154161536Sthomas# define MBSTRING_UTF8           (MBSTRING_FLAG)
15525450Speter# define MBSTRING_ASC            (MBSTRING_FLAG|1)
15625450Speter# define MBSTRING_BMP            (MBSTRING_FLAG|2)
15725450Speter# define MBSTRING_UNIV           (MBSTRING_FLAG|4)
15825450Speter# define SMIME_OLDMIME           0x400
15925450Speter# define SMIME_CRLFEOL           0x800
16025450Speter# define SMIME_STREAM            0x1000
16125450Speter    struct X509_algor_st;
16225450SpeterDECLARE_STACK_OF(X509_ALGOR)
16325450Speter
16425450Speter# define DECLARE_ASN1_SET_OF(type)/* filled in by mkstack.pl */
16525450Speter# define IMPLEMENT_ASN1_SET_OF(type)/* nothing, no longer needed */
16625450Speter
16725450Speter/*
168114232Sharti * We MUST make sure that, except for constness, asn1_ctx_st and
16977217Sphk * asn1_const_ctx are exactly the same.  Fortunately, as soon as the old ASN1
170178354Ssam * parsing macros are gone, we can throw this away as well...
171178354Ssam */
172178354Ssamtypedef struct asn1_ctx_st {
173178354Ssam    unsigned char *p;           /* work char pointer */
174178354Ssam    int eos;                    /* end of sequence read for indefinite
175178354Ssam                                 * encoding */
176178354Ssam    int error;                  /* error code to use when returning an error */
17777217Sphk    int inf;                    /* constructed if 0x20, indefinite is 0x21 */
17877217Sphk    int tag;                    /* tag from last 'get object' */
17925450Speter    int xclass;                 /* class from last 'get object' */
18085853Syar    long slen;                  /* length of last 'get object' */
18125450Speter    unsigned char *max;         /* largest value of p allowed */
18225450Speter    unsigned char *q;           /* temporary variable */
18377385Sphk    unsigned char **pp;         /* variable */
18477385Sphk    int line;                   /* used in error processing */
18525450Speter} ASN1_CTX;
18677385Sphk
18777385Sphktypedef struct asn1_const_ctx_st {
18877385Sphk    const unsigned char *p;     /* work char pointer */
18925450Speter    int eos;                    /* end of sequence read for indefinite
19025450Speter                                 * encoding */
19125450Speter    int error;                  /* error code to use when returning an error */
19225450Speter    int inf;                    /* constructed if 0x20, indefinite is 0x21 */
19325450Speter    int tag;                    /* tag from last 'get object' */
19425450Speter    int xclass;                 /* class from last 'get object' */
195170531Ssam    long slen;                  /* length of last 'get object' */
196170531Ssam    const unsigned char *max;   /* largest value of p allowed */
19725450Speter    const unsigned char *q;     /* temporary variable */
198140913Sambrisko    const unsigned char **pp;   /* variable */
199140913Sambrisko    int line;                   /* used in error processing */
20025450Speter} ASN1_const_CTX;
201140913Sambrisko
202140913Sambrisko/*
203140913Sambrisko * These are used internally in the ASN1_OBJECT to keep track of whether the
204140913Sambrisko * names and data need to be free()ed
20525450Speter */
206140913Sambrisko# define ASN1_OBJECT_FLAG_DYNAMIC         0x01/* internal use */
207140913Sambrisko# define ASN1_OBJECT_FLAG_CRITICAL        0x02/* critical x509v3 object id */
208140913Sambrisko# define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04/* internal use */
209140913Sambrisko# define ASN1_OBJECT_FLAG_DYNAMIC_DATA    0x08/* internal use */
210140913Sambriskotypedef struct asn1_object_st {
211140913Sambrisko    const char *sn, *ln;
212140913Sambrisko    int nid;
21325450Speter    int length;
214140913Sambrisko    const unsigned char *data;  /* data remains const after init */
215140913Sambrisko    int flags;                  /* Should we free this one */
216140913Sambrisko} ASN1_OBJECT;
21725450Speter
218140913Sambrisko# define ASN1_STRING_FLAG_BITS_LEFT 0x08/* Set if 0x07 has bits left value */
219140913Sambrisko/*
22025450Speter * This indicates that the ASN1_STRING is not a real value but just a place
221140913Sambrisko * holder for the location where indefinite length constructed data should be
222140913Sambrisko * inserted in the memory buffer
223140913Sambrisko */
224140913Sambrisko# define ASN1_STRING_FLAG_NDEF 0x010
225140913Sambrisko
226140913Sambrisko/*
227140913Sambrisko * This flag is used by the CMS code to indicate that a string is not
228140913Sambrisko * complete and is a place holder for content when it had all been accessed.
229140913Sambrisko * The flag will be reset when content has been written to it.
230140913Sambrisko */
231140913Sambrisko
232140913Sambrisko# define ASN1_STRING_FLAG_CONT 0x020
23325450Speter/*
23425450Speter * This flag is used by ASN1 code to indicate an ASN1_STRING is an MSTRING
235140913Sambrisko * type.
236140913Sambrisko */
23725450Speter# define ASN1_STRING_FLAG_MSTRING 0x040
238140913Sambrisko/* This is the base type that holds just about everything :-) */
239140913Sambriskostruct asn1_string_st {
240140913Sambrisko    int length;
241140913Sambrisko    int type;
242140913Sambrisko    unsigned char *data;
243140913Sambrisko    /*
244140913Sambrisko     * The value of the following field depends on the type being held.  It
245154240Sambrisko     * is mostly being used for BIT_STRING so if the input data has a
246140913Sambrisko     * non-zero 'unused bits' value, it will be handled correctly
247140913Sambrisko     */
248140913Sambrisko    long flags;
249140913Sambrisko};
250140913Sambrisko
251140913Sambrisko/*
252140913Sambrisko * ASN1_ENCODING structure: this is used to save the received encoding of an
253140913Sambrisko * ASN1 type. This is useful to get round problems with invalid encodings
254140913Sambrisko * which can break signatures.
255140913Sambrisko */
256140913Sambrisko
257140913Sambriskotypedef struct ASN1_ENCODING_st {
258140913Sambrisko    unsigned char *enc;         /* DER encoding */
259140913Sambrisko    long len;                   /* Length of encoding */
260170531Ssam    int modified;               /* set to 1 if 'enc' is invalid */
261140913Sambrisko} ASN1_ENCODING;
26225450Speter
26325450Speter/* Used with ASN1 LONG type: if a long is set to this it is omitted */
26425450Speter# define ASN1_LONG_UNDEF 0x7fffffffL
26525450Speter
26625450Speter# define STABLE_FLAGS_MALLOC     0x01
26725450Speter# define STABLE_NO_MASK          0x02
26825450Speter# define DIRSTRING_TYPE  \
26925450Speter (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_BMPSTRING|B_ASN1_UTF8STRING)
27025450Speter# define PKCS9STRING_TYPE (DIRSTRING_TYPE|B_ASN1_IA5STRING)
271140913Sambrisko
27225450Spetertypedef struct asn1_string_table_st {
27325450Speter    int nid;
274140913Sambrisko    long minsize;
275140913Sambrisko    long maxsize;
27625450Speter    unsigned long mask;
277140913Sambrisko    unsigned long flags;
278140913Sambrisko} ASN1_STRING_TABLE;
279140913Sambrisko
280140913SambriskoDECLARE_STACK_OF(ASN1_STRING_TABLE)
281140913Sambrisko
282140913Sambrisko/* size limits: this stuff is taken straight from RFC2459 */
28325450Speter
28425450Speter# define ub_name                         32768
285138593Ssam# define ub_common_name                  64
28695005Simp# define ub_locality_name                128
28725450Speter# define ub_state_name                   128
28825450Speter# define ub_organization_name            64
28925450Speter# define ub_organization_unit_name       64
29025450Speter# define ub_title                        64
29125450Speter# define ub_email_address                128
292138593Ssam
29395005Simp/*
29425450Speter * Declarations for template structures: for full definitions see asn1t.h
29525450Speter */
29625450Spetertypedef struct ASN1_TEMPLATE_st ASN1_TEMPLATE;
29725450Spetertypedef struct ASN1_TLC_st ASN1_TLC;
29825450Speter/* This is just an opaque pointer */
29925450Spetertypedef struct ASN1_VALUE_st ASN1_VALUE;
30095005Simp
30125450Speter/* Declare ASN1 functions: the implement macro in in asn1t.h */
302140913Sambrisko
303140913Sambrisko# define DECLARE_ASN1_FUNCTIONS(type) DECLARE_ASN1_FUNCTIONS_name(type, type)
30425450Speter
305170531Ssam# define DECLARE_ASN1_ALLOC_FUNCTIONS(type) \
30625450Speter        DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, type)
307140913Sambrisko
30825450Speter# define DECLARE_ASN1_FUNCTIONS_name(type, name) \
30925450Speter        DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \
310140913Sambrisko        DECLARE_ASN1_ENCODE_FUNCTIONS(type, name, name)
31125450Speter
31225450Speter# define DECLARE_ASN1_FUNCTIONS_fname(type, itname, name) \
313165359Sjkim        DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \
314165359Sjkim        DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name)
315165359Sjkim
316165359Sjkim# define DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) \
317165359Sjkim        type *d2i_##name(type **a, const unsigned char **in, long len); \
31825450Speter        int i2d_##name(type *a, unsigned char **out); \
319165359Sjkim        DECLARE_ASN1_ITEM(itname)
320140913Sambrisko
321140913Sambrisko# define DECLARE_ASN1_ENCODE_FUNCTIONS_const(type, name) \
32225450Speter        type *d2i_##name(type **a, const unsigned char **in, long len); \
32325450Speter        int i2d_##name(const type *a, unsigned char **out); \
324166113Smarius        DECLARE_ASN1_ITEM(name)
325166113Smarius
326166113Smarius# define DECLARE_ASN1_NDEF_FUNCTION(name) \
327166113Smarius        int i2d_##name##_NDEF(name *a, unsigned char **out);
328166113Smarius
329114164Ssam# define DECLARE_ASN1_FUNCTIONS_const(name) \
330170531Ssam        DECLARE_ASN1_ALLOC_FUNCTIONS(name) \
331166113Smarius        DECLARE_ASN1_ENCODE_FUNCTIONS_const(name, name)
332166113Smarius
333194799Sdelphij# define DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \
334166113Smarius        type *name##_new(void); \
335166113Smarius        void name##_free(type *a);
336166113Smarius
337166113Smarius# define DECLARE_ASN1_PRINT_FUNCTION(stname) \
338166113Smarius        DECLARE_ASN1_PRINT_FUNCTION_fname(stname, stname)
339166113Smarius
340166113Smarius# define DECLARE_ASN1_PRINT_FUNCTION_fname(stname, fname) \
341166113Smarius        int fname##_print_ctx(BIO *out, stname *x, int indent, \
342166113Smarius                                         const ASN1_PCTX *pctx);
343138593Ssam
344114164Ssam# define D2I_OF(type) type *(*)(type **,const unsigned char **,long)
345114164Ssam# define I2D_OF(type) int (*)(type *,unsigned char **)
346140913Sambrisko# define I2D_OF_const(type) int (*)(const type *,unsigned char **)
347140913Sambrisko
348114164Ssam# define CHECKED_D2I_OF(type, d2i) \
349170531Ssam    ((d2i_of_void*) (1 ? d2i : ((D2I_OF(type))0)))
350114164Ssam# define CHECKED_I2D_OF(type, i2d) \
351140913Sambrisko    ((i2d_of_void*) (1 ? i2d : ((I2D_OF(type))0)))
352114164Ssam# define CHECKED_NEW_OF(type, xnew) \
353114164Ssam    ((void *(*)(void)) (1 ? xnew : ((type *(*)(void))0)))
354140913Sambrisko# define CHECKED_PTR_OF(type, p) \
355114164Ssam    ((void*) (1 ? p : (type*)0))
356140913Sambrisko# define CHECKED_PPTR_OF(type, p) \
357140913Sambrisko    ((void**) (1 ? p : (type**)0))
358114164Ssam
359114164Ssam# define TYPEDEF_D2I_OF(type) typedef type *d2i_of_##type(type **,const unsigned char **,long)
36025450Speter# define TYPEDEF_I2D_OF(type) typedef int i2d_of_##type(type *,unsigned char **)
36125450Speter# define TYPEDEF_D2I2D_OF(type) TYPEDEF_D2I_OF(type); TYPEDEF_I2D_OF(type)
36225450Speter
36325450SpeterTYPEDEF_D2I2D_OF(void);
36425450Speter
36525450Speter/*-
36625450Speter * The following macros and typedefs allow an ASN1_ITEM
36725450Speter * to be embedded in a structure and referenced. Since
36825450Speter * the ASN1_ITEM pointers need to be globally accessible
36925450Speter * (possibly from shared libraries) they may exist in
37025450Speter * different forms. On platforms that support it the
37125450Speter * ASN1_ITEM structure itself will be globally exported.
37225450Speter * Other platforms will export a function that returns
37325450Speter * an ASN1_ITEM pointer.
37425450Speter *
37525450Speter * To handle both cases transparently the macros below
37625450Speter * should be used instead of hard coding an ASN1_ITEM
37725450Speter * pointer in a structure.
37825450Speter *
37925450Speter * The structure will look like this:
38025450Speter *
38125450Speter * typedef struct SOMETHING_st {
38225450Speter *      ...
38325450Speter *      ASN1_ITEM_EXP *iptr;
38425450Speter *      ...
38525450Speter * } SOMETHING;
38625450Speter *
38725450Speter * It would be initialised as e.g.:
38825450Speter *
38925450Speter * SOMETHING somevar = {...,ASN1_ITEM_ref(X509),...};
39025450Speter *
39125450Speter * and the actual pointer extracted with:
39225450Speter *
39325450Speter * const ASN1_ITEM *it = ASN1_ITEM_ptr(somevar.iptr);
39477217Sphk *
39577217Sphk * Finally an ASN1_ITEM pointer can be extracted from an
39677217Sphk * appropriate reference with: ASN1_ITEM_rptr(X509). This
39777217Sphk * would be used when a function takes an ASN1_ITEM * argument.
39877217Sphk *
39977217Sphk */
40077217Sphk
40177217Sphk# ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
40277217Sphk
403114164Ssam/* ASN1_ITEM pointer exported type */
404114164Ssamtypedef const ASN1_ITEM ASN1_ITEM_EXP;
405114164Ssam
406116820Ssam/* Macro to obtain ASN1_ITEM pointer from exported type */
407116820Ssam#  define ASN1_ITEM_ptr(iptr) (iptr)
408116820Ssam
409114232Sharti/* Macro to include ASN1_ITEM pointer from base type */
410114232Sharti#  define ASN1_ITEM_ref(iptr) (&(iptr##_it))
411114232Sharti
412114232Sharti#  define ASN1_ITEM_rptr(ref) (&(ref##_it))
413114232Sharti
414114232Sharti#  define DECLARE_ASN1_ITEM(name) \
415114232Sharti        OPENSSL_EXTERN const ASN1_ITEM name##_it;
416114232Sharti
417114232Sharti# else
41825450Speter
41925450Speter/*
42025450Speter * Platforms that can't easily handle shared global variables are declared as
42125450Speter * functions returning ASN1_ITEM pointers.
42225450Speter */
42325450Speter
42425450Speter/* ASN1_ITEM pointer exported type */
42525450Spetertypedef const ASN1_ITEM *ASN1_ITEM_EXP (void);
42625450Speter
42725450Speter/* Macro to obtain ASN1_ITEM pointer from exported type */
42825450Speter#  define ASN1_ITEM_ptr(iptr) (iptr())
42925450Speter
43025450Speter/* Macro to include ASN1_ITEM pointer from base type */
43125450Speter#  define ASN1_ITEM_ref(iptr) (iptr##_it)
43225450Speter
43325450Speter#  define ASN1_ITEM_rptr(ref) (ref##_it())
43425450Speter
43525450Speter#  define DECLARE_ASN1_ITEM(name) \
436114164Ssam        const ASN1_ITEM * name##_it(void);
437114164Ssam
438114164Ssam# endif
439116820Ssam
44025450Speter/* Parameters used by ASN1_STRING_print_ex() */
44125450Speter
44225450Speter/*
44325450Speter * These determine which characters to escape: RFC2253 special characters,
44425450Speter * control characters and MSB set characters
44525450Speter */
44625450Speter
44725450Speter# define ASN1_STRFLGS_ESC_2253           1
44825450Speter# define ASN1_STRFLGS_ESC_CTRL           2
44925450Speter# define ASN1_STRFLGS_ESC_MSB            4
45025450Speter
45125450Speter/*
45225450Speter * This flag determines how we do escaping: normally RC2253 backslash only,
45325450Speter * set this to use backslash and quote.
45477217Sphk */
45525450Speter
45625450Speter# define ASN1_STRFLGS_ESC_QUOTE          8
457114164Ssam
458114164Ssam/* These three flags are internal use only. */
459114164Ssam
46025450Speter/* Character is a valid PrintableString character */
46125450Speter# define CHARTYPE_PRINTABLESTRING        0x10
46225450Speter/* Character needs escaping if it is the first character */
46325450Speter# define CHARTYPE_FIRST_ESC_2253         0x20
46425450Speter/* Character needs escaping if it is the last character */
46525450Speter# define CHARTYPE_LAST_ESC_2253          0x40
46625450Speter
46725450Speter/*
46825450Speter * NB the internal flags are safely reused below by flags handled at the top
46925450Speter * level.
47025450Speter */
47177217Sphk
47225450Speter/*
47325450Speter * If this is set we convert all character strings to UTF8 first
474114164Ssam */
475114164Ssam
476114164Ssam# define ASN1_STRFLGS_UTF8_CONVERT       0x10
47725450Speter
47825450Speter/*
47925450Speter * If this is set we don't attempt to interpret content: just assume all
48025450Speter * strings are 1 byte per character. This will produce some pretty odd
48125450Speter * looking output!
48225450Speter */
48325450Speter
48425450Speter# define ASN1_STRFLGS_IGNORE_TYPE        0x20
48525450Speter
48625450Speter/* If this is set we include the string type in the output */
48725450Speter# define ASN1_STRFLGS_SHOW_TYPE          0x40
48877217Sphk
48925450Speter/*
49025450Speter * This determines which strings to display and which to 'dump' (hex dump of
491114164Ssam * content octets or DER encoding). We can only dump non character strings or
492114164Ssam * everything. If we don't dump 'unknown' they are interpreted as character
493114164Ssam * strings with 1 octet per character and are subject to the usual escaping
49425450Speter * options.
49577217Sphk */
49677217Sphk
49777217Sphk# define ASN1_STRFLGS_DUMP_ALL           0x80
49877217Sphk# define ASN1_STRFLGS_DUMP_UNKNOWN       0x100
49977217Sphk
50077217Sphk/*
50177217Sphk * These determine what 'dumping' does, we can dump the content octets or the
50277217Sphk * DER encoding: both use the RFC2253 #XXXXX notation.
50377217Sphk */
50477217Sphk
50577217Sphk# define ASN1_STRFLGS_DUMP_DER           0x200
50677217Sphk
50777217Sphk/*
508114164Ssam * All the string flags consistent with RFC2253, escaping control characters
509114164Ssam * isn't essential in RFC2253 but it is advisable anyway.
510116820Ssam */
511114164Ssam
512114164Ssam# define ASN1_STRFLGS_RFC2253    (ASN1_STRFLGS_ESC_2253 | \
51377217Sphk                                ASN1_STRFLGS_ESC_CTRL | \
514114232Sharti                                ASN1_STRFLGS_ESC_MSB | \
515114232Sharti                                ASN1_STRFLGS_UTF8_CONVERT | \
516114232Sharti                                ASN1_STRFLGS_DUMP_UNKNOWN | \
517114232Sharti                                ASN1_STRFLGS_DUMP_DER)
518114232Sharti
519114232ShartiDECLARE_STACK_OF(ASN1_INTEGER)
520114232ShartiDECLARE_ASN1_SET_OF(ASN1_INTEGER)
521114232Sharti
522114232ShartiDECLARE_STACK_OF(ASN1_GENERALSTRING)
523114232Sharti
524114232Shartitypedef struct asn1_type_st {
525114232Sharti    int type;
526114232Sharti    union {
527114232Sharti        char *ptr;
528114232Sharti        ASN1_BOOLEAN boolean;
529114232Sharti        ASN1_STRING *asn1_string;
530114232Sharti        ASN1_OBJECT *object;
53125450Speter        ASN1_INTEGER *integer;
53225450Speter        ASN1_ENUMERATED *enumerated;
53325450Speter        ASN1_BIT_STRING *bit_string;
53495005Simp        ASN1_OCTET_STRING *octet_string;
53525450Speter        ASN1_PRINTABLESTRING *printablestring;
53625450Speter        ASN1_T61STRING *t61string;
53725450Speter        ASN1_IA5STRING *ia5string;
53825450Speter        ASN1_GENERALSTRING *generalstring;
53925450Speter        ASN1_BMPSTRING *bmpstring;
54025450Speter        ASN1_UNIVERSALSTRING *universalstring;
54125450Speter        ASN1_UTCTIME *utctime;
54225450Speter        ASN1_GENERALIZEDTIME *generalizedtime;
54325450Speter        ASN1_VISIBLESTRING *visiblestring;
54425450Speter        ASN1_UTF8STRING *utf8string;
54525450Speter        /*
54625450Speter         * set and sequence are left complete and still contain the set or
54725450Speter         * sequence bytes
54825450Speter         */
54925450Speter        ASN1_STRING *set;
55025450Speter        ASN1_STRING *sequence;
55125450Speter        ASN1_VALUE *asn1_value;
55225450Speter    } value;
55325450Speter} ASN1_TYPE;
554114164Ssam
55525450SpeterDECLARE_STACK_OF(ASN1_TYPE)
55625450SpeterDECLARE_ASN1_SET_OF(ASN1_TYPE)
55725450Speter
558114164Ssamtypedef STACK_OF(ASN1_TYPE) ASN1_SEQUENCE_ANY;
559114164Ssam
560114164SsamDECLARE_ASN1_ENCODE_FUNCTIONS_const(ASN1_SEQUENCE_ANY, ASN1_SEQUENCE_ANY)
561114164SsamDECLARE_ASN1_ENCODE_FUNCTIONS_const(ASN1_SEQUENCE_ANY, ASN1_SET_ANY)
562114164Ssam
563114164Ssamtypedef struct NETSCAPE_X509_st {
564114164Ssam    ASN1_OCTET_STRING *header;
565114164Ssam    X509 *cert;
566114164Ssam} NETSCAPE_X509;
567114164Ssam
568114164Ssam/* This is used to contain a list of bit names */
569114164Ssamtypedef struct BIT_STRING_BITNAME_st {
570114164Ssam    int bitnum;
571114164Ssam    const char *lname;
572114164Ssam    const char *sname;
573114164Ssam} BIT_STRING_BITNAME;
574114164Ssam
575114164Ssam# define M_ASN1_STRING_length(x) ((x)->length)
576114164Ssam# define M_ASN1_STRING_length_set(x, n)  ((x)->length = (n))
577114164Ssam# define M_ASN1_STRING_type(x)   ((x)->type)
578114164Ssam# define M_ASN1_STRING_data(x)   ((x)->data)
579114164Ssam
580114164Ssam/* Macros for string operations */
58195005Simp# define M_ASN1_BIT_STRING_new() (ASN1_BIT_STRING *)\
58225450Speter                ASN1_STRING_type_new(V_ASN1_BIT_STRING)
58325450Speter# define M_ASN1_BIT_STRING_free(a)       ASN1_STRING_free((ASN1_STRING *)a)
58425450Speter# define M_ASN1_BIT_STRING_dup(a) (ASN1_BIT_STRING *)\
58525450Speter                ASN1_STRING_dup((const ASN1_STRING *)a)
58625450Speter# define M_ASN1_BIT_STRING_cmp(a,b) ASN1_STRING_cmp(\
58725450Speter                (const ASN1_STRING *)a,(const ASN1_STRING *)b)
58825450Speter# define M_ASN1_BIT_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
58925450Speter
59025450Speter# define M_ASN1_INTEGER_new()    (ASN1_INTEGER *)\
59125450Speter                ASN1_STRING_type_new(V_ASN1_INTEGER)
59225450Speter# define M_ASN1_INTEGER_free(a)          ASN1_STRING_free((ASN1_STRING *)a)
59325450Speter# define M_ASN1_INTEGER_dup(a) (ASN1_INTEGER *)\
59425450Speter                ASN1_STRING_dup((const ASN1_STRING *)a)
59525450Speter# define M_ASN1_INTEGER_cmp(a,b) ASN1_STRING_cmp(\
59625450Speter                (const ASN1_STRING *)a,(const ASN1_STRING *)b)
59725450Speter
59825450Speter# define M_ASN1_ENUMERATED_new() (ASN1_ENUMERATED *)\
59925450Speter                ASN1_STRING_type_new(V_ASN1_ENUMERATED)
60025450Speter# define M_ASN1_ENUMERATED_free(a)       ASN1_STRING_free((ASN1_STRING *)a)
60125450Speter# define M_ASN1_ENUMERATED_dup(a) (ASN1_ENUMERATED *)\
60225450Speter                ASN1_STRING_dup((const ASN1_STRING *)a)
60325450Speter# define M_ASN1_ENUMERATED_cmp(a,b)      ASN1_STRING_cmp(\
60425450Speter                (const ASN1_STRING *)a,(const ASN1_STRING *)b)
60525450Speter
60625450Speter# define M_ASN1_OCTET_STRING_new()       (ASN1_OCTET_STRING *)\
60725450Speter                ASN1_STRING_type_new(V_ASN1_OCTET_STRING)
60825450Speter# define M_ASN1_OCTET_STRING_free(a)     ASN1_STRING_free((ASN1_STRING *)a)
60925450Speter# define M_ASN1_OCTET_STRING_dup(a) (ASN1_OCTET_STRING *)\
61025450Speter                ASN1_STRING_dup((const ASN1_STRING *)a)
61125450Speter# define M_ASN1_OCTET_STRING_cmp(a,b) ASN1_STRING_cmp(\
61225450Speter                (const ASN1_STRING *)a,(const ASN1_STRING *)b)
61325450Speter# define M_ASN1_OCTET_STRING_set(a,b,c)  ASN1_STRING_set((ASN1_STRING *)a,b,c)
61425450Speter# define M_ASN1_OCTET_STRING_print(a,b)  ASN1_STRING_print(a,(ASN1_STRING *)b)
61525450Speter# define M_i2d_ASN1_OCTET_STRING(a,pp) \
61625450Speter                i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_OCTET_STRING,\
61725450Speter                V_ASN1_UNIVERSAL)
61825450Speter
61925450Speter# define B_ASN1_TIME \
62025450Speter                        B_ASN1_UTCTIME | \
62125450Speter                        B_ASN1_GENERALIZEDTIME
62295005Simp
62325450Speter# define B_ASN1_PRINTABLE \
62425450Speter                        B_ASN1_NUMERICSTRING| \
62525450Speter                        B_ASN1_PRINTABLESTRING| \
62625450Speter                        B_ASN1_T61STRING| \
62725450Speter                        B_ASN1_IA5STRING| \
62825450Speter                        B_ASN1_BIT_STRING| \
62925450Speter                        B_ASN1_UNIVERSALSTRING|\
63025450Speter                        B_ASN1_BMPSTRING|\
63125450Speter                        B_ASN1_UTF8STRING|\
63295005Simp                        B_ASN1_SEQUENCE|\
63325450Speter                        B_ASN1_UNKNOWN
63425450Speter
63577385Sphk# define B_ASN1_DIRECTORYSTRING \
63677385Sphk                        B_ASN1_PRINTABLESTRING| \
63777385Sphk                        B_ASN1_TELETEXSTRING|\
63877385Sphk                        B_ASN1_BMPSTRING|\
63977385Sphk                        B_ASN1_UNIVERSALSTRING|\
64077385Sphk                        B_ASN1_UTF8STRING
64177385Sphk
64277385Sphk# define B_ASN1_DISPLAYTEXT \
64395005Simp                        B_ASN1_IA5STRING| \
64477385Sphk                        B_ASN1_VISIBLESTRING| \
64577385Sphk                        B_ASN1_BMPSTRING|\
64625450Speter                        B_ASN1_UTF8STRING
64725450Speter
64825450Speter# define M_ASN1_PRINTABLE_new()  ASN1_STRING_type_new(V_ASN1_T61STRING)
64925450Speter# define M_ASN1_PRINTABLE_free(a)        ASN1_STRING_free((ASN1_STRING *)a)
65025450Speter# define M_i2d_ASN1_PRINTABLE(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
65125450Speter                pp,a->type,V_ASN1_UNIVERSAL)
65277385Sphk# define M_d2i_ASN1_PRINTABLE(a,pp,l) \
65377385Sphk                d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
65477385Sphk                        B_ASN1_PRINTABLE)
65577385Sphk
65695005Simp# define M_DIRECTORYSTRING_new() ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
65795005Simp# define M_DIRECTORYSTRING_free(a)       ASN1_STRING_free((ASN1_STRING *)a)
65877385Sphk# define M_i2d_DIRECTORYSTRING(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
65977385Sphk                                                pp,a->type,V_ASN1_UNIVERSAL)
66077385Sphk# define M_d2i_DIRECTORYSTRING(a,pp,l) \
66177385Sphk                d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
66277385Sphk                        B_ASN1_DIRECTORYSTRING)
66377385Sphk
66477385Sphk# define M_DISPLAYTEXT_new() ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
66577385Sphk# define M_DISPLAYTEXT_free(a) ASN1_STRING_free((ASN1_STRING *)a)
66677385Sphk# define M_i2d_DISPLAYTEXT(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
66777385Sphk                                                pp,a->type,V_ASN1_UNIVERSAL)
66877385Sphk# define M_d2i_DISPLAYTEXT(a,pp,l) \
66977385Sphk                d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
67077385Sphk                        B_ASN1_DISPLAYTEXT)
67177385Sphk
67277385Sphk# define M_ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING *)\
67377385Sphk                ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
67477385Sphk# define M_ASN1_PRINTABLESTRING_free(a)  ASN1_STRING_free((ASN1_STRING *)a)
675114164Ssam# define M_i2d_ASN1_PRINTABLESTRING(a,pp) \
676114164Ssam                i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_PRINTABLESTRING,\
677114164Ssam                V_ASN1_UNIVERSAL)
678114164Ssam# define M_d2i_ASN1_PRINTABLESTRING(a,pp,l) \
679114164Ssam                (ASN1_PRINTABLESTRING *)d2i_ASN1_type_bytes\
680114164Ssam                ((ASN1_STRING **)a,pp,l,B_ASN1_PRINTABLESTRING)
681114164Ssam
682114164Ssam# define M_ASN1_T61STRING_new()  (ASN1_T61STRING *)\
683114164Ssam                ASN1_STRING_type_new(V_ASN1_T61STRING)
684114164Ssam# define M_ASN1_T61STRING_free(a)        ASN1_STRING_free((ASN1_STRING *)a)
685114164Ssam# define M_i2d_ASN1_T61STRING(a,pp) \
686114164Ssam                i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_T61STRING,\
687114164Ssam                V_ASN1_UNIVERSAL)
688114164Ssam# define M_d2i_ASN1_T61STRING(a,pp,l) \
689114164Ssam                (ASN1_T61STRING *)d2i_ASN1_type_bytes\
690114164Ssam                ((ASN1_STRING **)a,pp,l,B_ASN1_T61STRING)
691114164Ssam
692114164Ssam# define M_ASN1_IA5STRING_new()  (ASN1_IA5STRING *)\
693114164Ssam                ASN1_STRING_type_new(V_ASN1_IA5STRING)
69477385Sphk# define M_ASN1_IA5STRING_free(a)        ASN1_STRING_free((ASN1_STRING *)a)
69595005Simp# define M_ASN1_IA5STRING_dup(a) \
69677385Sphk                (ASN1_IA5STRING *)ASN1_STRING_dup((const ASN1_STRING *)a)
69777385Sphk# define M_i2d_ASN1_IA5STRING(a,pp) \
69877385Sphk                i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_IA5STRING,\
69977385Sphk                        V_ASN1_UNIVERSAL)
70077385Sphk# define M_d2i_ASN1_IA5STRING(a,pp,l) \
70177385Sphk                (ASN1_IA5STRING *)d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l,\
70277385Sphk                        B_ASN1_IA5STRING)
70377385Sphk
70425450Speter# define M_ASN1_UTCTIME_new()    (ASN1_UTCTIME *)\
70525450Speter                ASN1_STRING_type_new(V_ASN1_UTCTIME)
70625450Speter# define M_ASN1_UTCTIME_free(a)  ASN1_STRING_free((ASN1_STRING *)a)
70777385Sphk# define M_ASN1_UTCTIME_dup(a) (ASN1_UTCTIME *)\
70877385Sphk                ASN1_STRING_dup((const ASN1_STRING *)a)
70925450Speter
71025450Speter# define M_ASN1_GENERALIZEDTIME_new()    (ASN1_GENERALIZEDTIME *)\
71125450Speter                ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME)
71225450Speter# define M_ASN1_GENERALIZEDTIME_free(a)  ASN1_STRING_free((ASN1_STRING *)a)
71325450Speter# define M_ASN1_GENERALIZEDTIME_dup(a) (ASN1_GENERALIZEDTIME *)ASN1_STRING_dup(\
71425450Speter        (const ASN1_STRING *)a)
71525450Speter
71625450Speter# define M_ASN1_TIME_new()       (ASN1_TIME *)\
71777385Sphk                ASN1_STRING_type_new(V_ASN1_UTCTIME)
718161536Sthomas# define M_ASN1_TIME_free(a)     ASN1_STRING_free((ASN1_STRING *)a)
719161536Sthomas# define M_ASN1_TIME_dup(a) (ASN1_TIME *)\
720161536Sthomas        ASN1_STRING_dup((const ASN1_STRING *)a)
721161536Sthomas
72225450Speter# define M_ASN1_GENERALSTRING_new()      (ASN1_GENERALSTRING *)\
72377385Sphk                ASN1_STRING_type_new(V_ASN1_GENERALSTRING)
72477385Sphk# define M_ASN1_GENERALSTRING_free(a)    ASN1_STRING_free((ASN1_STRING *)a)
72577385Sphk# define M_i2d_ASN1_GENERALSTRING(a,pp) \
72625450Speter                i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_GENERALSTRING,\
72725450Speter                        V_ASN1_UNIVERSAL)
728114164Ssam# define M_d2i_ASN1_GENERALSTRING(a,pp,l) \
729114164Ssam                (ASN1_GENERALSTRING *)d2i_ASN1_type_bytes\
730116820Ssam                ((ASN1_STRING **)a,pp,l,B_ASN1_GENERALSTRING)
731114164Ssam
732114164Ssam# define M_ASN1_UNIVERSALSTRING_new()    (ASN1_UNIVERSALSTRING *)\
733114164Ssam                ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING)
73425450Speter# define M_ASN1_UNIVERSALSTRING_free(a)  ASN1_STRING_free((ASN1_STRING *)a)
73525450Speter# define M_i2d_ASN1_UNIVERSALSTRING(a,pp) \
73625450Speter                i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UNIVERSALSTRING,\
73725450Speter                        V_ASN1_UNIVERSAL)
73825450Speter# define M_d2i_ASN1_UNIVERSALSTRING(a,pp,l) \
73925450Speter                (ASN1_UNIVERSALSTRING *)d2i_ASN1_type_bytes\
74025450Speter                ((ASN1_STRING **)a,pp,l,B_ASN1_UNIVERSALSTRING)
74125450Speter
74225450Speter# define M_ASN1_BMPSTRING_new()  (ASN1_BMPSTRING *)\
74325450Speter                ASN1_STRING_type_new(V_ASN1_BMPSTRING)
74425450Speter# define M_ASN1_BMPSTRING_free(a)        ASN1_STRING_free((ASN1_STRING *)a)
74525450Speter# define M_i2d_ASN1_BMPSTRING(a,pp) \
74625450Speter                i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_BMPSTRING,\
74725450Speter                        V_ASN1_UNIVERSAL)
74825450Speter# define M_d2i_ASN1_BMPSTRING(a,pp,l) \
749166113Smarius                (ASN1_BMPSTRING *)d2i_ASN1_type_bytes\
750166169Smarius                ((ASN1_STRING **)a,pp,l,B_ASN1_BMPSTRING)
751166113Smarius
75225450Speter# define M_ASN1_VISIBLESTRING_new()      (ASN1_VISIBLESTRING *)\
75325450Speter                ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
75477385Sphk# define M_ASN1_VISIBLESTRING_free(a)    ASN1_STRING_free((ASN1_STRING *)a)
75595005Simp# define M_i2d_ASN1_VISIBLESTRING(a,pp) \
75677385Sphk                i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_VISIBLESTRING,\
75777385Sphk                        V_ASN1_UNIVERSAL)
75877385Sphk# define M_d2i_ASN1_VISIBLESTRING(a,pp,l) \
75977385Sphk                (ASN1_VISIBLESTRING *)d2i_ASN1_type_bytes\
76077385Sphk                ((ASN1_STRING **)a,pp,l,B_ASN1_VISIBLESTRING)
76177385Sphk
76277385Sphk# define M_ASN1_UTF8STRING_new() (ASN1_UTF8STRING *)\
76377385Sphk                ASN1_STRING_type_new(V_ASN1_UTF8STRING)
76477385Sphk# define M_ASN1_UTF8STRING_free(a)       ASN1_STRING_free((ASN1_STRING *)a)
76577385Sphk# define M_i2d_ASN1_UTF8STRING(a,pp) \
76677385Sphk                i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UTF8STRING,\
76777385Sphk                        V_ASN1_UNIVERSAL)
76877385Sphk# define M_d2i_ASN1_UTF8STRING(a,pp,l) \
76977385Sphk                (ASN1_UTF8STRING *)d2i_ASN1_type_bytes\
77077385Sphk                ((ASN1_STRING **)a,pp,l,B_ASN1_UTF8STRING)
77177385Sphk
77277385Sphk  /* for the is_set parameter to i2d_ASN1_SET */
77377385Sphk# define IS_SEQUENCE     0
77477385Sphk# define IS_SET          1
77577385Sphk
776161536SthomasDECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
777161536Sthomas
778161536Sthomasint ASN1_TYPE_get(ASN1_TYPE *a);
779161536Sthomasvoid ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value);
78077385Sphkint ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value);
78177385Sphkint ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b);
78277385Sphk
783114164SsamASN1_OBJECT *ASN1_OBJECT_new(void);
784114164Ssamvoid ASN1_OBJECT_free(ASN1_OBJECT *a);
785114164Ssamint i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp);
786114164SsamASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
78777385Sphk                             long length);
78877385SphkASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
78977385Sphk                             long length);
79077385Sphk
79177385SphkDECLARE_ASN1_ITEM(ASN1_OBJECT)
79277385Sphk
79377385SphkDECLARE_STACK_OF(ASN1_OBJECT)
79477385SphkDECLARE_ASN1_SET_OF(ASN1_OBJECT)
79577385Sphk
79677385SphkASN1_STRING *ASN1_STRING_new(void);
79777385Sphkvoid ASN1_STRING_free(ASN1_STRING *a);
798166113Smariusvoid ASN1_STRING_clear_free(ASN1_STRING *a);
799166169Smariusint ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str);
800166169SmariusASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *a);
80177385SphkASN1_STRING *ASN1_STRING_type_new(int type);
80277385Sphkint ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b);
80325450Speter  /*
80425450Speter   * Since this is used to store all sorts of things, via macros, for now,
80525450Speter   * make its data void *
806138593Ssam   */
807138593Ssamint ASN1_STRING_set(ASN1_STRING *str, const void *data, int len);
808138593Ssamvoid ASN1_STRING_set0(ASN1_STRING *str, void *data, int len);
809138593Ssamint ASN1_STRING_length(const ASN1_STRING *x);
810138593Ssamvoid ASN1_STRING_length_set(ASN1_STRING *x, int n);
811138593Ssamint ASN1_STRING_type(ASN1_STRING *x);
812166113Smariusunsigned char *ASN1_STRING_data(ASN1_STRING *x);
813166113Smarius
814138593SsamDECLARE_ASN1_FUNCTIONS(ASN1_BIT_STRING)
815138593Ssamint i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp);
816138593SsamASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
817138593Ssam                                     const unsigned char **pp, long length);
818139494Ssamint ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d, int length);
819138593Ssamint ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value);
820138593Ssamint ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n);
821138593Ssamint ASN1_BIT_STRING_check(ASN1_BIT_STRING *a,
822138593Ssam                          unsigned char *flags, int flags_len);
823138593Ssam
824138593Ssam# ifndef OPENSSL_NO_BIO
825194799Sdelphijint ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
826138593Ssam                               BIT_STRING_BITNAME *tbl, int indent);
827138593Ssam# endif
828138593Ssamint ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl);
829138593Ssamint ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value,
830138593Ssam                            BIT_STRING_BITNAME *tbl);
831138593Ssam
832int i2d_ASN1_BOOLEAN(int a, unsigned char **pp);
833int d2i_ASN1_BOOLEAN(int *a, const unsigned char **pp, long length);
834
835DECLARE_ASN1_FUNCTIONS(ASN1_INTEGER)
836int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp);
837ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp,
838                               long length);
839ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp,
840                                long length);
841ASN1_INTEGER *ASN1_INTEGER_dup(const ASN1_INTEGER *x);
842int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y);
843
844DECLARE_ASN1_FUNCTIONS(ASN1_ENUMERATED)
845
846int ASN1_UTCTIME_check(ASN1_UTCTIME *a);
847ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t);
848ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
849                               int offset_day, long offset_sec);
850int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str);
851int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t);
852# if 0
853time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s);
854# endif
855
856int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *a);
857ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
858                                               time_t t);
859ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
860                                               time_t t, int offset_day,
861                                               long offset_sec);
862int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str);
863
864DECLARE_ASN1_FUNCTIONS(ASN1_OCTET_STRING)
865ASN1_OCTET_STRING *ASN1_OCTET_STRING_dup(const ASN1_OCTET_STRING *a);
866int ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a,
867                          const ASN1_OCTET_STRING *b);
868int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, const unsigned char *data,
869                          int len);
870
871DECLARE_ASN1_FUNCTIONS(ASN1_VISIBLESTRING)
872DECLARE_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING)
873DECLARE_ASN1_FUNCTIONS(ASN1_UTF8STRING)
874DECLARE_ASN1_FUNCTIONS(ASN1_NULL)
875DECLARE_ASN1_FUNCTIONS(ASN1_BMPSTRING)
876
877int UTF8_getc(const unsigned char *str, int len, unsigned long *val);
878int UTF8_putc(unsigned char *str, int len, unsigned long value);
879
880DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE)
881
882DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING)
883DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT)
884DECLARE_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING)
885DECLARE_ASN1_FUNCTIONS(ASN1_T61STRING)
886DECLARE_ASN1_FUNCTIONS(ASN1_IA5STRING)
887DECLARE_ASN1_FUNCTIONS(ASN1_GENERALSTRING)
888DECLARE_ASN1_FUNCTIONS(ASN1_UTCTIME)
889DECLARE_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME)
890DECLARE_ASN1_FUNCTIONS(ASN1_TIME)
891
892DECLARE_ASN1_ITEM(ASN1_OCTET_STRING_NDEF)
893
894ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t);
895ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t,
896                         int offset_day, long offset_sec);
897int ASN1_TIME_check(ASN1_TIME *t);
898ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME
899                                                   **out);
900int ASN1_TIME_set_string(ASN1_TIME *s, const char *str);
901
902int i2d_ASN1_SET(STACK_OF(OPENSSL_BLOCK) *a, unsigned char **pp,
903                 i2d_of_void *i2d, int ex_tag, int ex_class, int is_set);
904STACK_OF(OPENSSL_BLOCK) *d2i_ASN1_SET(STACK_OF(OPENSSL_BLOCK) **a,
905                                      const unsigned char **pp,
906                                      long length, d2i_of_void *d2i,
907                                      void (*free_func) (OPENSSL_BLOCK),
908                                      int ex_tag, int ex_class);
909
910# ifndef OPENSSL_NO_BIO
911int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a);
912int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size);
913int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a);
914int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size);
915int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a);
916int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size);
917int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type);
918# endif
919int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a);
920
921int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num);
922ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len,
923                                const char *sn, const char *ln);
924
925int ASN1_INTEGER_set(ASN1_INTEGER *a, long v);
926long ASN1_INTEGER_get(const ASN1_INTEGER *a);
927ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai);
928BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn);
929
930int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v);
931long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a);
932ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai);
933BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn);
934
935/* General */
936/* given a string, return the correct type, max is the maximum length */
937int ASN1_PRINTABLE_type(const unsigned char *s, int max);
938
939int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass);
940ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, const unsigned char **pp,
941                            long length, int Ptag, int Pclass);
942unsigned long ASN1_tag2bit(int tag);
943/* type is one or more of the B_ASN1_ values. */
944ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a, const unsigned char **pp,
945                                 long length, int type);
946
947/* PARSING */
948int asn1_Finish(ASN1_CTX *c);
949int asn1_const_Finish(ASN1_const_CTX *c);
950
951/* SPECIALS */
952int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,
953                    int *pclass, long omax);
954int ASN1_check_infinite_end(unsigned char **p, long len);
955int ASN1_const_check_infinite_end(const unsigned char **p, long len);
956void ASN1_put_object(unsigned char **pp, int constructed, int length,
957                     int tag, int xclass);
958int ASN1_put_eoc(unsigned char **pp);
959int ASN1_object_size(int constructed, int length, int tag);
960
961/* Used to implement other functions */
962void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x);
963
964# define ASN1_dup_of(type,i2d,d2i,x) \
965    ((type*)ASN1_dup(CHECKED_I2D_OF(type, i2d), \
966                     CHECKED_D2I_OF(type, d2i), \
967                     CHECKED_PTR_OF(type, x)))
968
969# define ASN1_dup_of_const(type,i2d,d2i,x) \
970    ((type*)ASN1_dup(CHECKED_I2D_OF(const type, i2d), \
971                     CHECKED_D2I_OF(type, d2i), \
972                     CHECKED_PTR_OF(const type, x)))
973
974void *ASN1_item_dup(const ASN1_ITEM *it, void *x);
975
976/* ASN1 alloc/free macros for when a type is only used internally */
977
978# define M_ASN1_new_of(type) (type *)ASN1_item_new(ASN1_ITEM_rptr(type))
979# define M_ASN1_free_of(x, type) \
980                ASN1_item_free(CHECKED_PTR_OF(type, x), ASN1_ITEM_rptr(type))
981
982# ifndef OPENSSL_NO_FP_API
983void *ASN1_d2i_fp(void *(*xnew) (void), d2i_of_void *d2i, FILE *in, void **x);
984
985#  define ASN1_d2i_fp_of(type,xnew,d2i,in,x) \
986    ((type*)ASN1_d2i_fp(CHECKED_NEW_OF(type, xnew), \
987                        CHECKED_D2I_OF(type, d2i), \
988                        in, \
989                        CHECKED_PPTR_OF(type, x)))
990
991void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x);
992int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x);
993
994#  define ASN1_i2d_fp_of(type,i2d,out,x) \
995    (ASN1_i2d_fp(CHECKED_I2D_OF(type, i2d), \
996                 out, \
997                 CHECKED_PTR_OF(type, x)))
998
999#  define ASN1_i2d_fp_of_const(type,i2d,out,x) \
1000    (ASN1_i2d_fp(CHECKED_I2D_OF(const type, i2d), \
1001                 out, \
1002                 CHECKED_PTR_OF(const type, x)))
1003
1004int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x);
1005int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags);
1006# endif
1007
1008int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in);
1009
1010# ifndef OPENSSL_NO_BIO
1011void *ASN1_d2i_bio(void *(*xnew) (void), d2i_of_void *d2i, BIO *in, void **x);
1012
1013#  define ASN1_d2i_bio_of(type,xnew,d2i,in,x) \
1014    ((type*)ASN1_d2i_bio( CHECKED_NEW_OF(type, xnew), \
1015                          CHECKED_D2I_OF(type, d2i), \
1016                          in, \
1017                          CHECKED_PPTR_OF(type, x)))
1018
1019void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x);
1020int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x);
1021
1022#  define ASN1_i2d_bio_of(type,i2d,out,x) \
1023    (ASN1_i2d_bio(CHECKED_I2D_OF(type, i2d), \
1024                  out, \
1025                  CHECKED_PTR_OF(type, x)))
1026
1027#  define ASN1_i2d_bio_of_const(type,i2d,out,x) \
1028    (ASN1_i2d_bio(CHECKED_I2D_OF(const type, i2d), \
1029                  out, \
1030                  CHECKED_PTR_OF(const type, x)))
1031
1032int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x);
1033int ASN1_UTCTIME_print(BIO *fp, const ASN1_UTCTIME *a);
1034int ASN1_GENERALIZEDTIME_print(BIO *fp, const ASN1_GENERALIZEDTIME *a);
1035int ASN1_TIME_print(BIO *fp, const ASN1_TIME *a);
1036int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v);
1037int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags);
1038int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num,
1039                  unsigned char *buf, int off);
1040int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent);
1041int ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent,
1042                    int dump);
1043# endif
1044const char *ASN1_tag2str(int tag);
1045
1046/* Used to load and write netscape format cert */
1047
1048DECLARE_ASN1_FUNCTIONS(NETSCAPE_X509)
1049
1050int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s);
1051
1052int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len);
1053int ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data, int max_len);
1054int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num,
1055                                  unsigned char *data, int len);
1056int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num,
1057                                  unsigned char *data, int max_len);
1058
1059STACK_OF(OPENSSL_BLOCK) *ASN1_seq_unpack(const unsigned char *buf, int len,
1060                                         d2i_of_void *d2i,
1061                                         void (*free_func) (OPENSSL_BLOCK));
1062unsigned char *ASN1_seq_pack(STACK_OF(OPENSSL_BLOCK) *safes, i2d_of_void *i2d,
1063                             unsigned char **buf, int *len);
1064void *ASN1_unpack_string(ASN1_STRING *oct, d2i_of_void *d2i);
1065void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it);
1066ASN1_STRING *ASN1_pack_string(void *obj, i2d_of_void *i2d,
1067                              ASN1_OCTET_STRING **oct);
1068
1069# define ASN1_pack_string_of(type,obj,i2d,oct) \
1070    (ASN1_pack_string(CHECKED_PTR_OF(type, obj), \
1071                      CHECKED_I2D_OF(type, i2d), \
1072                      oct))
1073
1074ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it,
1075                            ASN1_OCTET_STRING **oct);
1076
1077void ASN1_STRING_set_default_mask(unsigned long mask);
1078int ASN1_STRING_set_default_mask_asc(const char *p);
1079unsigned long ASN1_STRING_get_default_mask(void);
1080int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len,
1081                       int inform, unsigned long mask);
1082int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
1083                        int inform, unsigned long mask,
1084                        long minsize, long maxsize);
1085
1086ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out,
1087                                    const unsigned char *in, int inlen,
1088                                    int inform, int nid);
1089ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid);
1090int ASN1_STRING_TABLE_add(int, long, long, unsigned long, unsigned long);
1091void ASN1_STRING_TABLE_cleanup(void);
1092
1093/* ASN1 template functions */
1094
1095/* Old API compatible functions */
1096ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it);
1097void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it);
1098ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **val, const unsigned char **in,
1099                          long len, const ASN1_ITEM *it);
1100int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it);
1101int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out,
1102                       const ASN1_ITEM *it);
1103
1104void ASN1_add_oid_module(void);
1105
1106ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf);
1107ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf);
1108
1109/* ASN1 Print flags */
1110
1111/* Indicate missing OPTIONAL fields */
1112# define ASN1_PCTX_FLAGS_SHOW_ABSENT             0x001
1113/* Mark start and end of SEQUENCE */
1114# define ASN1_PCTX_FLAGS_SHOW_SEQUENCE           0x002
1115/* Mark start and end of SEQUENCE/SET OF */
1116# define ASN1_PCTX_FLAGS_SHOW_SSOF               0x004
1117/* Show the ASN1 type of primitives */
1118# define ASN1_PCTX_FLAGS_SHOW_TYPE               0x008
1119/* Don't show ASN1 type of ANY */
1120# define ASN1_PCTX_FLAGS_NO_ANY_TYPE             0x010
1121/* Don't show ASN1 type of MSTRINGs */
1122# define ASN1_PCTX_FLAGS_NO_MSTRING_TYPE         0x020
1123/* Don't show field names in SEQUENCE */
1124# define ASN1_PCTX_FLAGS_NO_FIELD_NAME           0x040
1125/* Show structure names of each SEQUENCE field */
1126# define ASN1_PCTX_FLAGS_SHOW_FIELD_STRUCT_NAME  0x080
1127/* Don't show structure name even at top level */
1128# define ASN1_PCTX_FLAGS_NO_STRUCT_NAME          0x100
1129
1130int ASN1_item_print(BIO *out, ASN1_VALUE *ifld, int indent,
1131                    const ASN1_ITEM *it, const ASN1_PCTX *pctx);
1132ASN1_PCTX *ASN1_PCTX_new(void);
1133void ASN1_PCTX_free(ASN1_PCTX *p);
1134unsigned long ASN1_PCTX_get_flags(ASN1_PCTX *p);
1135void ASN1_PCTX_set_flags(ASN1_PCTX *p, unsigned long flags);
1136unsigned long ASN1_PCTX_get_nm_flags(ASN1_PCTX *p);
1137void ASN1_PCTX_set_nm_flags(ASN1_PCTX *p, unsigned long flags);
1138unsigned long ASN1_PCTX_get_cert_flags(ASN1_PCTX *p);
1139void ASN1_PCTX_set_cert_flags(ASN1_PCTX *p, unsigned long flags);
1140unsigned long ASN1_PCTX_get_oid_flags(ASN1_PCTX *p);
1141void ASN1_PCTX_set_oid_flags(ASN1_PCTX *p, unsigned long flags);
1142unsigned long ASN1_PCTX_get_str_flags(ASN1_PCTX *p);
1143void ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags);
1144
1145BIO_METHOD *BIO_f_asn1(void);
1146
1147BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it);
1148
1149int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
1150                        const ASN1_ITEM *it);
1151int PEM_write_bio_ASN1_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
1152                              const char *hdr, const ASN1_ITEM *it);
1153int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
1154                     int ctype_nid, int econt_nid,
1155                     STACK_OF(X509_ALGOR) *mdalgs, const ASN1_ITEM *it);
1156ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it);
1157int SMIME_crlf_copy(BIO *in, BIO *out, int flags);
1158int SMIME_text(BIO *in, BIO *out);
1159
1160/* BEGIN ERROR CODES */
1161/*
1162 * The following lines are auto generated by the script mkerr.pl. Any changes
1163 * made after this point may be overwritten when the script is next run.
1164 */
1165void ERR_load_ASN1_strings(void);
1166
1167/* Error codes for the ASN1 functions. */
1168
1169/* Function codes. */
1170# define ASN1_F_A2D_ASN1_OBJECT                           100
1171# define ASN1_F_A2I_ASN1_ENUMERATED                       101
1172# define ASN1_F_A2I_ASN1_INTEGER                          102
1173# define ASN1_F_A2I_ASN1_STRING                           103
1174# define ASN1_F_APPEND_EXP                                176
1175# define ASN1_F_ASN1_BIT_STRING_SET_BIT                   183
1176# define ASN1_F_ASN1_CB                                   177
1177# define ASN1_F_ASN1_CHECK_TLEN                           104
1178# define ASN1_F_ASN1_COLLATE_PRIMITIVE                    105
1179# define ASN1_F_ASN1_COLLECT                              106
1180# define ASN1_F_ASN1_D2I_EX_PRIMITIVE                     108
1181# define ASN1_F_ASN1_D2I_FP                               109
1182# define ASN1_F_ASN1_D2I_READ_BIO                         107
1183# define ASN1_F_ASN1_DIGEST                               184
1184# define ASN1_F_ASN1_DO_ADB                               110
1185# define ASN1_F_ASN1_DUP                                  111
1186# define ASN1_F_ASN1_ENUMERATED_SET                       112
1187# define ASN1_F_ASN1_ENUMERATED_TO_BN                     113
1188# define ASN1_F_ASN1_EX_C2I                               204
1189# define ASN1_F_ASN1_FIND_END                             190
1190# define ASN1_F_ASN1_GENERALIZEDTIME_ADJ                  216
1191# define ASN1_F_ASN1_GENERALIZEDTIME_SET                  185
1192# define ASN1_F_ASN1_GENERATE_V3                          178
1193# define ASN1_F_ASN1_GET_OBJECT                           114
1194# define ASN1_F_ASN1_HEADER_NEW                           115
1195# define ASN1_F_ASN1_I2D_BIO                              116
1196# define ASN1_F_ASN1_I2D_FP                               117
1197# define ASN1_F_ASN1_INTEGER_SET                          118
1198# define ASN1_F_ASN1_INTEGER_TO_BN                        119
1199# define ASN1_F_ASN1_ITEM_D2I_FP                          206
1200# define ASN1_F_ASN1_ITEM_DUP                             191
1201# define ASN1_F_ASN1_ITEM_EX_COMBINE_NEW                  121
1202# define ASN1_F_ASN1_ITEM_EX_D2I                          120
1203# define ASN1_F_ASN1_ITEM_I2D_BIO                         192
1204# define ASN1_F_ASN1_ITEM_I2D_FP                          193
1205# define ASN1_F_ASN1_ITEM_PACK                            198
1206# define ASN1_F_ASN1_ITEM_SIGN                            195
1207# define ASN1_F_ASN1_ITEM_SIGN_CTX                        220
1208# define ASN1_F_ASN1_ITEM_UNPACK                          199
1209# define ASN1_F_ASN1_ITEM_VERIFY                          197
1210# define ASN1_F_ASN1_MBSTRING_NCOPY                       122
1211# define ASN1_F_ASN1_OBJECT_NEW                           123
1212# define ASN1_F_ASN1_OUTPUT_DATA                          214
1213# define ASN1_F_ASN1_PACK_STRING                          124
1214# define ASN1_F_ASN1_PCTX_NEW                             205
1215# define ASN1_F_ASN1_PKCS5_PBE_SET                        125
1216# define ASN1_F_ASN1_SEQ_PACK                             126
1217# define ASN1_F_ASN1_SEQ_UNPACK                           127
1218# define ASN1_F_ASN1_SIGN                                 128
1219# define ASN1_F_ASN1_STR2TYPE                             179
1220# define ASN1_F_ASN1_STRING_SET                           186
1221# define ASN1_F_ASN1_STRING_TABLE_ADD                     129
1222# define ASN1_F_ASN1_STRING_TYPE_NEW                      130
1223# define ASN1_F_ASN1_TEMPLATE_EX_D2I                      132
1224# define ASN1_F_ASN1_TEMPLATE_NEW                         133
1225# define ASN1_F_ASN1_TEMPLATE_NOEXP_D2I                   131
1226# define ASN1_F_ASN1_TIME_ADJ                             217
1227# define ASN1_F_ASN1_TIME_SET                             175
1228# define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING             134
1229# define ASN1_F_ASN1_TYPE_GET_OCTETSTRING                 135
1230# define ASN1_F_ASN1_UNPACK_STRING                        136
1231# define ASN1_F_ASN1_UTCTIME_ADJ                          218
1232# define ASN1_F_ASN1_UTCTIME_SET                          187
1233# define ASN1_F_ASN1_VERIFY                               137
1234# define ASN1_F_B64_READ_ASN1                             209
1235# define ASN1_F_B64_WRITE_ASN1                            210
1236# define ASN1_F_BIO_NEW_NDEF                              208
1237# define ASN1_F_BITSTR_CB                                 180
1238# define ASN1_F_BN_TO_ASN1_ENUMERATED                     138
1239# define ASN1_F_BN_TO_ASN1_INTEGER                        139
1240# define ASN1_F_C2I_ASN1_BIT_STRING                       189
1241# define ASN1_F_C2I_ASN1_INTEGER                          194
1242# define ASN1_F_C2I_ASN1_OBJECT                           196
1243# define ASN1_F_COLLECT_DATA                              140
1244# define ASN1_F_D2I_ASN1_BIT_STRING                       141
1245# define ASN1_F_D2I_ASN1_BOOLEAN                          142
1246# define ASN1_F_D2I_ASN1_BYTES                            143
1247# define ASN1_F_D2I_ASN1_GENERALIZEDTIME                  144
1248# define ASN1_F_D2I_ASN1_HEADER                           145
1249# define ASN1_F_D2I_ASN1_INTEGER                          146
1250# define ASN1_F_D2I_ASN1_OBJECT                           147
1251# define ASN1_F_D2I_ASN1_SET                              148
1252# define ASN1_F_D2I_ASN1_TYPE_BYTES                       149
1253# define ASN1_F_D2I_ASN1_UINTEGER                         150
1254# define ASN1_F_D2I_ASN1_UTCTIME                          151
1255# define ASN1_F_D2I_AUTOPRIVATEKEY                        207
1256# define ASN1_F_D2I_NETSCAPE_RSA                          152
1257# define ASN1_F_D2I_NETSCAPE_RSA_2                        153
1258# define ASN1_F_D2I_PRIVATEKEY                            154
1259# define ASN1_F_D2I_PUBLICKEY                             155
1260# define ASN1_F_D2I_RSA_NET                               200
1261# define ASN1_F_D2I_RSA_NET_2                             201
1262# define ASN1_F_D2I_X509                                  156
1263# define ASN1_F_D2I_X509_CINF                             157
1264# define ASN1_F_D2I_X509_PKEY                             159
1265# define ASN1_F_I2D_ASN1_BIO_STREAM                       211
1266# define ASN1_F_I2D_ASN1_SET                              188
1267# define ASN1_F_I2D_ASN1_TIME                             160
1268# define ASN1_F_I2D_DSA_PUBKEY                            161
1269# define ASN1_F_I2D_EC_PUBKEY                             181
1270# define ASN1_F_I2D_PRIVATEKEY                            163
1271# define ASN1_F_I2D_PUBLICKEY                             164
1272# define ASN1_F_I2D_RSA_NET                               162
1273# define ASN1_F_I2D_RSA_PUBKEY                            165
1274# define ASN1_F_LONG_C2I                                  166
1275# define ASN1_F_OID_MODULE_INIT                           174
1276# define ASN1_F_PARSE_TAGGING                             182
1277# define ASN1_F_PKCS5_PBE2_SET_IV                         167
1278# define ASN1_F_PKCS5_PBE_SET                             202
1279# define ASN1_F_PKCS5_PBE_SET0_ALGOR                      215
1280# define ASN1_F_PKCS5_PBKDF2_SET                          219
1281# define ASN1_F_SMIME_READ_ASN1                           212
1282# define ASN1_F_SMIME_TEXT                                213
1283# define ASN1_F_X509_CINF_NEW                             168
1284# define ASN1_F_X509_CRL_ADD0_REVOKED                     169
1285# define ASN1_F_X509_INFO_NEW                             170
1286# define ASN1_F_X509_NAME_ENCODE                          203
1287# define ASN1_F_X509_NAME_EX_D2I                          158
1288# define ASN1_F_X509_NAME_EX_NEW                          171
1289# define ASN1_F_X509_NEW                                  172
1290# define ASN1_F_X509_PKEY_NEW                             173
1291
1292/* Reason codes. */
1293# define ASN1_R_ADDING_OBJECT                             171
1294# define ASN1_R_ASN1_PARSE_ERROR                          203
1295# define ASN1_R_ASN1_SIG_PARSE_ERROR                      204
1296# define ASN1_R_AUX_ERROR                                 100
1297# define ASN1_R_BAD_CLASS                                 101
1298# define ASN1_R_BAD_OBJECT_HEADER                         102
1299# define ASN1_R_BAD_PASSWORD_READ                         103
1300# define ASN1_R_BAD_TAG                                   104
1301# define ASN1_R_BMPSTRING_IS_WRONG_LENGTH                 214
1302# define ASN1_R_BN_LIB                                    105
1303# define ASN1_R_BOOLEAN_IS_WRONG_LENGTH                   106
1304# define ASN1_R_BUFFER_TOO_SMALL                          107
1305# define ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER           108
1306# define ASN1_R_CONTEXT_NOT_INITIALISED                   217
1307# define ASN1_R_DATA_IS_WRONG                             109
1308# define ASN1_R_DECODE_ERROR                              110
1309# define ASN1_R_DECODING_ERROR                            111
1310# define ASN1_R_DEPTH_EXCEEDED                            174
1311# define ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED         198
1312# define ASN1_R_ENCODE_ERROR                              112
1313# define ASN1_R_ERROR_GETTING_TIME                        173
1314# define ASN1_R_ERROR_LOADING_SECTION                     172
1315# define ASN1_R_ERROR_PARSING_SET_ELEMENT                 113
1316# define ASN1_R_ERROR_SETTING_CIPHER_PARAMS               114
1317# define ASN1_R_EXPECTING_AN_INTEGER                      115
1318# define ASN1_R_EXPECTING_AN_OBJECT                       116
1319# define ASN1_R_EXPECTING_A_BOOLEAN                       117
1320# define ASN1_R_EXPECTING_A_TIME                          118
1321# define ASN1_R_EXPLICIT_LENGTH_MISMATCH                  119
1322# define ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED              120
1323# define ASN1_R_FIELD_MISSING                             121
1324# define ASN1_R_FIRST_NUM_TOO_LARGE                       122
1325# define ASN1_R_HEADER_TOO_LONG                           123
1326# define ASN1_R_ILLEGAL_BITSTRING_FORMAT                  175
1327# define ASN1_R_ILLEGAL_BOOLEAN                           176
1328# define ASN1_R_ILLEGAL_CHARACTERS                        124
1329# define ASN1_R_ILLEGAL_FORMAT                            177
1330# define ASN1_R_ILLEGAL_HEX                               178
1331# define ASN1_R_ILLEGAL_IMPLICIT_TAG                      179
1332# define ASN1_R_ILLEGAL_INTEGER                           180
1333# define ASN1_R_ILLEGAL_NESTED_TAGGING                    181
1334# define ASN1_R_ILLEGAL_NULL                              125
1335# define ASN1_R_ILLEGAL_NULL_VALUE                        182
1336# define ASN1_R_ILLEGAL_OBJECT                            183
1337# define ASN1_R_ILLEGAL_OPTIONAL_ANY                      126
1338# define ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE          170
1339# define ASN1_R_ILLEGAL_TAGGED_ANY                        127
1340# define ASN1_R_ILLEGAL_TIME_VALUE                        184
1341# define ASN1_R_INTEGER_NOT_ASCII_FORMAT                  185
1342# define ASN1_R_INTEGER_TOO_LARGE_FOR_LONG                128
1343# define ASN1_R_INVALID_BIT_STRING_BITS_LEFT              220
1344# define ASN1_R_INVALID_BMPSTRING_LENGTH                  129
1345# define ASN1_R_INVALID_DIGIT                             130
1346# define ASN1_R_INVALID_MIME_TYPE                         205
1347# define ASN1_R_INVALID_MODIFIER                          186
1348# define ASN1_R_INVALID_NUMBER                            187
1349# define ASN1_R_INVALID_OBJECT_ENCODING                   216
1350# define ASN1_R_INVALID_SEPARATOR                         131
1351# define ASN1_R_INVALID_TIME_FORMAT                       132
1352# define ASN1_R_INVALID_UNIVERSALSTRING_LENGTH            133
1353# define ASN1_R_INVALID_UTF8STRING                        134
1354# define ASN1_R_IV_TOO_LARGE                              135
1355# define ASN1_R_LENGTH_ERROR                              136
1356# define ASN1_R_LIST_ERROR                                188
1357# define ASN1_R_MIME_NO_CONTENT_TYPE                      206
1358# define ASN1_R_MIME_PARSE_ERROR                          207
1359# define ASN1_R_MIME_SIG_PARSE_ERROR                      208
1360# define ASN1_R_MISSING_EOC                               137
1361# define ASN1_R_MISSING_SECOND_NUMBER                     138
1362# define ASN1_R_MISSING_VALUE                             189
1363# define ASN1_R_MSTRING_NOT_UNIVERSAL                     139
1364# define ASN1_R_MSTRING_WRONG_TAG                         140
1365# define ASN1_R_NESTED_ASN1_STRING                        197
1366# define ASN1_R_NON_HEX_CHARACTERS                        141
1367# define ASN1_R_NOT_ASCII_FORMAT                          190
1368# define ASN1_R_NOT_ENOUGH_DATA                           142
1369# define ASN1_R_NO_CONTENT_TYPE                           209
1370# define ASN1_R_NO_DEFAULT_DIGEST                         201
1371# define ASN1_R_NO_MATCHING_CHOICE_TYPE                   143
1372# define ASN1_R_NO_MULTIPART_BODY_FAILURE                 210
1373# define ASN1_R_NO_MULTIPART_BOUNDARY                     211
1374# define ASN1_R_NO_SIG_CONTENT_TYPE                       212
1375# define ASN1_R_NULL_IS_WRONG_LENGTH                      144
1376# define ASN1_R_OBJECT_NOT_ASCII_FORMAT                   191
1377# define ASN1_R_ODD_NUMBER_OF_CHARS                       145
1378# define ASN1_R_PRIVATE_KEY_HEADER_MISSING                146
1379# define ASN1_R_SECOND_NUMBER_TOO_LARGE                   147
1380# define ASN1_R_SEQUENCE_LENGTH_MISMATCH                  148
1381# define ASN1_R_SEQUENCE_NOT_CONSTRUCTED                  149
1382# define ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG              192
1383# define ASN1_R_SHORT_LINE                                150
1384# define ASN1_R_SIG_INVALID_MIME_TYPE                     213
1385# define ASN1_R_STREAMING_NOT_SUPPORTED                   202
1386# define ASN1_R_STRING_TOO_LONG                           151
1387# define ASN1_R_STRING_TOO_SHORT                          152
1388# define ASN1_R_TAG_VALUE_TOO_HIGH                        153
1389# define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 154
1390# define ASN1_R_TIME_NOT_ASCII_FORMAT                     193
1391# define ASN1_R_TOO_LONG                                  155
1392# define ASN1_R_TYPE_NOT_CONSTRUCTED                      156
1393# define ASN1_R_TYPE_NOT_PRIMITIVE                        218
1394# define ASN1_R_UNABLE_TO_DECODE_RSA_KEY                  157
1395# define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY          158
1396# define ASN1_R_UNEXPECTED_EOC                            159
1397# define ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH           215
1398# define ASN1_R_UNKNOWN_FORMAT                            160
1399# define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM          161
1400# define ASN1_R_UNKNOWN_OBJECT_TYPE                       162
1401# define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE                   163
1402# define ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM               199
1403# define ASN1_R_UNKNOWN_TAG                               194
1404# define ASN1_R_UNKOWN_FORMAT                             195
1405# define ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE           164
1406# define ASN1_R_UNSUPPORTED_CIPHER                        165
1407# define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM          166
1408# define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE               167
1409# define ASN1_R_UNSUPPORTED_TYPE                          196
1410# define ASN1_R_WRONG_PUBLIC_KEY_TYPE                     200
1411# define ASN1_R_WRONG_TAG                                 168
1412# define ASN1_R_WRONG_TYPE                                169
1413
1414#ifdef  __cplusplus
1415}
1416#endif
1417#endif
1418