Introduce psa_key_handle_is_null inline function
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
diff --git a/include/mbedtls/ssl_internal.h b/include/mbedtls/ssl_internal.h
index 30be676..015b53c 100644
--- a/include/mbedtls/ssl_internal.h
+++ b/include/mbedtls/ssl_internal.h
@@ -1064,10 +1064,10 @@
static inline psa_key_handle_t mbedtls_ssl_get_opaque_psk(
const mbedtls_ssl_context *ssl )
{
- if( ssl->handshake->psk_opaque != 0 )
+ if( ! psa_key_handle_is_null( ssl->handshake->psk_opaque ) )
return( ssl->handshake->psk_opaque );
- if( ssl->conf->psk_opaque != 0 )
+ if( ! psa_key_handle_is_null( ssl->conf->psk_opaque ) )
return( ssl->conf->psk_opaque );
return( PSA_KEY_HANDLE_INIT );
diff --git a/include/psa/crypto_platform.h b/include/psa/crypto_platform.h
index 6ada324..a27136d 100644
--- a/include/psa/crypto_platform.h
+++ b/include/psa/crypto_platform.h
@@ -53,6 +53,17 @@
typedef uint16_t psa_key_handle_t;
#define PSA_KEY_HANDLE_INIT ( (psa_key_handle_t)0 )
+/** Check whether a handle is null.
+ *
+ * \param handle Key handle.
+ *
+ * \return Non-zero if the key handle is null, zero otherwise.
+ */
+static inline int psa_key_handle_is_null( psa_key_handle_t handle )
+{
+ return( handle == 0 );
+}
+
#if defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER)
/* Building for the PSA Crypto service on a PSA platform, a key owner is a PSA