Preliminary streaming ASN1 encode support.
[openssl.git] / crypto / asn1 / asn1.h
index 2d27f0782d59b67c25269ce9bbe2f1fd539b5f30..e870948e8df0a1cce0b41bcf88363f4a797c9469 100644 (file)
@@ -71,6 +71,7 @@
 #include <openssl/symhacks.h>
 
 #include <openssl/e_os2.h>
+#include <openssl/ossl_typ.h>
 
 #ifdef OPENSSL_BUILD_SHLIBCRYPTO
 # undef OPENSSL_EXTERN
@@ -191,6 +192,11 @@ typedef struct asn1_object_st
        } ASN1_OBJECT;
 
 #define ASN1_STRING_FLAG_BITS_LEFT 0x08 /* Set if 0x07 has bits left value */
+/* This indicates that the ASN1_STRING is not a real value but just a place
+ * holder for the location where indefinite length constructed data should
+ * be inserted in the memory buffer 
+ */
+#define ASN1_STRING_FLAG_NDEF 0x010 
 /* This is the base type that holds just about everything :-) */
 typedef struct asn1_string_st
        {
@@ -246,44 +252,6 @@ DECLARE_STACK_OF(ASN1_STRING_TABLE)
 #define ub_title                       64
 #define ub_email_address               128
 
-#ifdef NO_ASN1_TYPEDEFS
-#define ASN1_INTEGER           ASN1_STRING
-#define ASN1_ENUMERATED                ASN1_STRING
-#define ASN1_BIT_STRING                ASN1_STRING
-#define ASN1_OCTET_STRING      ASN1_STRING
-#define ASN1_PRINTABLESTRING   ASN1_STRING
-#define ASN1_T61STRING         ASN1_STRING
-#define ASN1_IA5STRING         ASN1_STRING
-#define ASN1_UTCTIME           ASN1_STRING
-#define ASN1_GENERALIZEDTIME   ASN1_STRING
-#define ASN1_TIME              ASN1_STRING
-#define ASN1_GENERALSTRING     ASN1_STRING
-#define ASN1_UNIVERSALSTRING   ASN1_STRING
-#define ASN1_BMPSTRING         ASN1_STRING
-#define ASN1_VISIBLESTRING     ASN1_STRING
-#define ASN1_UTF8STRING                ASN1_STRING
-#define ASN1_BOOLEAN           int
-#define ASN1_NULL              int
-#else
-typedef struct asn1_string_st ASN1_INTEGER;
-typedef struct asn1_string_st ASN1_ENUMERATED;
-typedef struct asn1_string_st ASN1_BIT_STRING;
-typedef struct asn1_string_st ASN1_OCTET_STRING;
-typedef struct asn1_string_st ASN1_PRINTABLESTRING;
-typedef struct asn1_string_st ASN1_T61STRING;
-typedef struct asn1_string_st ASN1_IA5STRING;
-typedef struct asn1_string_st ASN1_GENERALSTRING;
-typedef struct asn1_string_st ASN1_UNIVERSALSTRING;
-typedef struct asn1_string_st ASN1_BMPSTRING;
-typedef struct asn1_string_st ASN1_UTCTIME;
-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;
-typedef int ASN1_NULL;
-#endif
-
 /* Declarations for template structures: for full definitions
  * see asn1t.h
  */
@@ -317,13 +285,86 @@ typedef struct ASN1_VALUE_st ASN1_VALUE;
        int i2d_##name(const type *a, unsigned char **out); \
        DECLARE_ASN1_ITEM(name)
 
+#define        DECLARE_ASN1_NDEF_FUNCTION(name) \
+       int i2d_##name##_NDEF(name *a, unsigned char **out);
+
 #define DECLARE_ASN1_FUNCTIONS_const(name) \
        name *name##_new(void); \
        void name##_free(name *a);
 
+
+/* The following macros and typedefs allow an ASN1_ITEM
+ * to be embedded in a structure and referenced. Since
+ * the ASN1_ITEM pointers need to be globally accessible
+ * (possibly from shared libraries) they may exist in
+ * different forms. On platforms that support it the
+ * ASN1_ITEM structure itself will be globally exported.
+ * Other platforms will export a function that returns
+ * an ASN1_ITEM pointer.
+ *
+ * To handle both cases transparently the macros below
+ * should be used instead of hard coding an ASN1_ITEM
+ * pointer in a structure.
+ *
+ * The structure will look like this:
+ *
+ * typedef struct SOMETHING_st {
+ *      ...
+ *      ASN1_ITEM_EXP *iptr;
+ *      ...
+ * } SOMETHING; 
+ *
+ * It would be initialised as e.g.:
+ *
+ * SOMETHING somevar = {...,ASN1_ITEM_ref(X509),...};
+ *
+ * and the actual pointer extracted with:
+ *
+ * const ASN1_ITEM *it = ASN1_ITEM_ptr(somevar.iptr);
+ *
+ * Finally an ASN1_ITEM pointer can be extracted from an
+ * appropriate reference with: ASN1_ITEM_rptr(X509). This
+ * would be used when a function takes an ASN1_ITEM * argument.
+ *
+ */
+
+#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
+
+/* ASN1_ITEM pointer exported type */
+typedef const ASN1_ITEM ASN1_ITEM_EXP;
+
+/* Macro to obtain ASN1_ITEM pointer from exported type */
+#define ASN1_ITEM_ptr(iptr) (iptr)
+
+/* Macro to include ASN1_ITEM pointer from base type */
+#define ASN1_ITEM_ref(iptr) (&(iptr##_it))
+
+#define ASN1_ITEM_rptr(ref) (&(ref##_it))
+
 #define DECLARE_ASN1_ITEM(name) \
        OPENSSL_EXTERN const ASN1_ITEM name##_it;
 
+#else
+
+/* Platforms that can't easily handle shared global variables are declared
+ * as functions returning ASN1_ITEM pointers.
+ */
+
+/* ASN1_ITEM pointer exported type */
+typedef const ASN1_ITEM * ASN1_ITEM_EXP(void);
+
+/* Macro to obtain ASN1_ITEM pointer from exported type */
+#define ASN1_ITEM_ptr(iptr) (iptr())
+
+/* Macro to include ASN1_ITEM pointer from base type */
+#define ASN1_ITEM_ref(iptr) (iptr##_it)
+
+#define ASN1_ITEM_rptr(ref) (ref##_it())
+
+#define DECLARE_ASN1_ITEM(name) \
+       const ASN1_ITEM * name##_it(void);
+
+#endif
 
 /* Parameters used by ASN1_STRING_print_ex() */
 
@@ -407,6 +448,8 @@ typedef struct ASN1_VALUE_st ASN1_VALUE;
 DECLARE_STACK_OF(ASN1_INTEGER)
 DECLARE_ASN1_SET_OF(ASN1_INTEGER)
 
+DECLARE_STACK_OF(ASN1_GENERALSTRING)
+
 typedef struct asn1_type_st
        {
        int type;
@@ -738,6 +781,7 @@ int         ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b);
 int    ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, unsigned char *data, int len);
 
 DECLARE_ASN1_FUNCTIONS(ASN1_VISIBLESTRING)
+DECLARE_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING)
 DECLARE_ASN1_FUNCTIONS(ASN1_UTF8STRING)
 DECLARE_ASN1_FUNCTIONS(ASN1_NULL)
 DECLARE_ASN1_FUNCTIONS(ASN1_BMPSTRING)
@@ -752,10 +796,13 @@ DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT)
 DECLARE_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING)
 DECLARE_ASN1_FUNCTIONS(ASN1_T61STRING)
 DECLARE_ASN1_FUNCTIONS(ASN1_IA5STRING)
+DECLARE_ASN1_FUNCTIONS(ASN1_GENERALSTRING)
 DECLARE_ASN1_FUNCTIONS(ASN1_UTCTIME)
 DECLARE_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME)
 DECLARE_ASN1_FUNCTIONS(ASN1_TIME)
 
+DECLARE_ASN1_ITEM(ASN1_OCTET_STRING_NDEF)
+
 ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s,time_t t);
 int ASN1_TIME_check(ASN1_TIME *t);
 ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out);
@@ -812,6 +859,7 @@ int ASN1_get_object(unsigned char **pp, long *plength, int *ptag,
 int ASN1_check_infinite_end(unsigned char **p,long len);
 void ASN1_put_object(unsigned char **pp, int constructed, int length,
        int tag, int xclass);
+int ASN1_put_eoc(unsigned char **pp);
 int ASN1_object_size(int constructed, int length, int tag);
 
 /* Used to implement other functions */
@@ -852,8 +900,6 @@ void ASN1_HEADER_free(ASN1_HEADER *a);
 
 int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s);
 
-void ERR_load_ASN1_strings(void);
-
 /* Not used that much at this point, except for the first two */
 ASN1_METHOD *X509_asn1_meth(void);
 ASN1_METHOD *RSAPrivateKey_asn1_meth(void);
@@ -900,12 +946,15 @@ ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it);
 void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it);
 ASN1_VALUE * ASN1_item_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_ITEM *it);
 int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it);
+int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it);
 
+void ASN1_add_oid_module(void);
 
 /* BEGIN ERROR CODES */
 /* The following lines are auto generated by the script mkerr.pl. Any changes
  * made after this point may be overwritten when the script is next run.
  */
+void ERR_load_ASN1_strings(void);
 
 /* Error codes for the ASN1 functions. */
 
@@ -972,11 +1021,14 @@ int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it);
 #define ASN1_F_D2I_X509_PKEY                            159
 #define ASN1_F_I2D_ASN1_TIME                            160
 #define ASN1_F_I2D_DSA_PUBKEY                           161
+#define ASN1_F_I2D_ECDSA_PUBKEY                                 174
+#define ASN1_F_I2D_EC_PUBKEY                            176
 #define ASN1_F_I2D_NETSCAPE_RSA                                 162
 #define ASN1_F_I2D_PRIVATEKEY                           163
 #define ASN1_F_I2D_PUBLICKEY                            164
 #define ASN1_F_I2D_RSA_PUBKEY                           165
 #define ASN1_F_LONG_C2I                                         166
+#define ASN1_F_OID_MODULE_INIT                          175
 #define ASN1_F_PKCS5_PBE2_SET                           167
 #define ASN1_F_X509_CINF_NEW                            168
 #define ASN1_F_X509_CRL_ADD0_REVOKED                    169
@@ -986,6 +1038,7 @@ int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it);
 #define ASN1_F_X509_PKEY_NEW                            173
 
 /* Reason codes. */
+#define ASN1_R_ADDING_OBJECT                            171
 #define ASN1_R_AUX_ERROR                                100
 #define ASN1_R_BAD_CLASS                                101
 #define ASN1_R_BAD_OBJECT_HEADER                        102
@@ -999,6 +1052,7 @@ int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it);
 #define ASN1_R_DECODE_ERROR                             110
 #define ASN1_R_DECODING_ERROR                           111
 #define ASN1_R_ENCODE_ERROR                             112
+#define ASN1_R_ERROR_LOADING_SECTION                    172
 #define ASN1_R_ERROR_PARSING_SET_ELEMENT                113
 #define ASN1_R_ERROR_SETTING_CIPHER_PARAMS              114
 #define ASN1_R_EXPECTING_AN_INTEGER                     115
@@ -1013,6 +1067,7 @@ int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it);
 #define ASN1_R_ILLEGAL_CHARACTERS                       124
 #define ASN1_R_ILLEGAL_NULL                             125
 #define ASN1_R_ILLEGAL_OPTIONAL_ANY                     126
+#define ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE                 170
 #define ASN1_R_ILLEGAL_TAGGED_ANY                       127
 #define ASN1_R_INTEGER_TOO_LARGE_FOR_LONG               128
 #define ASN1_R_INVALID_BMPSTRING_LENGTH                         129
@@ -1061,4 +1116,3 @@ int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it);
 }
 #endif
 #endif
-