Skip to content

Commit

Permalink
fixup! APPS/load_key_certs_crls(): refactor to clean up the code a li…
Browse files Browse the repository at this point in the history
…ttle and add clarifying comments
  • Loading branch information
DDvO committed Nov 9, 2024
1 parent 37aca81 commit 7a73937
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions apps/lib/apps.c
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ static const char *format2string(int format)
return NULL;
}

/* Set type expectation, but set to 0 if objects of several types expected. */
/* Set type expectation, but set to 0 if objects of multiple types expected. */
#define SET_EXPECT(val) \
(expect = expect < 0 ? (val) : (expect == (val) ? (val) : 0))
#define SET_EXPECT1(pvar, val) \
Expand All @@ -918,7 +918,7 @@ static const char *format2string(int format)
pcrl != NULL ? "CRL" : pcrls != NULL ? "CRLs" : NULL)
/*
* Load those types of credentials for which the result pointer is not NULL.
* Reads from stdio if 'uri' is NULL and 'maybe_stdin' is nonzero.
* Reads from stdin if 'uri' is NULL and 'maybe_stdin' is nonzero.
* 'format' parameter may be FORMAT_PEM, FORMAT_ASN1, or 0 for no hint.
* desc may contain more detail on the credential(s) to be loaded for error msg
* For non-NULL ppkey, pcert, and pcrl the first suitable value found is loaded.
Expand Down Expand Up @@ -962,12 +962,24 @@ int load_key_certs_crls(const char *uri, int format, int maybe_stdin,
SET_EXPECT1(ppubkey, OSSL_STORE_INFO_PUBKEY);
SET_EXPECT1(pparams, OSSL_STORE_INFO_PARAMS);
SET_EXPECT1(pcert, OSSL_STORE_INFO_CERT);
/*
* Up to here, the follwing holds.
* If just one of the ppkey, ppubkey, pparams, and pcert function parameters
* is nonzero, expect > 0 indicates which type of credential is expected.
* If expect == 0, more than one of them is nonzero (multiple types expected).
*/

if (pcerts != NULL) {
if (*pcerts == NULL && (*pcerts = sk_X509_new_null()) == NULL) {
if (!quiet)
BIO_printf(bio_err, "Out of memory loading");
goto end;
}
/*
* Adapt the 'expect' variable:
* set to OSSL_STORE_INFO_CERT if no other type is expected so far,
* otherwise set to 0 (indicating that multiple types are expected).
*/
SET_EXPECT(OSSL_STORE_INFO_CERT);
}
SET_EXPECT1(pcrl, OSSL_STORE_INFO_CRL);
Expand All @@ -977,6 +989,11 @@ int load_key_certs_crls(const char *uri, int format, int maybe_stdin,
BIO_printf(bio_err, "Out of memory loading");
goto end;
}
/*
* Adapt the 'expect' variable:
* set to OSSL_STORE_INFO_CRL if no other type is expected so far,
* otherwise set to 0 (indicating that multiple types are expected).
*/
SET_EXPECT(OSSL_STORE_INFO_CRL);
}

Expand Down

0 comments on commit 7a73937

Please sign in to comment.