mirror of
https://github.com/cuberite/polarssl.git
synced 2025-09-30 08:56:50 -04:00
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:
parent
e8a811650b
commit
b781770b3e
@ -13,6 +13,18 @@
|
|||||||
* depends_on:MBEDTLS_PKCS7_C:MBEDTLS_RSA_C
|
* depends_on:MBEDTLS_PKCS7_C:MBEDTLS_RSA_C
|
||||||
* END_DEPENDENCIES
|
* 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 */
|
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO */
|
||||||
void pkcs7_parse(char *pkcs7_file, int res_expect)
|
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;
|
size_t buflen;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
mbedtls_pkcs7 pkcs7;
|
|
||||||
|
|
||||||
mbedtls_pkcs7_init(&pkcs7);
|
|
||||||
|
|
||||||
res = mbedtls_pk_load_file(pkcs7_file, &pkcs7_buf, &buflen);
|
res = mbedtls_pk_load_file(pkcs7_file, &pkcs7_buf, &buflen);
|
||||||
TEST_EQUAL(res, 0);
|
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);
|
TEST_EQUAL(res, res_expect);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
mbedtls_free(pkcs7_buf);
|
mbedtls_free(pkcs7_buf);
|
||||||
mbedtls_pkcs7_free(&pkcs7);
|
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user