Modernise 'selfsign.c' to use new X509_NAME code
[openssl.git] / crypto / x509v3 / v3_lib.c
index 06def2a659c67174626184bda3d5f285e6b7fb0f..4242d130a2c515a17605877fbfbaf973138e3182 100644 (file)
@@ -62,6 +62,8 @@
 #include <openssl/conf.h>
 #include <openssl/x509v3.h>
 
+#include "ext_dat.h"
+
 static STACK *ext_list = NULL;
 
 static int ext_cmp(X509V3_EXT_METHOD **a, X509V3_EXT_METHOD **b);
@@ -87,10 +89,15 @@ static int ext_cmp(X509V3_EXT_METHOD **a, X509V3_EXT_METHOD **b)
 
 X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid)
 {
-       X509V3_EXT_METHOD tmp;
+       X509V3_EXT_METHOD tmp, *t = &tmp, **ret;
        int idx;
+       if(nid < 0) return NULL;
        tmp.ext_nid = nid;
-       if(!ext_list || (tmp.ext_nid < 0) ) return NULL;
+       ret = (X509V3_EXT_METHOD **) OBJ_bsearch((char *)&t,
+                       (char *)standard_exts, STANDARD_EXTENSION_COUNT,
+                       sizeof(X509V3_EXT_METHOD *), (int (*)())ext_cmp);
+       if(ret) return *ret;
+       if(!ext_list) return NULL;
        idx = sk_find(ext_list, (char *)&tmp);
        if(idx == -1) return NULL;
        return (X509V3_EXT_METHOD *)sk_value(ext_list, idx);
@@ -125,7 +132,7 @@ int X509V3_EXT_add_alias(int nid_to, int nid_from)
        *tmpext = *ext;
        tmpext->ext_nid = nid_to;
        tmpext->ext_flags |= X509V3_EXT_DYNAMIC;
-       return 1;
+       return X509V3_EXT_add(tmpext);
 }
 
 void X509V3_EXT_cleanup(void)
@@ -139,28 +146,12 @@ static void ext_list_free(X509V3_EXT_METHOD *ext)
        if(ext->ext_flags & X509V3_EXT_DYNAMIC) Free(ext);
 }
 
-extern X509V3_EXT_METHOD v3_bcons, v3_nscert, v3_key_usage, v3_ext_ku;
-extern X509V3_EXT_METHOD v3_pkey_usage_period, v3_sxnet;
-extern X509V3_EXT_METHOD v3_ns_ia5_list[], v3_alt[], v3_skey_id, v3_akey_id;
-
-extern X509V3_EXT_METHOD v3_crl_num, v3_crl_reason, v3_cpols, v3_crld;
+/* Legacy function: we don't need to add standard extensions
+ * any more because they are now kept in ext_dat.h.
+ */
 
 int X509V3_add_standard_extensions(void)
 {
-       X509V3_EXT_add_list(v3_ns_ia5_list);
-       X509V3_EXT_add_list(v3_alt);
-       X509V3_EXT_add(&v3_bcons);
-       X509V3_EXT_add(&v3_nscert);
-       X509V3_EXT_add(&v3_key_usage);
-       X509V3_EXT_add(&v3_ext_ku);
-       X509V3_EXT_add(&v3_skey_id);
-       X509V3_EXT_add(&v3_akey_id);
-       X509V3_EXT_add(&v3_pkey_usage_period);
-       X509V3_EXT_add(&v3_crl_num);
-       X509V3_EXT_add(&v3_sxnet);
-       X509V3_EXT_add(&v3_crl_reason);
-       X509V3_EXT_add(&v3_cpols);
-       X509V3_EXT_add(&v3_crld);
        return 1;
 }
 
@@ -219,7 +210,7 @@ void *X509V3_get_d2i(STACK_OF(X509_EXTENSION) *x, int nid, int *crit, int *idx)
        }
        if(found_ex) {
                /* Found it */
-               *crit = found_ex->critical;
+               if(crit) *crit = found_ex->critical;
                return X509V3_EXT_d2i(found_ex);
        }
        
@@ -228,20 +219,3 @@ void *X509V3_get_d2i(STACK_OF(X509_EXTENSION) *x, int nid, int *crit, int *idx)
        if(crit) *crit = -1;
        return NULL;
 }
-
-/* As above but for a passed certificate */
-
-void *X509V3_X509_get_d2i(X509 *x, int nid, int *crit, int *idx)
-{
-       return X509V3_get_d2i(x->cert_info->extensions, nid, crit, idx);
-}
-
-void *X509V3_CRL_get_d2i(X509_CRL *x, int nid, int *crit, int *idx)
-{
-       return X509V3_get_d2i(x->crl->extensions, nid, crit, idx);
-}
-
-void *X509V3_REVOKED_get_d2i(X509_REVOKED *x, int nid, int *crit, int *idx)
-{
-       return X509V3_get_d2i(x->extensions, nid, crit, idx);
-}