Add corner test cases for EVP_EncodeFinal and EVP_DecodeFinal

This commit is contained in:
TakayukiMatsuo
2021-06-03 20:02:48 +09:00
parent f7477b932d
commit 195ca2b3f0
2 changed files with 19 additions and 2 deletions

View File

@ -2615,6 +2615,16 @@ static void test_wolfSSL_EVP_EncodeUpdate(void)
AssertIntEQ(XSTRNCMP(
(const char*)encOutBuff,(const char*)enc2,sizeof(enc2) ),0);
/* test with illeagal parameters */
outl = 1;
EVP_EncodeFinal(NULL, encOutBuff + outl, &outl);
AssertIntEQ(outl, 0);
outl = 1;
EVP_EncodeFinal(ctx, NULL, &outl);
AssertIntEQ(outl, 0);
EVP_EncodeFinal(ctx, encOutBuff + outl, NULL);
EVP_EncodeFinal(NULL, NULL, NULL);
EVP_ENCODE_CTX_free(ctx);
printf(resultFmt, passed);
#endif /* OPENSSL_EXTRA && WOLFSSL_BASE64_ENCODE*/
@ -2852,6 +2862,12 @@ static void test_wolfSSL_EVP_DecodeUpdate(void)
AssertIntEQ(outl,sizeof(plain4)-1);
/* test with illegal parameters */
AssertIntEQ(EVP_DecodeFinal(NULL,decOutBuff + outl,&outl), -1);
AssertIntEQ(EVP_DecodeFinal(ctx,NULL,&outl), -1);
AssertIntEQ(EVP_DecodeFinal(ctx,decOutBuff + outl, NULL), -1);
AssertIntEQ(EVP_DecodeFinal(NULL,NULL, NULL), -1);
EVP_DecodeFinal(
ctx,
decOutBuff + outl,

View File

@ -6958,9 +6958,10 @@ int wolfSSL_EVP_EncodeUpdate(WOLFSSL_EVP_ENCODE_CTX* ctx,
outsz = BASE64_ENCODE_RESULT_BLOCK_SIZE + 1;
res = Base64_Encode(ctx->data, BASE64_ENCODE_BLOCK_SIZE, out,
&outsz);
ctx->remaining = 0;
if (res == 0)
if (res == 0) {
ctx->remaining = 0;
*outl = outsz;
}
else
return 0; /* return with error */
}