test/pkcs7: Add helper function

In the future, tests will be added which take in a char buffer
and buflen. Rather than duplicate code, have tests which
read from file and from buffer use the same helper function

Signed-off-by: Nick Child <nick.child@ibm.com>
This commit is contained in:
Nick Child 2022-12-12 15:49:35 -06:00
parent e8a811650b
commit b781770b3e

View file

@ -13,6 +13,18 @@
* depends_on:MBEDTLS_PKCS7_C:MBEDTLS_RSA_C
* END_DEPENDENCIES
*/
/* BEGIN_SUITE_HELPERS */
int pkcs7_parse_buffer(unsigned char *pkcs7_buf, int buflen)
{
int res;
mbedtls_pkcs7 pkcs7;
mbedtls_pkcs7_init(&pkcs7);
res = mbedtls_pkcs7_parse_der(&pkcs7, pkcs7_buf, buflen);
mbedtls_pkcs7_free(&pkcs7);
return res;
}
/* END_SUITE_HELPERS */
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO */
void pkcs7_parse(char *pkcs7_file, int res_expect)
@ -21,19 +33,14 @@ void pkcs7_parse(char *pkcs7_file, int res_expect)
size_t buflen;
int res;
mbedtls_pkcs7 pkcs7;
mbedtls_pkcs7_init(&pkcs7);
res = mbedtls_pk_load_file(pkcs7_file, &pkcs7_buf, &buflen);
TEST_EQUAL(res, 0);
res = mbedtls_pkcs7_parse_der(&pkcs7, pkcs7_buf, buflen);
res = pkcs7_parse_buffer(pkcs7_buf, buflen);
TEST_EQUAL(res, res_expect);
exit:
mbedtls_free(pkcs7_buf);
mbedtls_pkcs7_free(&pkcs7);
}
/* END_CASE */