From 1d4e7d8278f46ce3b4d624e84d90df18ebf905f9 Mon Sep 17 00:00:00 2001 From: Ethan Looney Date: Tue, 22 Sep 2020 14:50:08 -0600 Subject: [PATCH 1/2] Added unit tests for PKCS7 --- tests/api.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/tests/api.c b/tests/api.c index 774a33296..7ffe474fd 100644 --- a/tests/api.c +++ b/tests/api.c @@ -23253,7 +23253,91 @@ static void test_PKCS7_signed_enveloped(void) #endif } +static int test_wc_PKCS7_NoDefaultSignedAttribs (void) +{ + int ret = 0; +#if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \ + && !defined(NO_AES) + PKCS7* pkcs7; + void* heap = NULL; + printf(testingFmt, "wc_PKCS7_NoDefaultSignedAttribs()"); + + pkcs7 = wc_PKCS7_New(heap, devId); + AssertNotNull(pkcs7); + AssertIntEQ(wc_PKCS7_Init(pkcs7, heap, devId), 0); + + ret = wc_PKCS7_NoDefaultSignedAttribs(NULL); + if (ret == BAD_FUNC_ARG) { + ret = 0; + } + if (ret == 0) { + ret = wc_PKCS7_NoDefaultSignedAttribs(pkcs7); + } + + wc_PKCS7_Free(pkcs7); + printf(resultFmt, ret == 0 ? passed : failed); +#endif + return ret; +} +static int test_wc_PKCS7_SetOriEncryptCtx (void) +{ + int ret = 0; +#if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \ + && !defined(NO_AES) + PKCS7* pkcs7; + void* heap = NULL; + WOLFSSL_CTX* ctx; + ctx = NULL; + + printf(testingFmt, "wc_PKCS7_SetOriEncryptCtx()"); + + pkcs7 = wc_PKCS7_New(heap, devId); + AssertNotNull(pkcs7); + AssertIntEQ(wc_PKCS7_Init(pkcs7, heap, devId), 0); + + ret = wc_PKCS7_SetOriEncryptCtx(NULL, ctx); + if (ret == BAD_FUNC_ARG) { + ret = 0; + } + if (ret == 0) { + ret = wc_PKCS7_SetOriEncryptCtx(pkcs7, ctx); + } + + wc_PKCS7_Free(pkcs7); + printf(resultFmt, ret == 0 ? passed : failed); +#endif + return ret; +} +static int test_wc_PKCS7_SetOriDecryptCtx (void) +{ + int ret = 0; +#if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \ + && !defined(NO_AES) + PKCS7* pkcs7; + void* heap = NULL; + WOLFSSL_CTX* ctx; + ctx = NULL; + + printf(testingFmt, "wc_PKCS7_SetOriDecryptCtx()"); + + pkcs7 = wc_PKCS7_New(heap, devId); + AssertNotNull(pkcs7); + AssertIntEQ(wc_PKCS7_Init(pkcs7, heap, devId), 0); + + ret = wc_PKCS7_SetOriDecryptCtx(NULL, ctx); + if (ret == BAD_FUNC_ARG) { + ret = 0; + } + if (ret == 0) { + ret = wc_PKCS7_SetOriDecryptCtx(pkcs7, ctx); + } + + wc_PKCS7_Free(pkcs7); + printf(resultFmt, ret == 0 ? passed : failed); +#endif + return ret; +} static void test_wc_i2d_PKCS12(void) { #if !defined(NO_ASN) && !defined(NO_PWDBASED) && defined(HAVE_PKCS12) \ @@ -36922,6 +37006,10 @@ void ApiTest(void) test_wc_PKCS7_Degenerate(); test_wc_PKCS7_BER(); test_PKCS7_signed_enveloped(); + AssertIntEQ(test_wc_PKCS7_NoDefaultSignedAttribs(), 0); + AssertIntEQ(test_wc_PKCS7_SetOriDecryptCtx(), 0); + AssertIntEQ(test_wc_PKCS7_SetOriEncryptCtx(), 0); + test_wc_i2d_PKCS12(); From 59294708a83a706d87f5b952b6be03e750809622 Mon Sep 17 00:00:00 2001 From: Ethan Looney Date: Wed, 23 Sep 2020 13:22:59 -0600 Subject: [PATCH 2/2] Changed test function call, uses internal AssertIntEQ instead of single call --- tests/api.c | 56 +++++++++++++++++++---------------------------------- 1 file changed, 20 insertions(+), 36 deletions(-) diff --git a/tests/api.c b/tests/api.c index 7ffe474fd..a338f6a1e 100644 --- a/tests/api.c +++ b/tests/api.c @@ -23253,9 +23253,8 @@ static void test_PKCS7_signed_enveloped(void) #endif } -static int test_wc_PKCS7_NoDefaultSignedAttribs (void) +static void test_wc_PKCS7_NoDefaultSignedAttribs (void) { - int ret = 0; #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \ && !defined(NO_AES) PKCS7* pkcs7; @@ -23267,22 +23266,17 @@ static int test_wc_PKCS7_NoDefaultSignedAttribs (void) AssertNotNull(pkcs7); AssertIntEQ(wc_PKCS7_Init(pkcs7, heap, devId), 0); - ret = wc_PKCS7_NoDefaultSignedAttribs(NULL); - if (ret == BAD_FUNC_ARG) { - ret = 0; - } - if (ret == 0) { - ret = wc_PKCS7_NoDefaultSignedAttribs(pkcs7); - } + AssertIntEQ(wc_PKCS7_NoDefaultSignedAttribs(NULL), BAD_FUNC_ARG); + + AssertIntEQ(wc_PKCS7_NoDefaultSignedAttribs(pkcs7), 0); wc_PKCS7_Free(pkcs7); - printf(resultFmt, ret == 0 ? passed : failed); + + printf(resultFmt, passed); #endif - return ret; } -static int test_wc_PKCS7_SetOriEncryptCtx (void) +static void test_wc_PKCS7_SetOriEncryptCtx (void) { - int ret = 0; #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \ && !defined(NO_AES) PKCS7* pkcs7; @@ -23296,22 +23290,17 @@ static int test_wc_PKCS7_SetOriEncryptCtx (void) AssertNotNull(pkcs7); AssertIntEQ(wc_PKCS7_Init(pkcs7, heap, devId), 0); - ret = wc_PKCS7_SetOriEncryptCtx(NULL, ctx); - if (ret == BAD_FUNC_ARG) { - ret = 0; - } - if (ret == 0) { - ret = wc_PKCS7_SetOriEncryptCtx(pkcs7, ctx); - } + AssertIntEQ(wc_PKCS7_SetOriEncryptCtx(NULL, ctx), BAD_FUNC_ARG); + + AssertIntEQ(wc_PKCS7_SetOriEncryptCtx(pkcs7, ctx), 0); wc_PKCS7_Free(pkcs7); - printf(resultFmt, ret == 0 ? passed : failed); + + printf(resultFmt, passed); #endif - return ret; } -static int test_wc_PKCS7_SetOriDecryptCtx (void) +static void test_wc_PKCS7_SetOriDecryptCtx (void) { - int ret = 0; #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \ && !defined(NO_AES) PKCS7* pkcs7; @@ -23325,18 +23314,13 @@ static int test_wc_PKCS7_SetOriDecryptCtx (void) AssertNotNull(pkcs7); AssertIntEQ(wc_PKCS7_Init(pkcs7, heap, devId), 0); - ret = wc_PKCS7_SetOriDecryptCtx(NULL, ctx); - if (ret == BAD_FUNC_ARG) { - ret = 0; - } - if (ret == 0) { - ret = wc_PKCS7_SetOriDecryptCtx(pkcs7, ctx); - } + AssertIntEQ(wc_PKCS7_SetOriDecryptCtx(NULL, ctx), BAD_FUNC_ARG); + + AssertIntEQ(wc_PKCS7_SetOriDecryptCtx(pkcs7, ctx), 0); wc_PKCS7_Free(pkcs7); - printf(resultFmt, ret == 0 ? passed : failed); + printf(resultFmt, passed); #endif - return ret; } static void test_wc_i2d_PKCS12(void) { @@ -37006,9 +36990,9 @@ void ApiTest(void) test_wc_PKCS7_Degenerate(); test_wc_PKCS7_BER(); test_PKCS7_signed_enveloped(); - AssertIntEQ(test_wc_PKCS7_NoDefaultSignedAttribs(), 0); - AssertIntEQ(test_wc_PKCS7_SetOriDecryptCtx(), 0); - AssertIntEQ(test_wc_PKCS7_SetOriEncryptCtx(), 0); + test_wc_PKCS7_NoDefaultSignedAttribs(); + test_wc_PKCS7_SetOriEncryptCtx(); + test_wc_PKCS7_SetOriDecryptCtx(); test_wc_i2d_PKCS12();