From dcd43fcc457b8aa8fdaeebc0ef0d4ec1ee76255c Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Mon, 12 May 2025 21:09:10 +0200 Subject: [PATCH] Move oid_xxx_numeric_string back to oid.h The header `mbedtls/oid.h` now belongs to the X.509 library. Move the declarations of `mbedtls_oid_get_numeric_string()` and `mbedtls_oid_from_numeric_string()` back to this header, which is where they were in all previous releases of Mbed TLS. This avoids gratuitously breaking backward compatibility. Signed-off-by: Gilles Peskine --- include/mbedtls/oid.h | 36 ++++++++++++++++++++++++++++++++++++ include/mbedtls/x509.h | 36 ------------------------------------ 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/include/mbedtls/oid.h b/include/mbedtls/oid.h index 5ef87d3d6a..375ea60cb6 100644 --- a/include/mbedtls/oid.h +++ b/include/mbedtls/oid.h @@ -264,4 +264,40 @@ * ecdsa-with-SHA2(3) 4 } */ #define MBEDTLS_OID_ECDSA_SHA512 MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 "\x04" +#if defined(MBEDTLS_X509_USE_C) +/** + * \brief Translate an ASN.1 OID into its numeric representation + * (e.g. "\x2A\x86\x48\x86\xF7\x0D" into "1.2.840.113549") + * + * \param buf buffer to put representation in + * \param size size of the buffer + * \param oid OID to translate + * + * \return Length of the string written (excluding final NULL) or + * PSA_ERROR_BUFFER_TOO_SMALL in case of error + */ +int mbedtls_oid_get_numeric_string(char *buf, size_t size, const mbedtls_asn1_buf *oid); +#endif /* MBEDTLS_X509_USE_C */ + +#if defined(MBEDTLS_X509_CREATE_C) +/** + * \brief Translate a string containing a dotted-decimal + * representation of an ASN.1 OID into its encoded form + * (e.g. "1.2.840.113549" into "\x2A\x86\x48\x86\xF7\x0D"). + * On success, this function allocates oid->buf from the + * heap. It must be freed by the caller using mbedtls_free(). + * + * \param oid #mbedtls_asn1_buf to populate with the DER-encoded OID + * \param oid_str string representation of the OID to parse + * \param size length of the OID string, not including any null terminator + * + * \return 0 if successful + * \return #MBEDTLS_ERR_ASN1_INVALID_DATA if \p oid_str does not + * represent a valid OID + * \return #MBEDTLS_ERR_ASN1_ALLOC_FAILED if the function fails to + * allocate oid->buf + */ +int mbedtls_oid_from_numeric_string(mbedtls_asn1_buf *oid, const char *oid_str, size_t size); +#endif /* MBEDTLS_X509_CREATE_C */ + #endif /* oid.h */ diff --git a/include/mbedtls/x509.h b/include/mbedtls/x509.h index 17b3c5d3b4..2afcfb2f9f 100644 --- a/include/mbedtls/x509.h +++ b/include/mbedtls/x509.h @@ -489,42 +489,6 @@ size_t mbedtls_x509_crt_parse_cn_inet_pton(const char *cn, void *dst); p += (size_t) ret; \ } while (0) -#if defined(MBEDTLS_X509_USE_C) -/** - * \brief Translate an ASN.1 OID into its numeric representation - * (e.g. "\x2A\x86\x48\x86\xF7\x0D" into "1.2.840.113549") - * - * \param buf buffer to put representation in - * \param size size of the buffer - * \param oid OID to translate - * - * \return Length of the string written (excluding final NULL) or - * PSA_ERROR_BUFFER_TOO_SMALL in case of error - */ -int mbedtls_oid_get_numeric_string(char *buf, size_t size, const mbedtls_asn1_buf *oid); -#endif /* MBEDTLS_X509_USE_C */ - -#if defined(MBEDTLS_X509_CREATE_C) -/** - * \brief Translate a string containing a dotted-decimal - * representation of an ASN.1 OID into its encoded form - * (e.g. "1.2.840.113549" into "\x2A\x86\x48\x86\xF7\x0D"). - * On success, this function allocates oid->buf from the - * heap. It must be freed by the caller using mbedtls_free(). - * - * \param oid #mbedtls_asn1_buf to populate with the DER-encoded OID - * \param oid_str string representation of the OID to parse - * \param size length of the OID string, not including any null terminator - * - * \return 0 if successful - * \return #MBEDTLS_ERR_ASN1_INVALID_DATA if \p oid_str does not - * represent a valid OID - * \return #MBEDTLS_ERR_ASN1_ALLOC_FAILED if the function fails to - * allocate oid->buf - */ -int mbedtls_oid_from_numeric_string(mbedtls_asn1_buf *oid, const char *oid_str, size_t size); -#endif /* MBEDTLS_X509_CREATE_C */ - #ifdef __cplusplus } #endif