Skip to content

Commit 2044d6b

Browse files
add callbacks for PKCS7 streaming input and output
1 parent a77c6d1 commit 2044d6b

4 files changed

Lines changed: 918 additions & 244 deletions

File tree

tests/api.c

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27019,8 +27019,8 @@ static int test_wc_PKCS7_EncodeSignedData(void)
2701927019
pkcs7->rng = &rng;
2702027020
}
2702127021
ExpectIntEQ(wc_PKCS7_GetStreamMode(pkcs7), 0);
27022-
ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1), 0);
27023-
ExpectIntEQ(wc_PKCS7_SetStreamMode(NULL, 1), BAD_FUNC_ARG);
27022+
ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1, NULL, NULL), 0);
27023+
ExpectIntEQ(wc_PKCS7_SetStreamMode(NULL, 1, NULL, NULL), BAD_FUNC_ARG);
2702427024
ExpectIntEQ(wc_PKCS7_GetStreamMode(pkcs7), 1);
2702527025

2702627026
ExpectIntGT(signedSz = wc_PKCS7_EncodeSignedData(pkcs7, output,
@@ -28287,16 +28287,46 @@ static int test_wc_PKCS7_EncodeDecodeEnvelopedData(void)
2828728287
pkcs7->privateKey = (testVectors + i)->privateKey;
2828828288
pkcs7->privateKeySz = (testVectors + i)->privateKeySz;
2828928289
}
28290-
ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1), 0);
28290+
ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1, NULL, NULL), 0);
2829128291

28292-
ExpectIntGE(encodedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, output,
28293-
(word32)sizeof(output)), 0);
28292+
encodedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, output,
28293+
(word32)sizeof(output));
2829428294

28295-
decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
28296-
(word32)encodedSz, decoded, (word32)sizeof(decoded));
28297-
ExpectIntGE(decodedSz, 0);
28298-
/* Verify the size of each buffer. */
28299-
ExpectIntEQ((word32)sizeof(input)/sizeof(char), decodedSz);
28295+
switch ((testVectors + i)->encryptOID) {
28296+
#ifndef NO_DES3
28297+
case DES3b:
28298+
case DESb:
28299+
ExpectIntEQ(encodedSz, BAD_FUNC_ARG);
28300+
break;
28301+
#endif
28302+
#ifdef HAVE_AESCCM
28303+
#ifdef WOLFSSL_AES_128
28304+
case AES128CCMb:
28305+
ExpectIntEQ(encodedSz, BAD_FUNC_ARG);
28306+
break;
28307+
#endif
28308+
#ifdef WOLFSSL_AES_192
28309+
case AES192CCMb:
28310+
ExpectIntEQ(encodedSz, BAD_FUNC_ARG);
28311+
break;
28312+
#endif
28313+
#ifdef WOLFSSL_AES_256
28314+
case AES256CCMb:
28315+
ExpectIntEQ(encodedSz, BAD_FUNC_ARG);
28316+
break;
28317+
#endif
28318+
#endif
28319+
default:
28320+
ExpectIntGE(encodedSz, 0);
28321+
}
28322+
28323+
if (encodedSz > 0) {
28324+
decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
28325+
(word32)encodedSz, decoded, (word32)sizeof(decoded));
28326+
ExpectIntGE(decodedSz, 0);
28327+
/* Verify the size of each buffer. */
28328+
ExpectIntEQ((word32)sizeof(input)/sizeof(char), decodedSz);
28329+
}
2830028330
wc_PKCS7_Free(pkcs7);
2830128331
pkcs7 = NULL;
2830228332
ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));

wolfcrypt/src/asn.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3465,7 +3465,9 @@ word32 SetBitString(word32 len, byte unusedBits, byte* output)
34653465

34663466
#ifdef ASN_BER_TO_DER
34673467

3468-
#define BER_OCTET_LENGTH 4096
3468+
#ifndef BER_OCTET_LENGTH
3469+
#define BER_OCTET_LENGTH 4096
3470+
#endif
34693471

34703472
/* sets the terminating 0x00 0x00 at the end of an indefinite length
34713473
* returns the number of bytes written */

0 commit comments

Comments
 (0)