From 979aa49d1cee5374dc607c0d869df4047c8d5b6e Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Thu, 21 Apr 2022 11:53:55 +0100 Subject: [PATCH] Add accessor for x509 certificate extension types Add accessor for x509 certificate extension types Signed-off-by: Thomas Daubney --- include/mbedtls/x509_crt.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/mbedtls/x509_crt.h b/include/mbedtls/x509_crt.h index 51883dc86..0b0120b70 100644 --- a/include/mbedtls/x509_crt.h +++ b/include/mbedtls/x509_crt.h @@ -1137,6 +1137,23 @@ int mbedtls_x509write_crt_set_key_usage( mbedtls_x509write_cert *ctx, int mbedtls_x509write_crt_set_ns_cert_type( mbedtls_x509write_cert *ctx, unsigned char ns_cert_type ); +/** + * \brief Query certificate for given extension type + * + * \param[in] ctx Certificate context to be queried, must not be \c NULL + * \param ext_type Extension type being queried for, must be a valid + * extension type. Must be one of the MBEDTLS_X509_EXT_XXX + * values + * + * \return 0 if the given extension type is not present, + * non-zero otherwise + */ +static inline int mbedtls_x509_crt_has_ext_type( const mbedtls_x509_crt *ctx, + int ext_type ) +{ + return ctx->MBEDTLS_PRIVATE(ext_types) & ext_type; +} + /** * \brief Free the contents of a CRT write context *