From: tb Date: Mon, 13 Nov 2023 16:16:14 +0000 (+0000) Subject: Make X509_certificate_type() less bad X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=4cef90fcf348b33fcd86b2dd48fed07a6613a733;p=openbsd Make X509_certificate_type() less bad This converts to proper single exit and undoes a number of unnecessarily silly muppet antics. ok beck --- diff --git a/lib/libcrypto/x509/x509type.c b/lib/libcrypto/x509/x509type.c index 7d07d2b5fed..1698d8a0abc 100644 --- a/lib/libcrypto/x509/x509type.c +++ b/lib/libcrypto/x509/x509type.c @@ -1,4 +1,4 @@ -/* $OpenBSD: x509type.c,v 1.23 2023/11/13 15:44:15 tb Exp $ */ +/* $OpenBSD: x509type.c,v 1.24 2023/11/13 16:16:14 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -73,12 +73,12 @@ X509_certificate_type(const X509 *x, const EVP_PKEY *pkey) int ret = 0; if (x == NULL) - return (0); + goto done; - if (pk == NULL) { - if ((pk = X509_get0_pubkey(x)) == NULL) - return (0); - } + if (pk == NULL) + pk = X509_get0_pubkey(x); + if (pk == NULL) + goto done; switch (pk->type) { case EVP_PKEY_RSA: @@ -107,25 +107,30 @@ X509_certificate_type(const X509 *x, const EVP_PKEY *pkey) break; } - nid = X509_get_signature_nid(x); - if (nid && OBJ_find_sigid_algs(nid, NULL, &nid)) { - switch (nid) { - case NID_rsaEncryption: - case NID_rsa: - ret |= EVP_PKS_RSA; - break; - case NID_dsa: - case NID_dsa_2: - ret |= EVP_PKS_DSA; - break; - case NID_X9_62_id_ecPublicKey: - ret |= EVP_PKS_EC; - break; - default: - break; - } + if ((nid = X509_get_signature_nid(x)) == NID_undef) + goto done; + + if (!OBJ_find_sigid_algs(nid, NULL, &nid)) + goto done; + + switch (nid) { + case NID_rsaEncryption: + case NID_rsa: + ret |= EVP_PKS_RSA; + break; + case NID_dsa: + case NID_dsa_2: + ret |= EVP_PKS_DSA; + break; + case NID_X9_62_id_ecPublicKey: + ret |= EVP_PKS_EC; + break; + default: + break; } - return (ret); + done: + + return ret; } LCRYPTO_ALIAS(X509_certificate_type);