New option to CA.pl to sign request using CA extensions.
[openssl.git] / crypto / asn1 / asn1.h
index d2cd0d0f7eee9d2bdc08d888f70400def5809dab..b2167561b5701ca2a4c50895ecfd5da74dbf8803 100644 (file)
 #ifndef HEADER_ASN1_H
 #define HEADER_ASN1_H
 
-#ifdef  __cplusplus
-extern "C" {
-#endif
-
 #include <time.h>
+#ifndef NO_BIO
+#include <openssl/bio.h>
+#endif
 #include <openssl/bn.h>
 #include <openssl/stack.h>
 #include <openssl/safestack.h>
@@ -72,6 +71,10 @@ extern "C" {
 #include <openssl/vms_idhacks.h>
 #endif
 
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
 #define V_ASN1_UNIVERSAL               0x00
 #define        V_ASN1_APPLICATION              0x40
 #define V_ASN1_CONTEXT_SPECIFIC                0x80
@@ -81,13 +84,15 @@ extern "C" {
 #define V_ASN1_PRIMITIVE_TAG           0x1f
 #define V_ASN1_PRIMATIVE_TAG           0x1f
 
-#define V_ASN1_APP_CHOOSE              -2      /* let the recipent choose */
+#define V_ASN1_APP_CHOOSE              -2      /* let the recipient choose */
+
+#define V_ASN1_NEG                     0x100   /* negative flag */
 
 #define V_ASN1_UNDEF                   -1
 #define V_ASN1_EOC                     0
 #define V_ASN1_BOOLEAN                 1       /**/
 #define V_ASN1_INTEGER                 2
-#define V_ASN1_NEG_INTEGER             (2+0x100)
+#define V_ASN1_NEG_INTEGER             (2 | V_ASN1_NEG)
 #define V_ASN1_BIT_STRING              3
 #define V_ASN1_OCTET_STRING            4
 #define V_ASN1_NULL                    5
@@ -96,7 +101,7 @@ extern "C" {
 #define V_ASN1_EXTERNAL                        8
 #define V_ASN1_REAL                    9
 #define V_ASN1_ENUMERATED              10
-#define V_ASN1_NEG_ENUMERATED          (10+0x100)
+#define V_ASN1_NEG_ENUMERATED          (10 | V_ASN1_NEG)
 #define V_ASN1_UTF8STRING              12
 #define V_ASN1_SEQUENCE                        16
 #define V_ASN1_SET                     17
@@ -140,32 +145,10 @@ extern "C" {
 #define MBSTRING_UNIV          (MBSTRING_FLAG|3)
 #define MBSTRING_UTF8          (MBSTRING_FLAG|4)
 
-#define DECLARE_ASN1_SET_OF(type) \
-int i2d_ASN1_SET_OF_##type(STACK_OF(type) *a,unsigned char **pp, \
-                          int (*func)(type *,unsigned char **), int ex_tag, \
-                          int ex_class, int is_set); \
-STACK_OF(type) *d2i_ASN1_SET_OF_##type(STACK_OF(type) **a,unsigned char **pp, \
-                                      long length, \
-                                      type *(*func)(type **, \
-                                                    unsigned char **,long), \
-                                      void (*free_func)(type *), \
-                                      int ex_tag,int ex_class);
-
-#define IMPLEMENT_ASN1_SET_OF(type) \
-int i2d_ASN1_SET_OF_##type(STACK_OF(type) *a,unsigned char **pp, \
-                          int (*func)(type *,unsigned char **), int ex_tag, \
-                          int ex_class, int is_set) \
-    { return i2d_ASN1_SET((STACK *)a,pp,func,ex_tag,ex_class,is_set); } \
-STACK_OF(type) *d2i_ASN1_SET_OF_##type(STACK_OF(type) **a,unsigned char **pp, \
-                                      long length, \
-                                      type *(*func)(type **, \
-                                                    unsigned char **,long), \
-                                      void (*free_func)(type *), \
-                                      int ex_tag,int ex_class) \
-    { return (STACK_OF(type) *)d2i_ASN1_SET((STACK **)a,pp,length, \
-                                           (char *(*)())func, \
-                                           (void (*)())free_func, \
-                                           ex_tag,ex_class); }
+struct X509_algor_st;
+
+#define DECLARE_ASN1_SET_OF(type) /* filled in by mkstack.pl */
+#define IMPLEMENT_ASN1_SET_OF(type) /* nothing, no longer needed */
 
 typedef struct asn1_ctx_st
        {
@@ -176,7 +159,7 @@ typedef struct asn1_ctx_st
        int tag;        /* tag from last 'get object' */
        int xclass;     /* class from last 'get object' */
        long slen;      /* length of last 'get object' */
-       unsigned char *max; /* largest value of p alowed */
+       unsigned char *max; /* largest value of p allowed */
        unsigned char *q;/* temporary variable */
        unsigned char **pp;/* variable */
        int line;       /* used in error processing */
@@ -212,6 +195,10 @@ typedef struct asn1_string_st
        } ASN1_STRING;
 
 #define STABLE_FLAGS_MALLOC    0x01
+#define STABLE_NO_MASK         0x02
+#define DIRSTRING_TYPE \
+ (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_BMPSTRING|B_ASN1_UTF8STRING)
+#define PKCS9STRING_TYPE (DIRSTRING_TYPE|B_ASN1_IA5STRING)
 
 typedef struct asn1_string_table_st {
        int nid;
@@ -234,7 +221,7 @@ DECLARE_STACK_OF(ASN1_STRING_TABLE)
 #define ub_title                       64
 #define ub_email_address               128
 
-#ifndef DEBUG
+#ifdef NO_ASN1_TYPEDEFS
 #define ASN1_INTEGER           ASN1_STRING
 #define ASN1_ENUMERATED                ASN1_STRING
 #define ASN1_BIT_STRING                ASN1_STRING
@@ -250,6 +237,7 @@ DECLARE_STACK_OF(ASN1_STRING_TABLE)
 #define ASN1_BMPSTRING         ASN1_STRING
 #define ASN1_VISIBLESTRING     ASN1_STRING
 #define ASN1_UTF8STRING                ASN1_STRING
+#define ASN1_BOOLEAN           int
 #else
 typedef struct asn1_string_st ASN1_INTEGER;
 typedef struct asn1_string_st ASN1_ENUMERATED;
@@ -266,13 +254,99 @@ typedef struct asn1_string_st ASN1_TIME;
 typedef struct asn1_string_st ASN1_GENERALIZEDTIME;
 typedef struct asn1_string_st ASN1_VISIBLESTRING;
 typedef struct asn1_string_st ASN1_UTF8STRING;
+typedef int ASN1_BOOLEAN;
 #endif
 
+typedef int ASN1_NULL;
+
+/* Parameters used by ASN1_STRING_print_ex() */
+
+/* These determine which characters to escape:
+ * RFC2253 special characters, control characters and
+ * MSB set characters
+ */
+
+#define ASN1_STRFLGS_ESC_2253          1
+#define ASN1_STRFLGS_ESC_CTRL          2
+#define ASN1_STRFLGS_ESC_MSB           4
+
+
+/* This flag determines how we do escaping: normally
+ * RC2253 backslash only, set this to use backslash and
+ * quote.
+ */
+
+#define ASN1_STRFLGS_ESC_QUOTE         8
+
+
+/* These three flags are internal use only. */
+
+/* Character is a valid PrintableString character */
+#define CHARTYPE_PRINTABLESTRING       0x10
+/* Character needs escaping if it is the first character */
+#define CHARTYPE_FIRST_ESC_2253                0x20
+/* Character needs escaping if it is the last character */
+#define CHARTYPE_LAST_ESC_2253         0x40
+
+/* NB the internal flags are safely reused below by flags
+ * handled at the top level.
+ */
+
+/* If this is set we convert all character strings
+ * to UTF8 first 
+ */
+
+#define ASN1_STRFLGS_UTF8_CONVERT      0x10
+
+/* If this is set we don't attempt to interpret content:
+ * just assume all strings are 1 byte per character. This
+ * will produce some pretty odd looking output!
+ */
+
+#define ASN1_STRFLGS_IGNORE_TYPE       0x20
+
+/* If this is set we include the string type in the output */
+#define ASN1_STRFLGS_SHOW_TYPE         0x40
+
+/* This determines which strings to display and which to
+ * 'dump' (hex dump of content octets or DER encoding). We can
+ * only dump non character strings or everything. If we
+ * don't dump 'unknown' they are interpreted as character
+ * strings with 1 octet per character and are subject to
+ * the usual escaping options.
+ */
+
+#define ASN1_STRFLGS_DUMP_ALL          0x80
+#define ASN1_STRFLGS_DUMP_UNKNOWN      0x100
+
+/* These determine what 'dumping' does, we can dump the
+ * content octets or the DER encoding: both use the
+ * RFC2253 #XXXXX notation.
+ */
+
+#define ASN1_STRFLGS_DUMP_DER          0x200
+
+/* All the string flags consistent with RFC2253,
+ * escaping control characters isn't essential in
+ * RFC2253 but it is advisable anyway.
+ */
+
+#define ASN1_STRFLGS_RFC2253   (ASN1_STRFLGS_ESC_2253 | \
+                               ASN1_STRFLGS_ESC_CTRL | \
+                               ASN1_STRFLGS_ESC_MSB | \
+                               ASN1_STRFLGS_UTF8_CONVERT | \
+                               ASN1_STRFLGS_DUMP_UNKNOWN | \
+                               ASN1_STRFLGS_DUMP_DER)
+
+DECLARE_STACK_OF(ASN1_INTEGER)
+DECLARE_ASN1_SET_OF(ASN1_INTEGER)
+
 typedef struct asn1_type_st
        {
        int type;
        union   {
                char *ptr;
+               ASN1_BOOLEAN            boolean;
                ASN1_STRING *           asn1_string;
                ASN1_OBJECT *           object;
                ASN1_INTEGER *          integer;
@@ -514,6 +588,8 @@ void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value);
 ASN1_OBJECT *  ASN1_OBJECT_new(void );
 void           ASN1_OBJECT_free(ASN1_OBJECT *a);
 int            i2d_ASN1_OBJECT(ASN1_OBJECT *a,unsigned char **pp);
+ASN1_OBJECT *  c2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp,
+                       long length);
 ASN1_OBJECT *  d2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp,
                        long length);
 
@@ -536,14 +612,17 @@ unsigned char * ASN1_STRING_data(ASN1_STRING *x);
 ASN1_BIT_STRING *      ASN1_BIT_STRING_new(void);
 void           ASN1_BIT_STRING_free(ASN1_BIT_STRING *a);
 int            i2d_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp);
+int            i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp);
 ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,unsigned char **pp,
                        long length);
+ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,unsigned char **pp,
+                       long length);
 int            ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d,
                        int length );
 int            ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value);
 int            ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n);
 
-#ifdef HEADER_BIO_H
+#ifndef NO_BIO
 int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
                                BIT_STRING_BITNAME *tbl, int indent);
 #endif
@@ -557,8 +636,11 @@ int                d2i_ASN1_BOOLEAN(int *a,unsigned char **pp,long length);
 ASN1_INTEGER * ASN1_INTEGER_new(void);
 void           ASN1_INTEGER_free(ASN1_INTEGER *a);
 int            i2d_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp);
+int            i2c_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp);
 ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp,
                        long length);
+ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp,
+                       long length);
 ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a,unsigned char **pp,
                        long length);
 ASN1_INTEGER * ASN1_INTEGER_dup(ASN1_INTEGER *x);
@@ -573,6 +655,7 @@ ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a,unsigned char **pp,
 int ASN1_UTCTIME_check(ASN1_UTCTIME *a);
 ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s,time_t t);
 int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, char *str); 
+time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s);
 
 int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *a);
 ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,time_t t);
@@ -599,6 +682,11 @@ int                i2d_ASN1_UTF8STRING(ASN1_UTF8STRING *a,unsigned char **pp);
 ASN1_UTF8STRING *d2i_ASN1_UTF8STRING(ASN1_UTF8STRING **a,
                        unsigned char **pp,long length);
 
+ASN1_NULL *    ASN1_NULL_new(void);
+void           ASN1_NULL_free(ASN1_NULL *a);
+int            i2d_ASN1_NULL(ASN1_NULL *a,unsigned char **pp);
+ASN1_NULL *d2i_ASN1_NULL(ASN1_NULL **a, unsigned char **pp,long length);
+
 ASN1_BMPSTRING *       ASN1_BMPSTRING_new(void);
 void           ASN1_BMPSTRING_free(ASN1_BMPSTRING *a);
 int i2d_ASN1_BMPSTRING(ASN1_BMPSTRING *a, unsigned char **pp);
@@ -662,10 +750,10 @@ ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s,time_t t);
 int            i2d_ASN1_SET(STACK *a, unsigned char **pp,
                        int (*func)(), int ex_tag, int ex_class, int is_set);
 STACK *                d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,
-                       char *(*func)(), void (*free_func)(),
+                       char *(*func)(), void (*free_func)(void *),
                        int ex_tag, int ex_class);
 
-#ifdef HEADER_BIO_H
+#ifndef NO_BIO
 int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a);
 int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size);
 int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a);
@@ -718,16 +806,21 @@ char *ASN1_dup(int (*i2d)(),char *(*d2i)(),char *x);
 #ifndef NO_FP_API
 char *ASN1_d2i_fp(char *(*xnew)(),char *(*d2i)(),FILE *fp,unsigned char **x);
 int ASN1_i2d_fp(int (*i2d)(),FILE *out,unsigned char *x);
+int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags);
 #endif
 
-#ifdef HEADER_BIO_H
+int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in);
+
+#ifndef NO_BIO
 char *ASN1_d2i_bio(char *(*xnew)(),char *(*d2i)(),BIO *bp,unsigned char **x);
 int ASN1_i2d_bio(int (*i2d)(),BIO *out,unsigned char *x);
 int ASN1_UTCTIME_print(BIO *fp,ASN1_UTCTIME *a);
 int ASN1_GENERALIZEDTIME_print(BIO *fp,ASN1_GENERALIZEDTIME *a);
 int ASN1_TIME_print(BIO *fp,ASN1_TIME *a);
 int ASN1_STRING_print(BIO *bp,ASN1_STRING *v);
+int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags);
 int ASN1_parse(BIO *bp,unsigned char *pp,long len,int indent);
+int ASN1_parse_dump(BIO *bp,unsigned char *pp,long len,int indent,int dump);
 #endif
 const char *ASN1_tag2str(int tag);
 
@@ -757,9 +850,9 @@ int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a,long *num,
        unsigned char *data, int max_len);
 
 STACK *ASN1_seq_unpack(unsigned char *buf, int len, char *(*d2i)(),
-                                                void (*free_func)() ); 
+                                                void (*free_func)(void *) ); 
 unsigned char *ASN1_seq_pack(STACK *safes, int (*i2d)(), unsigned char **buf,
-                                                                int *len );
+                            int *len );
 void *ASN1_unpack_string(ASN1_STRING *oct, char *(*d2i)());
 ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct);
 
@@ -775,6 +868,7 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
 ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, 
                const unsigned char *in, int inlen, int inform, int nid);
 ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid);
+int ASN1_STRING_TABLE_add(int, long, long, unsigned long, unsigned long);
 void ASN1_STRING_TABLE_cleanup(void);
 
 /* BEGIN ERROR CODES */
@@ -832,6 +926,7 @@ void ASN1_STRING_TABLE_cleanup(void);
 #define ASN1_F_D2I_ASN1_GENERALIZEDTIME                         223
 #define ASN1_F_D2I_ASN1_HEADER                          127
 #define ASN1_F_D2I_ASN1_INTEGER                                 128
+#define ASN1_F_D2I_ASN1_NULL                            292
 #define ASN1_F_D2I_ASN1_OBJECT                          129
 #define ASN1_F_D2I_ASN1_OCTET_STRING                    130
 #define ASN1_F_D2I_ASN1_PRINT_TYPE                      131
@@ -989,6 +1084,7 @@ void ASN1_STRING_TABLE_cleanup(void);
 #define ASN1_R_BN_LIB                                   107
 #define ASN1_R_BOOLEAN_IS_WRONG_LENGTH                  108
 #define ASN1_R_BUFFER_TOO_SMALL                                 109
+#define ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER          166
 #define ASN1_R_DATA_IS_WRONG                            110
 #define ASN1_R_DECODE_ERROR                             155
 #define ASN1_R_DECODING_ERROR                           111
@@ -1002,6 +1098,7 @@ void ASN1_STRING_TABLE_cleanup(void);
 #define ASN1_R_EXPECTING_A_BIT_STRING                   116
 #define ASN1_R_EXPECTING_A_BOOLEAN                      117
 #define ASN1_R_EXPECTING_A_GENERALIZEDTIME              151
+#define ASN1_R_EXPECTING_A_NULL                                 164
 #define ASN1_R_EXPECTING_A_TIME                                 152
 #define ASN1_R_EXPECTING_A_UTCTIME                      118
 #define ASN1_R_FIRST_NUM_TOO_LARGE                      119
@@ -1019,6 +1116,7 @@ void ASN1_STRING_TABLE_cleanup(void);
 #define ASN1_R_MISSING_SECOND_NUMBER                    126
 #define ASN1_R_NON_HEX_CHARACTERS                       127
 #define ASN1_R_NOT_ENOUGH_DATA                          128
+#define ASN1_R_NULL_IS_WRONG_LENGTH                     165
 #define ASN1_R_ODD_NUMBER_OF_CHARS                      129
 #define ASN1_R_PARSING                                  130
 #define ASN1_R_PRIVATE_KEY_HEADER_MISSING               131