Add preprocessor config guards

Signed-off-by: Agathiyan Bragadeesh <agathiyan.bragadeesh2@arm.com>
This commit is contained in:
Agathiyan Bragadeesh 2023-07-31 16:10:07 +01:00
parent 6cbfae591a
commit 0eb6673a80
2 changed files with 12 additions and 0 deletions

View file

@ -876,12 +876,15 @@ int mbedtls_x509_dn_gets(char *buf, size_t size, const mbedtls_x509_name *dn)
} }
if(is_numericoid) { if(is_numericoid) {
#if defined(MBEDTLS_ASN1_WRITE_C)
s[0] = '#'; s[0] = '#';
c = name->val.tag; c = name->val.tag;
char lowbits = (c & 0x0F); char lowbits = (c & 0x0F);
char highbits = c>>4; char highbits = c>>4;
s[1] = nibble_to_hex_digit(highbits); s[1] = nibble_to_hex_digit(highbits);
s[2] = nibble_to_hex_digit(lowbits); s[2] = nibble_to_hex_digit(lowbits);
asn1_len_p = asn1_len_buf+5; asn1_len_p = asn1_len_buf+5;
asn1_len_size = mbedtls_asn1_write_len(&asn1_len_p,asn1_len_buf,name->val.len); asn1_len_size = mbedtls_asn1_write_len(&asn1_len_p,asn1_len_buf,name->val.len);
asn1_len_start = 5 - asn1_len_size; asn1_len_start = 5 - asn1_len_size;
@ -900,6 +903,9 @@ 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) {

View file

@ -209,6 +209,7 @@ static int parse_attribute_value_string(const char *s, int len, unsigned char *d
return 0; return 0;
} }
#if defined(MBEDTLS_ASN1_PARSE_C)
static int parse_attribute_value_ber_encoded(const char *s, int len, unsigned char *data, size_t *data_len, int *tag) static int parse_attribute_value_ber_encoded(const char *s, int len, unsigned char *data, size_t *data_len, int *tag)
{ {
const char *c = s; const char *c = s;
@ -247,6 +248,7 @@ static int parse_attribute_value_ber_encoded(const char *s, int len, unsigned ch
return 0; return 0;
} }
#endif
int mbedtls_x509_string_to_names(mbedtls_asn1_named_data **head, const char *name) int mbedtls_x509_string_to_names(mbedtls_asn1_named_data **head, const char *name)
{ {
@ -290,10 +292,14 @@ int mbedtls_x509_string_to_names(mbedtls_asn1_named_data **head, const char *nam
tag = attr_descr->default_tag; tag = attr_descr->default_tag;
} }
if (numericoid) { if (numericoid) {
#if defined(MBEDTLS_ASN1_PARSE_C)
if ((parse_ret = if ((parse_ret =
parse_attribute_value_ber_encoded(s, c - s, data, &data_len, &tag)) != 0) { parse_attribute_value_ber_encoded(s, c - s, data, &data_len, &tag)) != 0) {
return parse_ret; return parse_ret;
} }
#else
return MBEDTLS_ERR_X509_INVALID_NAME;
#endif
} }
mbedtls_asn1_named_data *cur = mbedtls_asn1_named_data *cur =
mbedtls_asn1_store_named_data(head, oid, strlen(oid), mbedtls_asn1_store_named_data(head, oid, strlen(oid),