Skip to content

Commit

Permalink
crypto: simplify assertions in Safe*Print
Browse files Browse the repository at this point in the history
Checking the X509V3_EXT_METHOD doesn't do anything. X509V3_EXT_get is
already implemented by calling X509V3_EXT_get_nid on the extension's
NID. We may as well just check the NID directly.

PR-URL: #49709
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Richard Lau <rlau@redhat.com>
  • Loading branch information
davidben authored and marco-ippolito committed May 3, 2024
1 parent 4d051ba commit a4847c4
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/crypto/crypto_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -815,8 +815,7 @@ static bool PrintGeneralName(const BIOPointer& out, const GENERAL_NAME* gen) {
}

bool SafeX509SubjectAltNamePrint(const BIOPointer& out, X509_EXTENSION* ext) {
const X509V3_EXT_METHOD* method = X509V3_EXT_get(ext);
CHECK(method == X509V3_EXT_get_nid(NID_subject_alt_name));
CHECK_EQ(OBJ_obj2nid(X509_EXTENSION_get_object(ext)), NID_subject_alt_name);

GENERAL_NAMES* names = static_cast<GENERAL_NAMES*>(X509V3_EXT_d2i(ext));
if (names == nullptr)
Expand All @@ -840,8 +839,7 @@ bool SafeX509SubjectAltNamePrint(const BIOPointer& out, X509_EXTENSION* ext) {
}

bool SafeX509InfoAccessPrint(const BIOPointer& out, X509_EXTENSION* ext) {
const X509V3_EXT_METHOD* method = X509V3_EXT_get(ext);
CHECK(method == X509V3_EXT_get_nid(NID_info_access));
CHECK_EQ(OBJ_obj2nid(X509_EXTENSION_get_object(ext)), NID_info_access);

AUTHORITY_INFO_ACCESS* descs =
static_cast<AUTHORITY_INFO_ACCESS*>(X509V3_EXT_d2i(ext));
Expand Down

0 comments on commit a4847c4

Please sign in to comment.