Unify PSA to Mbed TLS error translation
Move all error translation utilities to psa_util.c.
Introduce macros and functions to avoid having
a local copy of the error translating function in
each place.
Identify overlapping errors and introduce a
generic function.
Provide a single macro for all error translations
(unless one file needs a couple of different ones).
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
diff --git a/library/pem.c b/library/pem.c
index 8044ed6..9f14052 100644
--- a/library/pem.c
+++ b/library/pem.c
@@ -39,6 +39,13 @@
#include "psa/crypto.h"
#endif
+#if !defined(MBEDTLS_MD5_C)
+#include "mbedtls/psa_util.h"
+#define PSA_TO_MBEDTLS_ERR(status) PSA_TO_MBEDTLS_ERR_LIST(status, \
+ psa_to_md_errors, \
+ psa_generic_status_to_mbedtls)
+#endif
+
#include "mbedtls/legacy_or_psa.h"
#if defined(MBEDTLS_HAS_ALG_MD5_VIA_MD_OR_PSA_BASED_ON_USE_PSA) && \
@@ -236,7 +243,7 @@
exit:
mbedtls_platform_zeroize(md5sum, 16);
- return mbedtls_md_error_from_psa(status);
+ return PSA_TO_MBEDTLS_ERR(status);
}
#endif /* MBEDTLS_MD5_C */