Skip to content

Commit ca3b1a1

Browse files
add test case
1 parent 7a23cff commit ca3b1a1

2 files changed

Lines changed: 38 additions & 6 deletions

File tree

tests/api.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51094,6 +51094,36 @@ static int test_wc_PKCS7_signed_enveloped(void)
5109451094
pkcs7 = NULL;
5109551095
#endif /* !NO_PKCS7_STREAM */
5109651096
#endif
51097+
51098+
{
51099+
/* arbitrary custom SKID */
51100+
byte customSKID[] = {
51101+
0x40, 0x25, 0x77, 0x56
51102+
};
51103+
51104+
wc_InitRng(&rng);
51105+
sigSz = FOURK_BUF * 2;
51106+
ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
51107+
if (pkcs7 != NULL) {
51108+
ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
51109+
pkcs7->content = cert;
51110+
pkcs7->contentSz = (word32)certSz;
51111+
pkcs7->contentOID = DATA;
51112+
pkcs7->privateKey = key;
51113+
pkcs7->privateKeySz = (word32)keySz;
51114+
pkcs7->encryptOID = RSAk;
51115+
pkcs7->hashOID = SHA256h;
51116+
pkcs7->rng = &rng;
51117+
ExpectIntEQ(wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID), 0);
51118+
ExpectIntEQ(wc_PKCS7_SetCustomSKID(pkcs7, customSKID,
51119+
sizeof(customSKID)), 0);
51120+
ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig,
51121+
(word32)sigSz)), 0);
51122+
}
51123+
wc_PKCS7_Free(pkcs7);
51124+
pkcs7 = NULL;
51125+
wc_FreeRng(&rng);
51126+
}
5109751127
#endif /* HAVE_PKCS7 && !NO_RSA && !NO_AES */
5109851128
return EXPECT_RESULT();
5109951129
}

wolfcrypt/src/pkcs7.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,16 +1376,16 @@ void wc_PKCS7_Free(PKCS7* pkcs7)
13761376
pkcs7->cachedEncryptedContentSz = 0;
13771377
}
13781378

1379-
if (pkcs7->isDynamic) {
1380-
pkcs7->isDynamic = 0;
1381-
XFREE(pkcs7, pkcs7->heap, DYNAMIC_TYPE_PKCS7);
1382-
}
1383-
13841379
if (pkcs7->customSKID) {
13851380
XFREE(pkcs7->customSKID, pkcs7->heap, DYNAMIC_TYPE_PKCS7);
13861381
pkcs7->customSKID = NULL;
13871382
pkcs7->customSKIDSz = 0;
13881383
}
1384+
1385+
if (pkcs7->isDynamic) {
1386+
pkcs7->isDynamic = 0;
1387+
XFREE(pkcs7, pkcs7->heap, DYNAMIC_TYPE_PKCS7);
1388+
}
13891389
}
13901390

13911391

@@ -3457,6 +3457,7 @@ int wc_PKCS7_SetCustomSKID(PKCS7* pkcs7, byte* in, word16 inSz)
34573457
}
34583458
else {
34593459
XMEMCPY(pkcs7->customSKID, in, inSz);
3460+
pkcs7->customSKIDSz = inSz;
34603461
}
34613462
return ret;
34623463
}
@@ -9633,8 +9634,9 @@ int wc_PKCS7_EncodeEnvelopedData(PKCS7* pkcs7, byte* output, word32 outputSz)
96339634
}
96349635

96359636
#ifndef ASN_BER_TO_DER
9636-
if (output == NULL || outputSz == 0)
9637+
if (output == NULL || outputSz == 0) {
96379638
return BAD_FUNC_ARG;
9639+
}
96389640
#else
96399641
/* if both output and callback are not set then error out */
96409642
if ((output == NULL || outputSz == 0) && (pkcs7->streamOutCb == NULL)) {

0 commit comments

Comments
 (0)