diff --git a/crypto/x509/v3_purp.c b/crypto/x509/v3_purp.c index a7a4e888e29..fdd920f7792 100644 --- a/crypto/x509/v3_purp.c +++ b/crypto/x509/v3_purp.c @@ -118,26 +118,21 @@ static const X509_PURPOSE xstandard[] = { (char *)"timestampsign", NULL}, }; -// As much as I'd like to make X509_check_purpose use a "const" X509* I -// really can't because it does recalculate hashes and do other non-const -// things. If |id| is -1 it just calls |x509v3_cache_extensions| for its -// side-effect. -// Returns 1 on success, 0 if x does not allow purpose, -1 on (internal) error. int X509_check_purpose(X509 *x, int id, int ca) { - int idx; - const X509_PURPOSE *pt; + // This differs from OpenSSL, which uses -1 to indicate a fatal error and 0 to + // indicate an invalid certificate. BoringSSL uses 0 for both. if (!x509v3_cache_extensions(x)) { - return -1; + return 0; } if (id == -1) { return 1; } - idx = X509_PURPOSE_get_by_id(id); + int idx = X509_PURPOSE_get_by_id(id); if (idx == -1) { - return -1; + return 0; } - pt = X509_PURPOSE_get0(idx); + const X509_PURPOSE *pt = X509_PURPOSE_get0(idx); return pt->check_purpose(pt, x, ca); }