tests: x509parse: fix return values for invalid RSA keys
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 09b248e..8f0da5a 100644
--- a/tests/suites/test_suite_x509parse.function
+++ b/tests/suites/test_suite_x509parse.function
@@ -1118,17 +1118,29 @@
void x509parse_crt(data_t *buf, char *result_str, int result)
{
mbedtls_x509_crt crt;
-#if !defined(MBEDTLS_X509_REMOVE_INFO)
+ #if !defined(MBEDTLS_X509_REMOVE_INFO)
unsigned char output[2000] = { 0 };
- int res;
-#else
+ #else
((void) result_str);
-#endif
+ #endif
+ /* Pick an error which is not used in the test_suite_x509parse.data file. */
+ int result_ext = MBEDTLS_ERR_ERROR_GENERIC_ERROR;
+ int res;
+
+#if !defined(MBEDTLS_PK_USE_PSA_RSA_DATA)
+ /* Support for mbedtls#10213 before psa#308. Once psa#308 will be
+ * merged this dirty fix can be removed. */
+ if (result == MBEDTLS_ERR_PK_INVALID_PUBKEY) {
+ result_ext = MBEDTLS_ERR_ASN1_UNEXPECTED_TAG;
+ }
+#endif /* MBEDTLS_PK_USE_PSA_RSA_DATA */
mbedtls_x509_crt_init(&crt);
USE_PSA_INIT();
- TEST_EQUAL(mbedtls_x509_crt_parse_der(&crt, buf->x, buf->len), result);
+ res = mbedtls_x509_crt_parse_der(&crt, buf->x, buf->len);
+ fprintf(stderr, "\n res=%d, result=%d, result_ext=%d \n", res, result, result_ext);
+ TEST_ASSERT((res == result) || (res == result_ext));
#if !defined(MBEDTLS_X509_REMOVE_INFO)
if ((result) == 0) {
res = mbedtls_x509_crt_info((char *) output, 2000, "", &crt);
@@ -1143,7 +1155,8 @@
mbedtls_x509_crt_free(&crt);
mbedtls_x509_crt_init(&crt);
- TEST_EQUAL(mbedtls_x509_crt_parse_der_nocopy(&crt, buf->x, buf->len), result);
+ res = mbedtls_x509_crt_parse_der_nocopy(&crt, buf->x, buf->len);
+ TEST_ASSERT((res == result) || (res == result_ext));
#if !defined(MBEDTLS_X509_REMOVE_INFO)
if ((result) == 0) {
memset(output, 0, 2000);
@@ -1161,8 +1174,8 @@
mbedtls_x509_crt_free(&crt);
mbedtls_x509_crt_init(&crt);
- TEST_EQUAL(mbedtls_x509_crt_parse_der_with_ext_cb(&crt, buf->x, buf->len, 0, NULL, NULL),
- result);
+ res = mbedtls_x509_crt_parse_der_with_ext_cb(&crt, buf->x, buf->len, 0, NULL, NULL);
+ TEST_ASSERT((res == result) || (res == result_ext));
#if !defined(MBEDTLS_X509_REMOVE_INFO)
if ((result) == 0) {
res = mbedtls_x509_crt_info((char *) output, 2000, "", &crt);
@@ -1178,8 +1191,8 @@
mbedtls_x509_crt_free(&crt);
mbedtls_x509_crt_init(&crt);
- TEST_EQUAL(mbedtls_x509_crt_parse_der_with_ext_cb(&crt, buf->x, buf->len, 1, NULL, NULL),
- result);
+ res = mbedtls_x509_crt_parse_der_with_ext_cb(&crt, buf->x, buf->len, 1, NULL, NULL);
+ TEST_ASSERT((res == result) || (res == result_ext));
#if !defined(MBEDTLS_X509_REMOVE_INFO)
if ((result) == 0) {
res = mbedtls_x509_crt_info((char *) output, 2000, "", &crt);