mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2026-03-20 19:21:09 +01:00
test: proper positioning of USE_PSA_INIT + added missing exit labels
Signed-off-by: valerio <valerio.setti@nordicsemi.no>
This commit is contained in:
@@ -428,13 +428,14 @@ void x509_accessor_ext_types(int ext_type, int has_ext_type)
|
||||
mbedtls_x509_crt crt;
|
||||
int expected_result = ext_type & has_ext_type;
|
||||
|
||||
USE_PSA_INIT();
|
||||
mbedtls_x509_crt_init(&crt);
|
||||
USE_PSA_INIT();
|
||||
|
||||
crt.ext_types = ext_type;
|
||||
|
||||
TEST_ASSERT(mbedtls_x509_crt_has_ext_type(&crt, has_ext_type) == expected_result);
|
||||
|
||||
exit:
|
||||
mbedtls_x509_crt_free(&crt);
|
||||
USE_PSA_DONE();
|
||||
}
|
||||
@@ -464,8 +465,8 @@ void x509_parse_san(char *crt_file, char *result_str, int parse_result)
|
||||
char *p = buf;
|
||||
size_t n = sizeof(buf);
|
||||
|
||||
USE_PSA_INIT();
|
||||
mbedtls_x509_crt_init(&crt);
|
||||
USE_PSA_INIT();
|
||||
memset(buf, 0, 2000);
|
||||
|
||||
TEST_EQUAL(mbedtls_x509_crt_parse_file(&crt, crt_file), parse_result);
|
||||
@@ -493,7 +494,6 @@ void x509_parse_san(char *crt_file, char *result_str, int parse_result)
|
||||
TEST_ASSERT(strcmp(buf, result_str) == 0);
|
||||
|
||||
exit:
|
||||
|
||||
mbedtls_x509_crt_free(&crt);
|
||||
USE_PSA_DONE();
|
||||
}
|
||||
@@ -506,8 +506,8 @@ void x509_cert_info(char *crt_file, char *result_str)
|
||||
char buf[2000];
|
||||
int res;
|
||||
|
||||
USE_PSA_INIT();
|
||||
mbedtls_x509_crt_init(&crt);
|
||||
USE_PSA_INIT();
|
||||
memset(buf, 0, 2000);
|
||||
|
||||
TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
|
||||
@@ -531,8 +531,8 @@ void mbedtls_x509_crl_info(char *crl_file, char *result_str)
|
||||
char buf[2000];
|
||||
int res;
|
||||
|
||||
USE_PSA_INIT();
|
||||
mbedtls_x509_crl_init(&crl);
|
||||
USE_PSA_INIT();
|
||||
memset(buf, 0, 2000);
|
||||
|
||||
TEST_ASSERT(mbedtls_x509_crl_parse_file(&crl, crl_file) == 0);
|
||||
@@ -555,8 +555,8 @@ void mbedtls_x509_crl_parse(char *crl_file, int result)
|
||||
mbedtls_x509_crl crl;
|
||||
char buf[2000];
|
||||
|
||||
USE_PSA_INIT();
|
||||
mbedtls_x509_crl_init(&crl);
|
||||
USE_PSA_INIT();
|
||||
memset(buf, 0, 2000);
|
||||
|
||||
TEST_ASSERT(mbedtls_x509_crl_parse_file(&crl, crl_file) == result);
|
||||
@@ -574,8 +574,8 @@ void mbedtls_x509_csr_info(char *csr_file, char *result_str)
|
||||
char buf[2000];
|
||||
int res;
|
||||
|
||||
USE_PSA_INIT();
|
||||
mbedtls_x509_csr_init(&csr);
|
||||
USE_PSA_INIT();
|
||||
memset(buf, 0, 2000);
|
||||
|
||||
TEST_ASSERT(mbedtls_x509_csr_parse_file(&csr, csr_file) == 0);
|
||||
@@ -606,6 +606,8 @@ void x509_verify_info(int flags, char *prefix, char *result_str)
|
||||
TEST_ASSERT(res >= 0);
|
||||
|
||||
TEST_ASSERT(strcmp(buf, result_str) == 0);
|
||||
|
||||
exit:
|
||||
USE_PSA_DONE();
|
||||
}
|
||||
/* END_CASE */
|
||||
@@ -630,10 +632,10 @@ void x509_verify_restart(char *crt_file, char *ca_file,
|
||||
* - x509_verify() for server5 -> test-ca2: ~ 18800
|
||||
* - x509_verify() for server10 -> int-ca3 -> int-ca2: ~ 25500
|
||||
*/
|
||||
MD_OR_USE_PSA_INIT();
|
||||
mbedtls_x509_crt_restart_init(&rs_ctx);
|
||||
mbedtls_x509_crt_init(&crt);
|
||||
mbedtls_x509_crt_init(&ca);
|
||||
MD_OR_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);
|
||||
@@ -682,10 +684,10 @@ void x509_verify(char *crt_file, char *ca_file, char *crl_file,
|
||||
char *cn_name = NULL;
|
||||
const mbedtls_x509_crt_profile *profile;
|
||||
|
||||
MD_OR_USE_PSA_INIT();
|
||||
mbedtls_x509_crt_init(&crt);
|
||||
mbedtls_x509_crt_init(&ca);
|
||||
mbedtls_x509_crl_init(&crl);
|
||||
MD_OR_USE_PSA_INIT();
|
||||
|
||||
if (strcmp(cn_name_str, "NULL") != 0) {
|
||||
cn_name = cn_name_str;
|
||||
@@ -767,9 +769,9 @@ void x509_verify_ca_cb_failure(char *crt_file, char *ca_file, char *name,
|
||||
mbedtls_x509_crt ca;
|
||||
uint32_t flags = 0;
|
||||
|
||||
USE_PSA_INIT();
|
||||
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);
|
||||
@@ -801,9 +803,10 @@ void x509_verify_callback(char *crt_file, char *ca_file, char *name,
|
||||
uint32_t flags = 0;
|
||||
verify_print_context vrfy_ctx;
|
||||
|
||||
MD_OR_USE_PSA_INIT();
|
||||
mbedtls_x509_crt_init(&crt);
|
||||
mbedtls_x509_crt_init(&ca);
|
||||
MD_OR_USE_PSA_INIT();
|
||||
|
||||
verify_print_init(&vrfy_ctx);
|
||||
|
||||
TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
|
||||
@@ -838,8 +841,9 @@ void mbedtls_x509_dn_gets_subject_replace(char *crt_file,
|
||||
char buf[2000];
|
||||
int res = 0;
|
||||
|
||||
USE_PSA_INIT();
|
||||
mbedtls_x509_crt_init(&crt);
|
||||
USE_PSA_INIT();
|
||||
|
||||
memset(buf, 0, 2000);
|
||||
|
||||
TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
|
||||
@@ -868,8 +872,9 @@ void mbedtls_x509_dn_gets(char *crt_file, char *entity, char *result_str)
|
||||
char buf[2000];
|
||||
int res = 0;
|
||||
|
||||
USE_PSA_INIT();
|
||||
mbedtls_x509_crt_init(&crt);
|
||||
USE_PSA_INIT();
|
||||
|
||||
memset(buf, 0, 2000);
|
||||
|
||||
TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
|
||||
@@ -914,6 +919,7 @@ void mbedtls_x509_get_name(char *rdn_sequence, int exp_ret)
|
||||
|
||||
TEST_EQUAL(ret, exp_ret);
|
||||
|
||||
exit:
|
||||
mbedtls_free(name);
|
||||
USE_PSA_DONE();
|
||||
}
|
||||
@@ -992,8 +998,8 @@ void mbedtls_x509_time_is_past(char *crt_file, char *entity, int result)
|
||||
{
|
||||
mbedtls_x509_crt crt;
|
||||
|
||||
USE_PSA_INIT();
|
||||
mbedtls_x509_crt_init(&crt);
|
||||
USE_PSA_INIT();
|
||||
|
||||
TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
|
||||
|
||||
@@ -1016,8 +1022,8 @@ void mbedtls_x509_time_is_future(char *crt_file, char *entity, int result)
|
||||
{
|
||||
mbedtls_x509_crt crt;
|
||||
|
||||
USE_PSA_INIT();
|
||||
mbedtls_x509_crt_init(&crt);
|
||||
USE_PSA_INIT();
|
||||
|
||||
TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
|
||||
|
||||
@@ -1040,8 +1046,8 @@ void x509parse_crt_file(char *crt_file, int result)
|
||||
{
|
||||
mbedtls_x509_crt crt;
|
||||
|
||||
USE_PSA_INIT();
|
||||
mbedtls_x509_crt_init(&crt);
|
||||
USE_PSA_INIT();
|
||||
|
||||
TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == result);
|
||||
|
||||
@@ -1062,8 +1068,8 @@ void x509parse_crt(data_t *buf, char *result_str, int result)
|
||||
((void) result_str);
|
||||
#endif
|
||||
|
||||
USE_PSA_INIT();
|
||||
mbedtls_x509_crt_init(&crt);
|
||||
USE_PSA_INIT();
|
||||
|
||||
TEST_ASSERT(mbedtls_x509_crt_parse_der(&crt, buf->x, buf->len) == (result));
|
||||
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
@@ -1147,12 +1153,12 @@ void x509parse_crt_cb(data_t *buf, char *result_str, int result)
|
||||
((void) result_str);
|
||||
#endif
|
||||
|
||||
USE_PSA_INIT();
|
||||
oid.tag = MBEDTLS_ASN1_OID;
|
||||
oid.len = MBEDTLS_OID_SIZE(MBEDTLS_OID_PKIX "\x01\x1F");
|
||||
oid.p = (unsigned char *) MBEDTLS_OID_PKIX "\x01\x1F";
|
||||
|
||||
mbedtls_x509_crt_init(&crt);
|
||||
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));
|
||||
@@ -1197,8 +1203,9 @@ void x509parse_crl(data_t *buf, char *result_str, int result)
|
||||
unsigned char output[2000];
|
||||
int res;
|
||||
|
||||
USE_PSA_INIT();
|
||||
mbedtls_x509_crl_init(&crl);
|
||||
USE_PSA_INIT();
|
||||
|
||||
memset(output, 0, 2000);
|
||||
|
||||
|
||||
@@ -1225,8 +1232,9 @@ void mbedtls_x509_csr_parse(data_t *csr_der, char *ref_out, int ref_ret)
|
||||
char my_out[1000];
|
||||
int my_ret;
|
||||
|
||||
USE_PSA_INIT();
|
||||
mbedtls_x509_csr_init(&csr);
|
||||
USE_PSA_INIT();
|
||||
|
||||
memset(my_out, 0, sizeof(my_out));
|
||||
|
||||
my_ret = mbedtls_x509_csr_parse_der(&csr, csr_der->x, csr_der->len);
|
||||
@@ -1251,8 +1259,9 @@ void mbedtls_x509_csr_parse_file(char *csr_file, char *ref_out, int ref_ret)
|
||||
char my_out[1000];
|
||||
int my_ret;
|
||||
|
||||
USE_PSA_INIT();
|
||||
mbedtls_x509_csr_init(&csr);
|
||||
USE_PSA_INIT();
|
||||
|
||||
memset(my_out, 0, sizeof(my_out));
|
||||
|
||||
my_ret = mbedtls_x509_csr_parse_file(&csr, csr_file);
|
||||
@@ -1276,8 +1285,8 @@ void mbedtls_x509_crt_parse_path(char *crt_path, int ret, int nb_crt)
|
||||
mbedtls_x509_crt chain, *cur;
|
||||
int i;
|
||||
|
||||
USE_PSA_INIT();
|
||||
mbedtls_x509_crt_init(&chain);
|
||||
USE_PSA_INIT();
|
||||
|
||||
TEST_ASSERT(mbedtls_x509_crt_parse_path(&chain, crt_path) == ret);
|
||||
|
||||
@@ -1309,9 +1318,9 @@ void mbedtls_x509_crt_verify_max(char *ca_file, char *chain_dir, int nb_int,
|
||||
* We expect chain_dir to contain certificates 00.crt, 01.crt, etc.
|
||||
* with NN.crt signed by NN-1.crt
|
||||
*/
|
||||
MD_OR_USE_PSA_INIT();
|
||||
mbedtls_x509_crt_init(&trusted);
|
||||
mbedtls_x509_crt_init(&chain);
|
||||
MD_OR_USE_PSA_INIT();
|
||||
|
||||
/* Load trusted root */
|
||||
TEST_ASSERT(mbedtls_x509_crt_parse_file(&trusted, ca_file) == 0);
|
||||
@@ -1347,9 +1356,9 @@ void mbedtls_x509_crt_verify_chain(char *chain_paths, char *trusted_ca,
|
||||
mbedtls_x509_crt trusted, chain;
|
||||
const mbedtls_x509_crt_profile *profile = NULL;
|
||||
|
||||
MD_OR_USE_PSA_INIT();
|
||||
mbedtls_x509_crt_init(&chain);
|
||||
mbedtls_x509_crt_init(&trusted);
|
||||
MD_OR_USE_PSA_INIT();
|
||||
|
||||
while ((act = mystrsep(&chain_paths, " ")) != NULL) {
|
||||
TEST_ASSERT(mbedtls_x509_crt_parse_file(&chain, act) == 0);
|
||||
@@ -1389,6 +1398,7 @@ void x509_oid_desc(data_t *buf, char *ref_desc)
|
||||
int ret;
|
||||
|
||||
USE_PSA_INIT();
|
||||
|
||||
oid.tag = MBEDTLS_ASN1_OID;
|
||||
oid.p = buf->x;
|
||||
oid.len = buf->len;
|
||||
@@ -1403,6 +1413,8 @@ void x509_oid_desc(data_t *buf, char *ref_desc)
|
||||
TEST_ASSERT(desc != NULL);
|
||||
TEST_ASSERT(strcmp(desc, ref_desc) == 0);
|
||||
}
|
||||
|
||||
exit:
|
||||
USE_PSA_DONE();
|
||||
}
|
||||
/* END_CASE */
|
||||
@@ -1414,6 +1426,7 @@ void x509_oid_numstr(data_t *oid_buf, char *numstr, int blen, int ret)
|
||||
char num_buf[100];
|
||||
|
||||
USE_PSA_INIT();
|
||||
|
||||
memset(num_buf, 0x2a, sizeof(num_buf));
|
||||
|
||||
oid.tag = MBEDTLS_ASN1_OID;
|
||||
@@ -1428,6 +1441,8 @@ void x509_oid_numstr(data_t *oid_buf, char *numstr, int blen, int ret)
|
||||
TEST_ASSERT(num_buf[ret] == 0);
|
||||
TEST_ASSERT(strcmp(num_buf, numstr) == 0);
|
||||
}
|
||||
|
||||
exit:
|
||||
USE_PSA_DONE();
|
||||
}
|
||||
/* END_CASE */
|
||||
@@ -1437,8 +1452,8 @@ void x509_check_key_usage(char *crt_file, int usage, int ret)
|
||||
{
|
||||
mbedtls_x509_crt crt;
|
||||
|
||||
USE_PSA_INIT();
|
||||
mbedtls_x509_crt_init(&crt);
|
||||
USE_PSA_INIT();
|
||||
|
||||
TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
|
||||
|
||||
@@ -1456,8 +1471,8 @@ void x509_check_extended_key_usage(char *crt_file, data_t *oid, int ret
|
||||
{
|
||||
mbedtls_x509_crt crt;
|
||||
|
||||
USE_PSA_INIT();
|
||||
mbedtls_x509_crt_init(&crt);
|
||||
USE_PSA_INIT();
|
||||
|
||||
TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
|
||||
|
||||
@@ -1497,6 +1512,7 @@ void x509_get_time(int tag, char *time_str, int ret, int year, int mon,
|
||||
TEST_ASSERT(min == time.min);
|
||||
TEST_ASSERT(sec == time.sec);
|
||||
}
|
||||
exit:
|
||||
USE_PSA_DONE();
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
Reference in New Issue
Block a user