test: fix USE_PSA_INIT/DONE for x509 test suite
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
diff --git a/tests/suites/test_suite_x509parse.function b/tests/suites/test_suite_x509parse.function
index db7c086..a6bae21 100644
--- a/tests/suites/test_suite_x509parse.function
+++ b/tests/suites/test_suite_x509parse.function
@@ -409,6 +409,7 @@
mbedtls_x509_crt_init(&crt);
memset(buf, 0, 2000);
+ USE_PSA_INIT();
TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
@@ -432,6 +433,7 @@
exit:
mbedtls_x509_crt_free(&crt);
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -444,6 +446,7 @@
mbedtls_x509_crt_init(&crt);
memset(buf, 0, 2000);
+ USE_PSA_INIT();
TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
res = mbedtls_x509_crt_info(buf, 2000, "", &crt);
@@ -455,6 +458,7 @@
exit:
mbedtls_x509_crt_free(&crt);
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -467,6 +471,7 @@
mbedtls_x509_crl_init(&crl);
memset(buf, 0, 2000);
+ USE_PSA_INIT();
TEST_ASSERT(mbedtls_x509_crl_parse_file(&crl, crl_file) == 0);
res = mbedtls_x509_crl_info(buf, 2000, "", &crl);
@@ -478,6 +483,7 @@
exit:
mbedtls_x509_crl_free(&crl);
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -489,11 +495,13 @@
mbedtls_x509_crl_init(&crl);
memset(buf, 0, 2000);
+ USE_PSA_INIT();
TEST_ASSERT(mbedtls_x509_crl_parse_file(&crl, crl_file) == result);
exit:
mbedtls_x509_crl_free(&crl);
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -506,6 +514,7 @@
mbedtls_x509_csr_init(&csr);
memset(buf, 0, 2000);
+ USE_PSA_INIT();
TEST_ASSERT(mbedtls_x509_csr_parse_file(&csr, csr_file) == 0);
res = mbedtls_x509_csr_info(buf, 2000, "", &csr);
@@ -517,6 +526,7 @@
exit:
mbedtls_x509_csr_free(&csr);
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -526,6 +536,7 @@
char buf[2000];
int res;
+ USE_PSA_INIT();
memset(buf, 0, sizeof(buf));
res = mbedtls_x509_crt_verify_info(buf, sizeof(buf), prefix, flags);
@@ -533,6 +544,9 @@
TEST_ASSERT(res >= 0);
TEST_ASSERT(strcmp(buf, result_str) == 0);
+
+exit:
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -556,10 +570,10 @@
* - x509_verify() for server5 -> test-ca2: ~ 18800
* - x509_verify() for server10 -> int-ca3 -> int-ca2: ~ 25500
*/
-
mbedtls_x509_crt_restart_init(&rs_ctx);
mbedtls_x509_crt_init(&crt);
mbedtls_x509_crt_init(&ca);
+ USE_PSA_INIT();
TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
TEST_ASSERT(mbedtls_x509_crt_parse_file(&ca, ca_file) == 0);
@@ -589,6 +603,7 @@
mbedtls_x509_crt_restart_free(&rs_ctx);
mbedtls_x509_crt_free(&crt);
mbedtls_x509_crt_free(&ca);
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -695,6 +710,7 @@
mbedtls_x509_crt_init(&crt);
mbedtls_x509_crt_init(&ca);
+ USE_PSA_INIT();
TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
TEST_ASSERT(mbedtls_x509_crt_parse_file(&ca, ca_file) == 0);
@@ -712,6 +728,7 @@
exit:
mbedtls_x509_crt_free(&crt);
mbedtls_x509_crt_free(&ca);
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -762,6 +779,7 @@
mbedtls_x509_crt_init(&crt);
memset(buf, 0, 2000);
+ USE_PSA_INIT();
TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
if (strcmp(entity, "subject") == 0) {
@@ -779,6 +797,7 @@
exit:
mbedtls_x509_crt_free(&crt);
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -794,6 +813,7 @@
mbedtls_x509_crt_init(&crt);
memset(buf, 0, 2000);
+ USE_PSA_INIT();
TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
crt.subject.next->val.p = (unsigned char *) new_subject_ou;
@@ -810,6 +830,7 @@
}
exit:
mbedtls_x509_crt_free(&crt);
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -823,6 +844,7 @@
mbedtls_x509_name *allocated, *prev;
int ret;
+ USE_PSA_INIT();
memset(&head, 0, sizeof(head));
name = mbedtls_test_unhexify_alloc(rdn_sequence, &name_len);
@@ -843,6 +865,9 @@
TEST_EQUAL(ret, exp_ret);
mbedtls_free(name);
+
+exit:
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -852,6 +877,7 @@
mbedtls_x509_crt crt;
mbedtls_x509_crt_init(&crt);
+ USE_PSA_INIT();
TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
@@ -865,6 +891,7 @@
exit:
mbedtls_x509_crt_free(&crt);
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -874,6 +901,7 @@
mbedtls_x509_crt crt;
mbedtls_x509_crt_init(&crt);
+ USE_PSA_INIT();
TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
@@ -887,6 +915,7 @@
exit:
mbedtls_x509_crt_free(&crt);
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -896,11 +925,13 @@
mbedtls_x509_crt crt;
mbedtls_x509_crt_init(&crt);
+ USE_PSA_INIT();
TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == result);
exit:
mbedtls_x509_crt_free(&crt);
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -913,6 +944,7 @@
mbedtls_x509_crt_init(&crt);
memset(output, 0, 2000);
+ USE_PSA_INIT();
TEST_ASSERT(mbedtls_x509_crt_parse_der(&crt, buf->x, buf->len) == (result));
if ((result) == 0) {
@@ -970,6 +1002,7 @@
exit:
mbedtls_x509_crt_free(&crt);
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -987,6 +1020,7 @@
mbedtls_x509_crt_init(&crt);
memset(output, 0, 2000);
+ USE_PSA_INIT();
TEST_ASSERT(mbedtls_x509_crt_parse_der_with_ext_cb(&crt, buf->x, buf->len, 0, parse_crt_ext_cb,
&oid) == (result));
@@ -1016,6 +1050,7 @@
exit:
mbedtls_x509_crt_free(&crt);
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -1028,7 +1063,7 @@
mbedtls_x509_crl_init(&crl);
memset(output, 0, 2000);
-
+ USE_PSA_INIT();
TEST_ASSERT(mbedtls_x509_crl_parse(&crl, buf->x, buf->len) == (result));
if ((result) == 0) {
@@ -1042,6 +1077,7 @@
exit:
mbedtls_x509_crl_free(&crl);
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -1054,6 +1090,7 @@
mbedtls_x509_csr_init(&csr);
memset(my_out, 0, sizeof(my_out));
+ USE_PSA_INIT();
my_ret = mbedtls_x509_csr_parse_der(&csr, csr_der->x, csr_der->len);
TEST_ASSERT(my_ret == ref_ret);
@@ -1066,6 +1103,7 @@
exit:
mbedtls_x509_csr_free(&csr);
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -1076,6 +1114,7 @@
int i;
mbedtls_x509_crt_init(&chain);
+ USE_PSA_INIT();
TEST_ASSERT(mbedtls_x509_crt_parse_path(&chain, crt_path) == ret);
@@ -1090,6 +1129,7 @@
exit:
mbedtls_x509_crt_free(&chain);
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -1106,10 +1146,8 @@
* We expect chain_dir to contain certificates 00.crt, 01.crt, etc.
* with NN.crt signed by NN-1.crt
*/
-
mbedtls_x509_crt_init(&trusted);
mbedtls_x509_crt_init(&chain);
-
USE_PSA_INIT();
/* Load trusted root */
@@ -1148,7 +1186,6 @@
mbedtls_x509_crt_init(&chain);
mbedtls_x509_crt_init(&trusted);
-
USE_PSA_INIT();
while ((act = mystrsep(&chain_paths, " ")) != NULL) {
@@ -1188,7 +1225,7 @@
const char *desc = NULL;
int ret;
-
+ USE_PSA_INIT();
oid.tag = MBEDTLS_ASN1_OID;
oid.p = buf->x;
oid.len = buf->len;
@@ -1203,6 +1240,9 @@
TEST_ASSERT(desc != NULL);
TEST_ASSERT(strcmp(desc, ref_desc) == 0);
}
+
+exit:
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -1212,6 +1252,7 @@
mbedtls_x509_buf oid;
char num_buf[100];
+ USE_PSA_INIT();
memset(num_buf, 0x2a, sizeof(num_buf));
oid.tag = MBEDTLS_ASN1_OID;
@@ -1226,6 +1267,9 @@
TEST_ASSERT(num_buf[ret] == 0);
TEST_ASSERT(strcmp(num_buf, numstr) == 0);
}
+
+exit:
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -1235,6 +1279,7 @@
mbedtls_x509_crt crt;
mbedtls_x509_crt_init(&crt);
+ USE_PSA_INIT();
TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
@@ -1242,6 +1287,7 @@
exit:
mbedtls_x509_crt_free(&crt);
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -1252,7 +1298,7 @@
mbedtls_x509_crt crt;
mbedtls_x509_crt_init(&crt);
-
+ USE_PSA_INIT();
TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
@@ -1261,6 +1307,7 @@
exit:
mbedtls_x509_crt_free(&crt);
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -1273,6 +1320,7 @@
unsigned char *start = buf;
unsigned char *end = buf;
+ USE_PSA_INIT();
memset(&time, 0x00, sizeof(time));
*end = (unsigned char) tag; end++;
*end = strlen(time_str);
@@ -1290,6 +1338,9 @@
TEST_ASSERT(min == time.min);
TEST_ASSERT(sec == time.sec);
}
+
+exit:
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -1303,6 +1354,8 @@
mbedtls_md_type_t my_msg_md, my_mgf_md;
int my_salt_len;
+ USE_PSA_INIT();
+
buf.p = params->x;
buf.len = params->len;
buf.tag = params_tag;
@@ -1319,13 +1372,17 @@
}
exit:
- ;;
+ USE_PSA_DONE();
}
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_SELF_TEST */
void x509_selftest()
{
+ USE_PSA_INIT();
TEST_ASSERT(mbedtls_x509_self_test(1) == 0);
+
+exit:
+ USE_PSA_DONE();
}
/* END_CASE */