Add support for the noCheck OCSP extension. This is
[openssl.git] / crypto / x509v3 / v3_lib.c
index 4242d130a2c515a17605877fbfbaf973138e3182..33765118c22015b47497d6b207b40d7e24f20615 100644 (file)
 
 #include "ext_dat.h"
 
-static STACK *ext_list = NULL;
+static STACK_OF(X509V3_EXT_METHOD) *ext_list = NULL;
 
-static int ext_cmp(X509V3_EXT_METHOD **a, X509V3_EXT_METHOD **b);
+static int ext_cmp(const X509V3_EXT_METHOD * const *a,
+               const X509V3_EXT_METHOD * const *b);
 static void ext_list_free(X509V3_EXT_METHOD *ext);
 
 int X509V3_EXT_add(X509V3_EXT_METHOD *ext)
 {
-       if(!ext_list && !(ext_list = sk_new(ext_cmp))) {
+       if(!ext_list && !(ext_list = sk_X509V3_EXT_METHOD_new(ext_cmp))) {
                X509V3err(X509V3_F_X509V3_EXT_ADD,ERR_R_MALLOC_FAILURE);
                return 0;
        }
-       if(!sk_push(ext_list, (char *)ext)) {
+       if(!sk_X509V3_EXT_METHOD_push(ext_list, ext)) {
                X509V3err(X509V3_F_X509V3_EXT_ADD,ERR_R_MALLOC_FAILURE);
                return 0;
        }
        return 1;
 }
 
-static int ext_cmp(X509V3_EXT_METHOD **a, X509V3_EXT_METHOD **b)
+static int ext_cmp(const X509V3_EXT_METHOD * const *a,
+               const X509V3_EXT_METHOD * const *b)
 {
        return ((*a)->ext_nid - (*b)->ext_nid);
 }
@@ -95,12 +97,12 @@ X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid)
        tmp.ext_nid = nid;
        ret = (X509V3_EXT_METHOD **) OBJ_bsearch((char *)&t,
                        (char *)standard_exts, STANDARD_EXTENSION_COUNT,
-                       sizeof(X509V3_EXT_METHOD *), (int (*)())ext_cmp);
+                       sizeof(X509V3_EXT_METHOD *), (int (*)(const void *, const void *))ext_cmp);
        if(ret) return *ret;
        if(!ext_list) return NULL;
-       idx = sk_find(ext_list, (char *)&tmp);
+       idx = sk_X509V3_EXT_METHOD_find(ext_list, &tmp);
        if(idx == -1) return NULL;
-       return (X509V3_EXT_METHOD *)sk_value(ext_list, idx);
+       return sk_X509V3_EXT_METHOD_value(ext_list, idx);
 }
 
 X509V3_EXT_METHOD *X509V3_EXT_get(X509_EXTENSION *ext)
@@ -125,7 +127,7 @@ int X509V3_EXT_add_alias(int nid_to, int nid_from)
                X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS,X509V3_R_EXTENSION_NOT_FOUND);
                return 0;
        }
-       if(!(tmpext = (X509V3_EXT_METHOD *)Malloc(sizeof(X509V3_EXT_METHOD)))) {
+       if(!(tmpext = (X509V3_EXT_METHOD *)OPENSSL_malloc(sizeof(X509V3_EXT_METHOD)))) {
                X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS,ERR_R_MALLOC_FAILURE);
                return 0;
        }
@@ -137,13 +139,13 @@ int X509V3_EXT_add_alias(int nid_to, int nid_from)
 
 void X509V3_EXT_cleanup(void)
 {
-       sk_pop_free(ext_list, ext_list_free);
+       sk_X509V3_EXT_METHOD_pop_free(ext_list, ext_list_free);
        ext_list = NULL;
 }
 
 static void ext_list_free(X509V3_EXT_METHOD *ext)
 {
-       if(ext->ext_flags & X509V3_EXT_DYNAMIC) Free(ext);
+       if(ext->ext_flags & X509V3_EXT_DYNAMIC) OPENSSL_free(ext);
 }
 
 /* Legacy function: we don't need to add standard extensions
@@ -161,8 +163,9 @@ void *X509V3_EXT_d2i(X509_EXTENSION *ext)
 {
        X509V3_EXT_METHOD *method;
        unsigned char *p;
-       if(!(method = X509V3_EXT_get(ext)) || !method->d2i) return NULL;
+       if(!(method = X509V3_EXT_get(ext))) return NULL;
        p = ext->value->data;
+       if(method->it) return ASN1_item_d2i(NULL, &p, ext->value->length, method->it);
        return method->d2i(NULL, &p, ext->value->length);
 }
 
@@ -213,9 +216,11 @@ void *X509V3_get_d2i(STACK_OF(X509_EXTENSION) *x, int nid, int *crit, int *idx)
                if(crit) *crit = found_ex->critical;
                return X509V3_EXT_d2i(found_ex);
        }
-       
+
        /* Extension not found */
        if(idx) *idx = -1;
        if(crit) *crit = -1;
        return NULL;
 }
+
+IMPLEMENT_STACK_OF(X509V3_EXT_METHOD)