Update from stable branch.
[openssl.git] / crypto / x509v3 / v3_purp.c
index 2234bf147adc3a116009b210676955db57fe7455..181bd34979bc5ed1709fb62849e3c78155411214 100644 (file)
@@ -1,5 +1,5 @@
 /* v3_purp.c */
-/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
  * project 2001.
  */
 /* ====================================================================
@@ -267,11 +267,14 @@ int X509_PURPOSE_get_trust(X509_PURPOSE *xp)
        return xp->trust;
 }
 
-static int nid_cmp(int *a, int *b)
+static int nid_cmp(const int *a, const int *b)
        {
        return *a - *b;
        }
 
+DECLARE_OBJ_BSEARCH_CMP_FN(int, int, nid);
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(int, int, nid);
+
 int X509_supported_extension(X509_EXTENSION *ex)
        {
        /* This table is a list of the NIDs of supported extensions:
@@ -282,7 +285,7 @@ int X509_supported_extension(X509_EXTENSION *ex)
         * searched using bsearch.
         */
 
-       static int supported_nids[] = {
+       static const int supported_nids[] = {
                NID_netscape_cert_type, /* 71 */
                NID_key_usage,          /* 83 */
                NID_subject_alt_name,   /* 85 */
@@ -300,16 +303,13 @@ int X509_supported_extension(X509_EXTENSION *ex)
                NID_inhibit_any_policy  /* 748 */
        };
 
-       int ex_nid;
-
-       ex_nid = OBJ_obj2nid(X509_EXTENSION_get_object(ex));
+       int ex_nid = OBJ_obj2nid(X509_EXTENSION_get_object(ex));
 
        if (ex_nid == NID_undef) 
                return 0;
 
-       if (OBJ_bsearch((char *)&ex_nid, (char *)supported_nids,
-               sizeof(supported_nids)/sizeof(int), sizeof(int),
-               (int (*)(const void *, const void *))nid_cmp))
+       if (OBJ_bsearch_nid(&ex_nid, supported_nids,
+                       sizeof(supported_nids)/sizeof(int)))
                return 1;
        return 0;
        }
@@ -465,8 +465,7 @@ static void x509v3_cache_extensions(X509 *x)
        if (!x->nc && (i != -1))
                x->ex_flags |= EXFLAG_INVALID;
        setup_crldp(x);
-                       
-                       
+
 #ifndef OPENSSL_NO_RFC3779
        x->rfc3779_addr =X509_get_ext_d2i(x, NID_sbgp_ipAddrBlock, NULL, NULL);
        x->rfc3779_asid =X509_get_ext_d2i(x, NID_sbgp_autonomousSysNum,
@@ -477,6 +476,9 @@ static void x509v3_cache_extensions(X509 *x)
                ex = X509_get_ext(x, i);
                if (!X509_EXTENSION_get_critical(ex))
                        continue;
+               if (OBJ_obj2nid(X509_EXTENSION_get_object(ex))
+                                       == NID_freshest_crl)
+                       x->ex_flags |= EXFLAG_FRESHEST;
                if (!X509_supported_extension(ex))
                        {
                        x->ex_flags |= EXFLAG_CRITICAL;