Remove redundant function from pkcs7_parse_reuse

Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
This commit is contained in:
Ben Taylor 2026-06-02 15:32:54 +01:00
parent e9ec4ce3ca
commit f60f5ba85c

View File

@ -29,29 +29,6 @@ static int pkcs7_parse_buffer(unsigned char *pkcs7_buf, int buflen)
return res;
}
# ifdef MBEDTLS_FS_IO
static int pkcs7_parse_buffers_reuse(unsigned char *first_buf, int first_len,
unsigned char *second_buf, int second_len)
{
int res;
mbedtls_pkcs7 pkcs7;
mbedtls_pkcs7_init(&pkcs7);
res = mbedtls_pkcs7_parse_der(&pkcs7, first_buf, first_len);
if (res != MBEDTLS_PKCS7_SIGNED_DATA) {
goto exit;
}
mbedtls_pkcs7_free(&pkcs7);
res = mbedtls_pkcs7_parse_der(&pkcs7, second_buf, second_len);
exit:
mbedtls_pkcs7_free(&pkcs7);
return res;
}
#endif
/* END_SUITE_HELPERS */
/* BEGIN_CASE */
@ -102,30 +79,36 @@ void pkcs7_parse_reuse(char *first_pkcs7_file, char *second_pkcs7_file,
{
unsigned char *first_pkcs7_buf = NULL;
unsigned char *second_pkcs7_buf = NULL;
mbedtls_pkcs7 pkcs7;
size_t first_buflen;
size_t second_buflen;
int res;
/* PKCS7 uses X509 which itself relies on PK under the hood and the latter
* can use PSA to store keys and perform operations so psa_crypto_init()
* must be called before. */
USE_PSA_INIT();
res = mbedtls_pk_load_file(first_pkcs7_file, &first_pkcs7_buf,
&first_buflen);
TEST_EQUAL(res, 0);
mbedtls_pkcs7_init(&pkcs7);
res = mbedtls_pk_load_file(second_pkcs7_file, &second_pkcs7_buf,
&second_buflen);
TEST_EQUAL(res, 0);
TEST_EQUAL(mbedtls_pk_load_file(first_pkcs7_file, &first_pkcs7_buf,
&first_buflen), 0);
res = pkcs7_parse_buffers_reuse(first_pkcs7_buf, first_buflen,
second_pkcs7_buf, second_buflen);
TEST_EQUAL(res, res_expect);
TEST_EQUAL(mbedtls_pk_load_file(second_pkcs7_file, &second_pkcs7_buf,
&second_buflen), 0);
TEST_EQUAL(mbedtls_pkcs7_parse_der(&pkcs7, first_pkcs7_buf,
first_buflen),
MBEDTLS_PKCS7_SIGNED_DATA);
mbedtls_pkcs7_free(&pkcs7);
TEST_EQUAL(mbedtls_pkcs7_parse_der(&pkcs7, second_pkcs7_buf,
second_buflen),
res_expect);
exit:
mbedtls_free(first_pkcs7_buf);
mbedtls_free(second_pkcs7_buf);
mbedtls_pkcs7_free(&pkcs7);
USE_PSA_DONE();
}
/* END_CASE */