Add asn1 write tag and len to x509 use c config

Signed-off-by: Agathiyan Bragadeesh <agathiyan.bragadeesh2@arm.com>
This commit is contained in:
Agathiyan Bragadeesh 2023-09-04 14:53:30 +01:00
parent a2423debcc
commit 86dc08599b
3 changed files with 8 additions and 7 deletions

View File

@ -48,6 +48,7 @@
extern "C" { extern "C" {
#endif #endif
#if defined(MBEDTLS_ASN1_WRITE_C) || defined(MBEDTLS_X509_USE_C)
/** /**
* \brief Write a length field in ASN.1 format. * \brief Write a length field in ASN.1 format.
* *
@ -76,7 +77,9 @@ int mbedtls_asn1_write_len(unsigned char **p, const unsigned char *start,
*/ */
int mbedtls_asn1_write_tag(unsigned char **p, const unsigned char *start, int mbedtls_asn1_write_tag(unsigned char **p, const unsigned char *start,
unsigned char tag); unsigned char tag);
#endif /* MBEDTLS_ASN1_WRITE_C || MBEDTLS_X509_USE_C */
#if defined(MBEDTLS_ASN1_WRITE_C)
/** /**
* \brief Write raw buffer data. * \brief Write raw buffer data.
* *
@ -393,4 +396,6 @@ mbedtls_asn1_named_data *mbedtls_asn1_store_named_data(mbedtls_asn1_named_data *
} }
#endif #endif
#endif /* MBEDTLS_ASN1_WRITE_C */
#endif /* MBEDTLS_ASN1_WRITE_H */ #endif /* MBEDTLS_ASN1_WRITE_H */

View File

@ -19,7 +19,7 @@
#include "common.h" #include "common.h"
#if defined(MBEDTLS_ASN1_WRITE_C) #if defined(MBEDTLS_ASN1_WRITE_C) || defined(MBEDTLS_X509_USE_C)
#include "mbedtls/asn1write.h" #include "mbedtls/asn1write.h"
#include "mbedtls/error.h" #include "mbedtls/error.h"
@ -102,7 +102,9 @@ int mbedtls_asn1_write_tag(unsigned char **p, const unsigned char *start, unsign
return 1; return 1;
} }
#endif /* MBEDTLS_ASN1_WRITE_C || MBEDTLS_X509_USE_C */
#if defined(MBEDTLS_ASN1_WRITE_C)
int mbedtls_asn1_write_raw_buffer(unsigned char **p, const unsigned char *start, int mbedtls_asn1_write_raw_buffer(unsigned char **p, const unsigned char *start,
const unsigned char *buf, size_t size) const unsigned char *buf, size_t size)
{ {

View File

@ -43,9 +43,7 @@
#include "mbedtls/pem.h" #include "mbedtls/pem.h"
#endif #endif
#if defined(MBEDTLS_ASN1_WRITE_C)
#include "mbedtls/asn1write.h" #include "mbedtls/asn1write.h"
#endif
#include "mbedtls/platform.h" #include "mbedtls/platform.h"
@ -874,7 +872,6 @@ int mbedtls_x509_dn_gets(char *buf, size_t size, const mbedtls_x509_name *dn)
MBEDTLS_X509_SAFE_SNPRINTF; MBEDTLS_X509_SAFE_SNPRINTF;
if (print_hexstring) { if (print_hexstring) {
#if defined(MBEDTLS_ASN1_WRITE_C)
s[0] = '#'; s[0] = '#';
asn1_len_p = asn1_tag_len_buf + 10; asn1_len_p = asn1_tag_len_buf + 10;
@ -907,9 +904,6 @@ int mbedtls_x509_dn_gets(char *buf, size_t size, const mbedtls_x509_name *dn)
s[j++] = nibble_to_hex_digit(highbits); s[j++] = nibble_to_hex_digit(highbits);
s[j++] = nibble_to_hex_digit(lowbits); s[j++] = nibble_to_hex_digit(lowbits);
} }
#else
return MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE;
#endif
} else { } else {
for (i = 0, j = 0; i < name->val.len; i++, j++) { for (i = 0, j = 0; i < name->val.len; i++, j++) {
if (j >= sizeof(s) - 1) { if (j >= sizeof(s) - 1) {