Remove do/while(0) loop in wc_PKCS7_DecodeEncryptedKeyPackage(); use if-else if chain

This commit is contained in:
Josh Holtrop
2025-07-10 15:25:57 -04:00
parent 6d51b73626
commit f776c95e54

View File

@@ -14888,41 +14888,30 @@ WOLFSSL_API int wc_PKCS7_DecodeEncryptedKeyPackage(wc_PKCS7 * pkcs7,
word32 contentType = 0;
int length = 0;
do {
if (pkiMsg == NULL) {
ret = BAD_FUNC_ARG;
break;
}
/* Expect a SEQUENCE header to start the EncryptedKeyPackage
* ContentInfo. */
if (GetSequence_ex(pkiMsg, &pkiIndex, &length, pkiMsgSz, 1) < 0) {
else if (GetSequence_ex(pkiMsg, &pkiIndex, &length, pkiMsgSz, 1) < 0) {
ret = ASN_PARSE_E;
break;
}
/* Validate the EncryptedKeyPackage OBJECT IDENTIFIER. */
if (wc_GetContentType(pkiMsg, &pkiIndex, &contentType, pkiMsgSz) < 0) {
else if (wc_GetContentType(pkiMsg, &pkiIndex, &contentType, pkiMsgSz) < 0) {
ret = ASN_PARSE_E;
break;
}
if (contentType != ENCRYPTED_KEY_PACKAGE) {
else if (contentType != ENCRYPTED_KEY_PACKAGE) {
WOLFSSL_MSG("PKCS#7 input not of type EncryptedKeyPackage");
ret = PKCS7_OID_E;
break;
}
/* Expect content [0] tag */
if (GetASNHeader(pkiMsg, ASN_CONTEXT_SPECIFIC | ASN_CONSTRUCTED,
else if (GetASNHeader(pkiMsg, ASN_CONTEXT_SPECIFIC | ASN_CONSTRUCTED,
&pkiIndex, &length, pkiMsgSz) < 0) {
ret = ASN_PARSE_E;
break;
}
/* Check for an EncryptedKeyPackage explicit CHOICE [0] tag, indicating
* an EnvelopedData subtype. */
if (GetASNHeader(pkiMsg, ASN_CONTEXT_SPECIFIC | ASN_CONSTRUCTED,
else if (GetASNHeader(pkiMsg, ASN_CONTEXT_SPECIFIC | ASN_CONSTRUCTED,
&pkiIndex, &length, pkiMsgSz) >= 0) {
/* An explicit CHOICE [0] tag was found. pkiIndex now should point
* to the EnvelopedData ContentInfo object within the
@@ -14940,7 +14929,6 @@ WOLFSSL_API int wc_PKCS7_DecodeEncryptedKeyPackage(wc_PKCS7 * pkcs7,
ret = ASN_PARSE_E;
#endif
}
} while(0);
return ret;
}