Skip to content

Commit f776c95

Browse files
Remove do/while(0) loop in wc_PKCS7_DecodeEncryptedKeyPackage(); use if-else if chain
1 parent 6d51b73 commit f776c95

File tree

1 file changed

+38
-50
lines changed

1 file changed

+38
-50
lines changed

wolfcrypt/src/pkcs7.c

Lines changed: 38 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -14888,59 +14888,47 @@ WOLFSSL_API int wc_PKCS7_DecodeEncryptedKeyPackage(wc_PKCS7 * pkcs7,
1488814888
word32 contentType = 0;
1488914889
int length = 0;
1489014890

14891-
do {
14892-
if (pkiMsg == NULL) {
14893-
ret = BAD_FUNC_ARG;
14894-
break;
14895-
}
14896-
14897-
/* Expect a SEQUENCE header to start the EncryptedKeyPackage
14898-
* ContentInfo. */
14899-
if (GetSequence_ex(pkiMsg, &pkiIndex, &length, pkiMsgSz, 1) < 0) {
14900-
ret = ASN_PARSE_E;
14901-
break;
14902-
}
14903-
14904-
/* Validate the EncryptedKeyPackage OBJECT IDENTIFIER. */
14905-
if (wc_GetContentType(pkiMsg, &pkiIndex, &contentType, pkiMsgSz) < 0) {
14906-
ret = ASN_PARSE_E;
14907-
break;
14908-
}
14909-
14910-
if (contentType != ENCRYPTED_KEY_PACKAGE) {
14911-
WOLFSSL_MSG("PKCS#7 input not of type EncryptedKeyPackage");
14912-
ret = PKCS7_OID_E;
14913-
break;
14914-
}
14915-
14916-
/* Expect content [0] tag */
14917-
if (GetASNHeader(pkiMsg, ASN_CONTEXT_SPECIFIC | ASN_CONSTRUCTED,
14918-
&pkiIndex, &length, pkiMsgSz) < 0) {
14919-
ret = ASN_PARSE_E;
14920-
break;
14921-
}
14922-
14923-
/* Check for an EncryptedKeyPackage explicit CHOICE [0] tag, indicating
14924-
* an EnvelopedData subtype. */
14925-
if (GetASNHeader(pkiMsg, ASN_CONTEXT_SPECIFIC | ASN_CONSTRUCTED,
14926-
&pkiIndex, &length, pkiMsgSz) >= 0) {
14927-
/* An explicit CHOICE [0] tag was found. pkiIndex now should point
14928-
* to the EnvelopedData ContentInfo object within the
14929-
* EncryptedKeyPackage. */
14930-
ret = wc_PKCS7_DecodeEnvelopedData(pkcs7, &pkiMsg[pkiIndex],
14931-
pkiMsgSz - pkiIndex, output, outputSz);
14932-
}
14933-
else {
14891+
if (pkiMsg == NULL) {
14892+
ret = BAD_FUNC_ARG;
14893+
}
14894+
/* Expect a SEQUENCE header to start the EncryptedKeyPackage
14895+
* ContentInfo. */
14896+
else if (GetSequence_ex(pkiMsg, &pkiIndex, &length, pkiMsgSz, 1) < 0) {
14897+
ret = ASN_PARSE_E;
14898+
}
14899+
/* Validate the EncryptedKeyPackage OBJECT IDENTIFIER. */
14900+
else if (wc_GetContentType(pkiMsg, &pkiIndex, &contentType, pkiMsgSz) < 0) {
14901+
ret = ASN_PARSE_E;
14902+
}
14903+
else if (contentType != ENCRYPTED_KEY_PACKAGE) {
14904+
WOLFSSL_MSG("PKCS#7 input not of type EncryptedKeyPackage");
14905+
ret = PKCS7_OID_E;
14906+
}
14907+
/* Expect content [0] tag */
14908+
else if (GetASNHeader(pkiMsg, ASN_CONTEXT_SPECIFIC | ASN_CONSTRUCTED,
14909+
&pkiIndex, &length, pkiMsgSz) < 0) {
14910+
ret = ASN_PARSE_E;
14911+
}
14912+
/* Check for an EncryptedKeyPackage explicit CHOICE [0] tag, indicating
14913+
* an EnvelopedData subtype. */
14914+
else if (GetASNHeader(pkiMsg, ASN_CONTEXT_SPECIFIC | ASN_CONSTRUCTED,
14915+
&pkiIndex, &length, pkiMsgSz) >= 0) {
14916+
/* An explicit CHOICE [0] tag was found. pkiIndex now should point
14917+
* to the EnvelopedData ContentInfo object within the
14918+
* EncryptedKeyPackage. */
14919+
ret = wc_PKCS7_DecodeEnvelopedData(pkcs7, &pkiMsg[pkiIndex],
14920+
pkiMsgSz - pkiIndex, output, outputSz);
14921+
}
14922+
else {
1493414923
#ifndef NO_PKCS7_ENCRYPTED_DATA
14935-
/* An explicit CHOICE [0] tag was not found. Check if we have an
14936-
* EncryptedData blob. */
14937-
ret = wc_PKCS7_DecodeEncryptedData(pkcs7, &pkiMsg[pkiIndex],
14938-
pkiMsgSz - pkiIndex, output, outputSz);
14924+
/* An explicit CHOICE [0] tag was not found. Check if we have an
14925+
* EncryptedData blob. */
14926+
ret = wc_PKCS7_DecodeEncryptedData(pkcs7, &pkiMsg[pkiIndex],
14927+
pkiMsgSz - pkiIndex, output, outputSz);
1493914928
#else
14940-
ret = ASN_PARSE_E;
14929+
ret = ASN_PARSE_E;
1494114930
#endif
14942-
}
14943-
} while(0);
14931+
}
1494414932

1494514933
return ret;
1494614934
}

0 commit comments

Comments
 (0)