New ASN1 macros which will encode an empty SEQUENCE OF.
[oweals/openssl.git] / crypto / asn1 / x_crl.c
index 6755cd610424941d06148e342e691d169e3207e2..9f200a763172807fb4efe069bc7ee12079da900a 100644 (file)
 #include <openssl/asn1_mac.h>
 #include <openssl/x509.h>
 
-static int X509_REVOKED_cmp(X509_REVOKED **a,X509_REVOKED **b);
-static int X509_REVOKED_seq_cmp(X509_REVOKED **a,X509_REVOKED **b);
+static int X509_REVOKED_cmp(const X509_REVOKED * const *a,
+                               const X509_REVOKED * const *b);
+static int X509_REVOKED_seq_cmp(const X509_REVOKED * const *a,
+                               const X509_REVOKED * const *b);
 int i2d_X509_REVOKED(X509_REVOKED *a, unsigned char **pp)
        {
        M_ASN1_I2D_vars(a);
 
        M_ASN1_I2D_len(a->serialNumber,i2d_ASN1_INTEGER);
        M_ASN1_I2D_len(a->revocationDate,i2d_ASN1_TIME);
-       M_ASN1_I2D_len_SEQUENCE_opt_type(X509_EXTENSION,a->extensions,
+       M_ASN1_I2D_len_SEQUENCE_opt_ex_type(X509_EXTENSION,a->extensions,
                                         i2d_X509_EXTENSION);
 
        M_ASN1_I2D_seq_total();
 
        M_ASN1_I2D_put(a->serialNumber,i2d_ASN1_INTEGER);
        M_ASN1_I2D_put(a->revocationDate,i2d_ASN1_TIME);
-       M_ASN1_I2D_put_SEQUENCE_opt_type(X509_EXTENSION,a->extensions,
+       M_ASN1_I2D_put_SEQUENCE_opt_ex_type(X509_EXTENSION,a->extensions,
                                         i2d_X509_EXTENSION);
 
        M_ASN1_I2D_finish();
@@ -100,7 +102,8 @@ int i2d_X509_CRL_INFO(X509_CRL_INFO *a, unsigned char **pp)
        {
        int v1=0;
        long l=0;
-       int (*old_cmp)(X509_REVOKED **,X509_REVOKED **);
+       int (*old_cmp)(const X509_REVOKED * const *,
+                       const X509_REVOKED * const *);
        M_ASN1_I2D_vars(a);
        
        old_cmp=sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_seq_cmp);
@@ -116,9 +119,9 @@ int i2d_X509_CRL_INFO(X509_CRL_INFO *a, unsigned char **pp)
        M_ASN1_I2D_len(a->lastUpdate,i2d_ASN1_TIME);
        if (a->nextUpdate != NULL)
                { M_ASN1_I2D_len(a->nextUpdate,i2d_ASN1_TIME); }
-       M_ASN1_I2D_len_SEQUENCE_opt_type(X509_REVOKED,a->revoked,
+       M_ASN1_I2D_len_SEQUENCE_opt_ex_type(X509_REVOKED,a->revoked,
                                         i2d_X509_REVOKED);
-       M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(X509_EXTENSION,a->extensions,
+       M_ASN1_I2D_len_EXP_SEQUENCE_opt_ex_type(X509_EXTENSION,a->extensions,
                                             i2d_X509_EXTENSION,0,
                                             V_ASN1_SEQUENCE,v1);
 
@@ -130,12 +133,12 @@ int i2d_X509_CRL_INFO(X509_CRL_INFO *a, unsigned char **pp)
                }
        M_ASN1_I2D_put(a->sig_alg,i2d_X509_ALGOR);
        M_ASN1_I2D_put(a->issuer,i2d_X509_NAME);
-       M_ASN1_I2D_put(a->lastUpdate,i2d_ASN1_UTCTIME);
+       M_ASN1_I2D_put(a->lastUpdate,i2d_ASN1_TIME);
        if (a->nextUpdate != NULL)
-               { M_ASN1_I2D_put(a->nextUpdate,i2d_ASN1_UTCTIME); }
-       M_ASN1_I2D_put_SEQUENCE_opt_type(X509_REVOKED,a->revoked,
+               { M_ASN1_I2D_put(a->nextUpdate,i2d_ASN1_TIME); }
+       M_ASN1_I2D_put_SEQUENCE_opt_ex_type(X509_REVOKED,a->revoked,
                                         i2d_X509_REVOKED);
-       M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(X509_EXTENSION,a->extensions,
+       M_ASN1_I2D_put_EXP_SEQUENCE_opt_ex_type(X509_EXTENSION,a->extensions,
                                             i2d_X509_EXTENSION,0,
                                             V_ASN1_SEQUENCE,v1);
 
@@ -164,13 +167,9 @@ X509_CRL_INFO *d2i_X509_CRL_INFO(X509_CRL_INFO **a, unsigned char **pp,
        M_ASN1_D2I_get(ret->issuer,d2i_X509_NAME);
        M_ASN1_D2I_get(ret->lastUpdate,d2i_ASN1_TIME);
        /* Manually handle the OPTIONAL ASN1_TIME stuff */
-       if(c.slen != 0
-          && ( (M_ASN1_next & ~V_ASN1_CONSTRUCTED) ==
-                   (V_ASN1_UNIVERSAL|V_ASN1_UTCTIME)
-               || (M_ASN1_next & ~V_ASN1_CONSTRUCTED) ==
-                   (V_ASN1_UNIVERSAL|V_ASN1_GENERALIZEDTIME) ) ) {
-               M_ASN1_D2I_get(ret->nextUpdate,d2i_ASN1_TIME);
-       }
+       /* First try UTCTime */
+       M_ASN1_D2I_get_opt(ret->nextUpdate,d2i_ASN1_UTCTIME, V_ASN1_UTCTIME);
+       /* If that doesn't work try GeneralizedTime */
        if(!ret->nextUpdate) 
                M_ASN1_D2I_get_opt(ret->nextUpdate,d2i_ASN1_GENERALIZEDTIME,
                                                        V_ASN1_GENERALIZEDTIME);
@@ -287,7 +286,7 @@ void X509_REVOKED_free(X509_REVOKED *a)
        M_ASN1_INTEGER_free(a->serialNumber);
        M_ASN1_UTCTIME_free(a->revocationDate);
        sk_X509_EXTENSION_pop_free(a->extensions,X509_EXTENSION_free);
-       Free(a);
+       OPENSSL_free(a);
        }
 
 void X509_CRL_INFO_free(X509_CRL_INFO *a)
@@ -301,7 +300,7 @@ void X509_CRL_INFO_free(X509_CRL_INFO *a)
                M_ASN1_UTCTIME_free(a->nextUpdate);
        sk_X509_REVOKED_pop_free(a->revoked,X509_REVOKED_free);
        sk_X509_EXTENSION_pop_free(a->extensions,X509_EXTENSION_free);
-       Free(a);
+       OPENSSL_free(a);
        }
 
 void X509_CRL_free(X509_CRL *a)
@@ -326,17 +325,19 @@ void X509_CRL_free(X509_CRL *a)
        X509_CRL_INFO_free(a->crl);
        X509_ALGOR_free(a->sig_alg);
        M_ASN1_BIT_STRING_free(a->signature);
-       Free(a);
+       OPENSSL_free(a);
        }
 
-static int X509_REVOKED_cmp(X509_REVOKED **a, X509_REVOKED **b)
+static int X509_REVOKED_cmp(const X509_REVOKED * const *a,
+                       const X509_REVOKED * const *b)
        {
        return(ASN1_STRING_cmp(
                (ASN1_STRING *)(*a)->serialNumber,
                (ASN1_STRING *)(*b)->serialNumber));
        }
 
-static int X509_REVOKED_seq_cmp(X509_REVOKED **a, X509_REVOKED **b)
+static int X509_REVOKED_seq_cmp(const X509_REVOKED * const *a,
+                               const X509_REVOKED * const *b)
        {
        return((*a)->sequence-(*b)->sequence);
        }