code and adds support to ASN1_TYPE and asn1parse.
Changes between 0.9.1c and 0.9.2
+ *) Preliminary support for ENUMERATED type. This is largely copied from the
+ INTEGER code.
+ [Steve Henson]
+
*) Add new function, EVP_MD_CTX_copy() to replace frequent use of memcpy.
[Eric A. Young, (from changes to C2Net SSLeay, integrated by Mark Cox)]
LIB=$(TOP)/libcrypto.a
LIBSRC= a_object.c a_bitstr.c a_utctm.c a_gentm.c a_time.c a_int.c a_octet.c \
a_print.c a_type.c a_set.c a_dup.c a_d2i_fp.c a_i2d_fp.c a_bmp.c \
- a_sign.c a_digest.c a_verify.c \
+ a_enum.c a_sign.c a_digest.c a_verify.c \
x_algor.c x_val.c x_pubkey.c x_sig.c x_req.c x_attrib.c \
x_name.c x_cinf.c x_x509.c x_crl.c x_info.c x_spki.c nsseq.c \
d2i_r_pr.c i2d_r_pr.c d2i_r_pu.c i2d_r_pu.c \
evp_asn1.c
LIBOBJ= a_object.o a_bitstr.o a_utctm.o a_gentm.o a_time.o a_int.o a_octet.o \
a_print.o a_type.o a_set.o a_dup.o a_d2i_fp.o a_i2d_fp.o a_bmp.o \
- a_sign.o a_digest.o a_verify.o \
+ a_enum.o a_sign.o a_digest.o a_verify.o \
x_algor.o x_val.o x_pubkey.o x_sig.o x_req.o x_attrib.o \
x_name.o x_cinf.o x_x509.o x_crl.o x_info.o x_spki.o nsseq.o \
d2i_r_pr.o i2d_r_pr.o d2i_r_pu.o i2d_r_pu.o \
case V_ASN1_NEG_INTEGER:
r=i2d_ASN1_INTEGER(a->value.integer,pp);
break;
+ case V_ASN1_ENUMERATED:
+ case V_ASN1_NEG_ENUMERATED:
+ r=i2d_ASN1_ENUMERATED(a->value.enumerated,pp);
+ break;
case V_ASN1_BIT_STRING:
r=i2d_ASN1_BIT_STRING(a->value.bit_string,pp);
break;
d2i_ASN1_INTEGER(NULL,&p,max-p)) == NULL)
goto err;
break;
+ case V_ASN1_ENUMERATED:
+ if ((ret->value.enumerated=
+ d2i_ASN1_ENUMERATED(NULL,&p,max-p)) == NULL)
+ goto err;
+ break;
case V_ASN1_BIT_STRING:
if ((ret->value.bit_string=
d2i_ASN1_BIT_STRING(NULL,&p,max-p)) == NULL)
break;
case V_ASN1_INTEGER:
case V_ASN1_NEG_INTEGER:
+ case V_ASN1_ENUMERATED:
+ case V_ASN1_NEG_ENUMERATED:
case V_ASN1_BIT_STRING:
case V_ASN1_OCTET_STRING:
case V_ASN1_SEQUENCE:
#define ASN1_F_ASN1_D2I_BIO 104
#define ASN1_F_ASN1_D2I_FP 105
#define ASN1_F_ASN1_DUP 106
+#define ASN1_F_ASN1_ENUMERATED_SET 232
+#define ASN1_F_ASN1_ENUMERATED_TO_BN 233
#define ASN1_F_ASN1_GENERALIZEDTIME_NEW 222
#define ASN1_F_ASN1_GET_OBJECT 107
#define ASN1_F_ASN1_HEADER_NEW 108
#define ASN1_F_ASN1_UTCTIME_NEW 120
#define ASN1_F_ASN1_VERIFY 121
#define ASN1_F_BASIC_CONSTRAINTS_NEW 226
+#define ASN1_F_BN_TO_ASN1_ENUMERATED 234
#define ASN1_F_BN_TO_ASN1_INTEGER 122
#define ASN1_F_D2I_ASN1_BIT_STRING 123
#define ASN1_F_D2I_ASN1_BMPSTRING 124
#define ASN1_F_D2I_ASN1_BOOLEAN 125
#define ASN1_F_D2I_ASN1_BYTES 126
+#define ASN1_F_D2I_ASN1_ENUMERATED 235
#define ASN1_F_D2I_ASN1_GENERALIZEDTIME 223
#define ASN1_F_D2I_ASN1_HEADER 127
#define ASN1_F_D2I_ASN1_INTEGER 128
#define ASN1_R_DATA_IS_WRONG 110
#define ASN1_R_DECODING_ERROR 111
#define ASN1_R_ERROR_PARSING_SET_ELEMENT 112
+#define ASN1_R_EXPECTING_AN_ENUMERATED 154
#define ASN1_R_EXPECTING_AN_INTEGER 113
#define ASN1_R_EXPECTING_AN_OBJECT 114
#define ASN1_R_EXPECTING_AN_OCTET_STRING 115
#define V_ASN1_OBJECT_DESCRIPTOR 7
#define V_ASN1_EXTERNAL 8
#define V_ASN1_REAL 9
-#define V_ASN1_ENUMERATED 10 /* microsoft weirdness */
+#define V_ASN1_ENUMERATED 10
+#define V_ASN1_NEG_ENUMERATED (10+0x100)
#define V_ASN1_SEQUENCE 16
#define V_ASN1_SET 17
#define V_ASN1_NUMERICSTRING 18 /**/
#ifndef DEBUG
#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_BMPSTRING ASN1_STRING
#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;
ASN1_STRING * asn1_string;
ASN1_OBJECT * object;
ASN1_INTEGER * integer;
+ ASN1_ENUMERATED * enumerated;
ASN1_BIT_STRING * bit_string;
ASN1_OCTET_STRING * octet_string;
ASN1_PRINTABLESTRING * printablestring;
/* i2d_ASN1_INTEGER() is a function */
/* d2i_ASN1_INTEGER() is a function */
+#define ASN1_ENUMERATED_new() (ASN1_ENUMERATED *)\
+ ASN1_STRING_type_new(V_ASN1_ENUMERATED)
+#define ASN1_ENUMERATED_free(a) ASN1_STRING_free((ASN1_STRING *)a)
+#define ASN1_ENUMERATED_dup(a) (ASN1_ENUMERATED *)ASN1_STRING_dup((ASN1_STRING *)a)
+#define ASN1_ENUMERATED_cmp(a,b) ASN1_STRING_cmp(\
+ (ASN1_STRING *)a,(ASN1_STRING *)b)
+/* ASN1_ENUMERATED_set() is a function, also see BN_to_ASN1_ENUMERATED() */
+/* ASN1_ENUMERATED_get() is a function, also see ASN1_ENUMERATED_to_BN() */
+/* i2d_ASN1_ENUMERATED() is a function */
+/* d2i_ASN1_ENUMERATED() is a function */
+
#define ASN1_OCTET_STRING_new() (ASN1_OCTET_STRING *)\
ASN1_STRING_type_new(V_ASN1_OCTET_STRING)
#define ASN1_OCTET_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp,
long length);
+int i2d_ASN1_ENUMERATED(ASN1_ENUMERATED *a,unsigned char **pp);
+ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a,unsigned char **pp,
+ long length);
+
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);
#ifdef HEADER_BIO_H
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);
+int a2i_ASN1_ENUMERATED(BIO *bp,ASN1_ENUMERATED *bs,char *buf,int size);
int i2a_ASN1_OBJECT(BIO *bp,ASN1_OBJECT *a);
int a2i_ASN1_STRING(BIO *bp,ASN1_STRING *bs,char *buf,int size);
int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type);
ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai);
BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai,BIGNUM *bn);
+int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v);
+long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a);
+ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai);
+BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai,BIGNUM *bn);
+
/* General */
/* given a string, return the correct type, max is the maximum length */
int ASN1_PRINTABLE_type(unsigned char *s, int max);
int d2i_ASN1_BOOLEAN();
int i2d_ASN1_INTEGER();
ASN1_INTEGER *d2i_ASN1_INTEGER();
+int i2d_ASN1_ENUMERATED();
+ASN1_INTEGER *d2i_ASN1_ENUMERATED();
int ASN1_UTCTIME_check();
ASN1_UTCTIME *ASN1_UTCTIME_set();
int ASN1_UTCTIME_set_string();
long ASN1_INTEGER_get();
ASN1_INTEGER *BN_to_ASN1_INTEGER();
BIGNUM *ASN1_INTEGER_to_BN();
+int ASN1_ENUMERATED_set();
+long ASN1_ENUMERATED_get();
+ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED();
+BIGNUM *ASN1_ENUMERATED_to_BN();
int ASN1_PRINTABLE_type();
int i2d_ASN1_bytes();
ASN1_STRING *d2i_ASN1_bytes();
int ASN1_parse();
int i2a_ASN1_INTEGER();
int a2i_ASN1_INTEGER();
+int i2a_ASN1_ENUMERATED();
+int a2i_ASN1_ENUMERATED();
int i2a_ASN1_OBJECT();
int i2t_ASN1_OBJECT();
int a2i_ASN1_STRING();
#define ASN1_F_ASN1_D2I_BIO 104
#define ASN1_F_ASN1_D2I_FP 105
#define ASN1_F_ASN1_DUP 106
+#define ASN1_F_ASN1_ENUMERATED_SET 232
+#define ASN1_F_ASN1_ENUMERATED_TO_BN 233
#define ASN1_F_ASN1_GENERALIZEDTIME_NEW 222
#define ASN1_F_ASN1_GET_OBJECT 107
#define ASN1_F_ASN1_HEADER_NEW 108
#define ASN1_F_ASN1_UTCTIME_NEW 120
#define ASN1_F_ASN1_VERIFY 121
#define ASN1_F_BASIC_CONSTRAINTS_NEW 226
+#define ASN1_F_BN_TO_ASN1_ENUMERATED 234
#define ASN1_F_BN_TO_ASN1_INTEGER 122
#define ASN1_F_D2I_ASN1_BIT_STRING 123
#define ASN1_F_D2I_ASN1_BMPSTRING 124
#define ASN1_F_D2I_ASN1_BOOLEAN 125
#define ASN1_F_D2I_ASN1_BYTES 126
+#define ASN1_F_D2I_ASN1_ENUMERATED 235
#define ASN1_F_D2I_ASN1_GENERALIZEDTIME 223
#define ASN1_F_D2I_ASN1_HEADER 127
#define ASN1_F_D2I_ASN1_INTEGER 128
#define ASN1_R_DATA_IS_WRONG 110
#define ASN1_R_DECODING_ERROR 111
#define ASN1_R_ERROR_PARSING_SET_ELEMENT 112
+#define ASN1_R_EXPECTING_AN_ENUMERATED 154
#define ASN1_R_EXPECTING_AN_INTEGER 113
#define ASN1_R_EXPECTING_AN_OBJECT 114
#define ASN1_R_EXPECTING_AN_OCTET_STRING 115
{ERR_PACK(0,ASN1_F_ASN1_D2I_BIO,0), "ASN1_d2i_bio"},
{ERR_PACK(0,ASN1_F_ASN1_D2I_FP,0), "ASN1_d2i_fp"},
{ERR_PACK(0,ASN1_F_ASN1_DUP,0), "ASN1_dup"},
+{ERR_PACK(0,ASN1_F_ASN1_ENUMERATED_SET,0), "ASN1_ENUMERATED_set"},
+{ERR_PACK(0,ASN1_F_ASN1_ENUMERATED_TO_BN,0), "ASN1_ENUMERATED_to_BN"},
{ERR_PACK(0,ASN1_F_ASN1_GENERALIZEDTIME_NEW,0), "ASN1_GENERALIZEDTIME_NEW"},
{ERR_PACK(0,ASN1_F_ASN1_GET_OBJECT,0), "ASN1_get_object"},
{ERR_PACK(0,ASN1_F_ASN1_HEADER_NEW,0), "ASN1_HEADER_new"},
{ERR_PACK(0,ASN1_F_ASN1_UTCTIME_NEW,0), "ASN1_UTCTIME_NEW"},
{ERR_PACK(0,ASN1_F_ASN1_VERIFY,0), "ASN1_VERIFY"},
{ERR_PACK(0,ASN1_F_BASIC_CONSTRAINTS_NEW,0), "BASIC_CONSTRAINTS_NEW"},
+{ERR_PACK(0,ASN1_F_BN_TO_ASN1_ENUMERATED,0), "BN_to_ASN1_ENUMERATED"},
{ERR_PACK(0,ASN1_F_BN_TO_ASN1_INTEGER,0), "BN_to_ASN1_INTEGER"},
{ERR_PACK(0,ASN1_F_D2I_ASN1_BIT_STRING,0), "d2i_ASN1_BIT_STRING"},
{ERR_PACK(0,ASN1_F_D2I_ASN1_BMPSTRING,0), "d2i_ASN1_BMPSTRING"},
{ERR_PACK(0,ASN1_F_D2I_ASN1_BOOLEAN,0), "d2i_ASN1_BOOLEAN"},
{ERR_PACK(0,ASN1_F_D2I_ASN1_BYTES,0), "d2i_ASN1_bytes"},
+{ERR_PACK(0,ASN1_F_D2I_ASN1_ENUMERATED,0), "d2i_ASN1_ENUMERATED"},
{ERR_PACK(0,ASN1_F_D2I_ASN1_GENERALIZEDTIME,0), "d2i_ASN1_GENERALIZEDTIME"},
{ERR_PACK(0,ASN1_F_D2I_ASN1_HEADER,0), "d2i_ASN1_HEADER"},
{ERR_PACK(0,ASN1_F_D2I_ASN1_INTEGER,0), "d2i_ASN1_INTEGER"},
{ASN1_R_DATA_IS_WRONG ,"data is wrong"},
{ASN1_R_DECODING_ERROR ,"decoding error"},
{ASN1_R_ERROR_PARSING_SET_ELEMENT ,"error parsing set element"},
+{ASN1_R_EXPECTING_AN_ENUMERATED ,"expecting an enumerated"},
{ASN1_R_EXPECTING_AN_INTEGER ,"expecting an integer"},
{ASN1_R_EXPECTING_AN_OBJECT ,"expecting an object"},
{ASN1_R_EXPECTING_AN_OCTET_STRING ,"expecting an octet string"},
p="BOOLEAN";
else if (tag == V_ASN1_INTEGER)
p="INTEGER";
+ else if (tag == V_ASN1_ENUMERATED)
+ p="ENUMERATED";
else if (tag == V_ASN1_BIT_STRING)
p="BIT STRING";
else if (tag == V_ASN1_OCTET_STRING)
}
ASN1_INTEGER_free(bs);
}
+ else if (tag == V_ASN1_ENUMERATED)
+ {
+ ASN1_ENUMERATED *bs;
+ int i;
+
+ opp=op;
+ bs=d2i_ASN1_ENUMERATED(NULL,&opp,len+hl);
+ if (bs != NULL)
+ {
+ if (BIO_write(bp,":",1) <= 0) goto end;
+ if (bs->type == V_ASN1_NEG_ENUMERATED)
+ if (BIO_write(bp,"-",1) <= 0)
+ goto end;
+ for (i=0; i<bs->length; i++)
+ {
+ if (BIO_printf(bp,"%02X",
+ bs->data[i]) <= 0)
+ goto end;
+ }
+ if (bs->length == 0)
+ {
+ if (BIO_write(bp,"00",2) <= 0)
+ goto end;
+ }
+ }
+ else
+ {
+ if (BIO_write(bp,"BAD ENUMERATED",11) <= 0)
+ goto end;
+ }
+ ASN1_ENUMERATED_free(bs);
+ }
if (!nl)
{