Fix code style on x509.c and x509_create.c

Signed-off-by: Agathiyan Bragadeesh <agathiyan.bragadeesh2@arm.com>
This commit is contained in:
Agathiyan Bragadeesh 2023-08-01 11:10:52 +01:00
parent c9d74f3109
commit 4987c8fcb0
2 changed files with 40 additions and 33 deletions

View File

@ -854,12 +854,13 @@ int mbedtls_x509_dn_gets(char *buf, size_t size, const mbedtls_x509_name *dn)
MBEDTLS_X509_SAFE_SNPRINTF;
}
print_hexstring = (name->val.tag == MBEDTLS_ASN1_BIT_STRING) || (name->val.tag == MBEDTLS_ASN1_OCTET_STRING);
print_hexstring = (name->val.tag == MBEDTLS_ASN1_BIT_STRING) ||
(name->val.tag == MBEDTLS_ASN1_OCTET_STRING);
if ((ret = mbedtls_oid_get_attr_short_name(&name->oid, &short_name)) == 0) {
ret = mbedtls_snprintf(p, n, "%s=", short_name);
} else {
if ((ret = mbedtls_oid_get_numeric_string(numericoid,256,&name->oid)) > 0) {
if ((ret = mbedtls_oid_get_numeric_string(numericoid, 256, &name->oid)) > 0) {
ret = mbedtls_snprintf(p, n, "%s=", numericoid);
print_hexstring = 1;
} else {
@ -868,7 +869,7 @@ int mbedtls_x509_dn_gets(char *buf, size_t size, const mbedtls_x509_name *dn)
}
MBEDTLS_X509_SAFE_SNPRINTF;
if(print_hexstring) {
if (print_hexstring) {
#if defined(MBEDTLS_ASN1_WRITE_C)
s[0] = '#';
@ -879,16 +880,15 @@ int mbedtls_x509_dn_gets(char *buf, size_t size, const mbedtls_x509_name *dn)
s[2] = nibble_to_hex_digit(lowbits);
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;
for (i = 0, j = 3; i < asn1_len_size + name->val.len; i++, j++) {
if (j + 1 >= sizeof(s) - 1) {
return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL;
}
if(i < asn1_len_size) {
if (i < asn1_len_size) {
c = asn1_len_buf[asn1_len_start+i];
}
else {
} else {
c = name->val.p[i-asn1_len_size];
}
char lowbits = (c & 0x0F);

View File

@ -175,7 +175,10 @@ static int hexpair_to_int(char c1, char c2)
}
}
static int parse_attribute_value_string(const char *s, int len, unsigned char *data, size_t *data_len)
static int parse_attribute_value_string(const char *s,
int len,
unsigned char *data,
size_t *data_len)
{
const char *c = s;
const char *end = c + len;
@ -210,41 +213,45 @@ static int parse_attribute_value_string(const char *s, int len, unsigned char *d
}
#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 *end = c + len;
unsigned char asn1_der_buf[256];
unsigned char *asn1_der_end;
unsigned char *p;
unsigned char *asn1_der_end;
unsigned char *p;
unsigned char *d;
int n;
/* Converting from hexstring to raw binary so we can use asn1parse.c*/
if ((len < 5) || (*c != '#')) {
return MBEDTLS_ERR_X509_INVALID_NAME;
}
c++;
if((*tag = hexpair_to_int(*c, *(c+1))) == -1) {
return MBEDTLS_ERR_X509_INVALID_NAME;
}
c += 2;
p = asn1_der_buf;
/* Converting from hexstring to raw binary so we can use asn1parse.c*/
if ((len < 5) || (*c != '#')) {
return MBEDTLS_ERR_X509_INVALID_NAME;
}
c++;
if ((*tag = hexpair_to_int(*c, *(c+1))) == -1) {
return MBEDTLS_ERR_X509_INVALID_NAME;
}
c += 2;
p = asn1_der_buf;
for (p = asn1_der_buf; c < end; c += 2) {
if ((c + 1 >= end) || (n = hexpair_to_int(*c, *(c+1))) == -1) {
return MBEDTLS_ERR_X509_INVALID_NAME;
}
*(p++) = n;
}
asn1_der_end = p;
asn1_der_end = p;
p = asn1_der_buf;
if(mbedtls_asn1_get_len(&p, asn1_der_end, data_len) != 0) {
return MBEDTLS_ERR_X509_INVALID_NAME;
}
p = asn1_der_buf;
if (mbedtls_asn1_get_len(&p, asn1_der_end, data_len) != 0) {
return MBEDTLS_ERR_X509_INVALID_NAME;
}
for (d = data; p < asn1_der_end; p++) {
*(d++) = *p;
}
for (d = data; p < asn1_der_end; p++) {
*(d++) = *p;
}
return 0;
}
@ -292,14 +299,14 @@ int mbedtls_x509_string_to_names(mbedtls_asn1_named_data **head, const char *nam
tag = attr_descr->default_tag;
}
if (numericoid) {
#if defined(MBEDTLS_ASN1_PARSE_C)
#if defined(MBEDTLS_ASN1_PARSE_C)
if ((parse_ret =
parse_attribute_value_ber_encoded(s, c - s, data, &data_len, &tag)) != 0) {
return parse_ret;
}
#else
return MBEDTLS_ERR_X509_INVALID_NAME;
#endif
#else
return MBEDTLS_ERR_X509_INVALID_NAME;
#endif
}
mbedtls_asn1_named_data *cur =
mbedtls_asn1_store_named_data(head, oid, strlen(oid),