test: properly check written PEM buffer len

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This commit is contained in:
Valerio Setti 2023-04-18 12:57:52 +02:00
parent 232a006a46
commit 2280895784

View File

@ -38,7 +38,7 @@ static void pk_write_check_common(char *key_file, int is_public_key, int is_der)
}
} else {
TEST_EQUAL(mbedtls_pk_parse_keyfile(&key, key_file, NULL,
mbedtls_test_rnd_std_rand, NULL), 0);
mbedtls_test_rnd_std_rand, NULL), 0);
if (is_der) {
ret = mbedtls_pk_write_key_der(&key, buf, check_buf_len);
} else {
@ -56,7 +56,7 @@ static void pk_write_check_common(char *key_file, int is_public_key, int is_der)
start_buf = buf + check_buf_len - buf_len;
} else {
TEST_EQUAL(ret, 0);
buf_len = check_buf_len;
buf_len = strlen((char *) buf) + 1; /* +1 takes the string terminator into account */
start_buf = buf;
}