mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-08-05 19:35:48 +03:00
Refactor dn_gets use library function to write tag
Signed-off-by: Agathiyan Bragadeesh <agathiyan.bragadeesh2@arm.com>
This commit is contained in:
@@ -826,8 +826,8 @@ static char nibble_to_hex_digit(int i)
|
|||||||
int mbedtls_x509_dn_gets(char *buf, size_t size, const mbedtls_x509_name *dn)
|
int mbedtls_x509_dn_gets(char *buf, size_t size, const mbedtls_x509_name *dn)
|
||||||
{
|
{
|
||||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||||
size_t i, j, n, asn1_len_size, asn1_len_start;
|
size_t i, j, n, asn1_len_size, asn1_tag_size, asn1_tag_len_buf_start;
|
||||||
unsigned char asn1_len_buf[5];
|
unsigned char asn1_tag_len_buf[10];
|
||||||
unsigned char *asn1_len_p;
|
unsigned char *asn1_len_p;
|
||||||
unsigned char c, merge = 0;
|
unsigned char c, merge = 0;
|
||||||
const mbedtls_x509_name *name;
|
const mbedtls_x509_name *name;
|
||||||
@@ -874,28 +874,29 @@ int mbedtls_x509_dn_gets(char *buf, size_t size, const mbedtls_x509_name *dn)
|
|||||||
#if defined(MBEDTLS_ASN1_WRITE_C)
|
#if defined(MBEDTLS_ASN1_WRITE_C)
|
||||||
s[0] = '#';
|
s[0] = '#';
|
||||||
|
|
||||||
c = name->val.tag;
|
asn1_len_p = asn1_tag_len_buf + 10;
|
||||||
lowbits = (c & 0x0F);
|
asn1_len_size = mbedtls_asn1_write_len(&asn1_len_p, asn1_tag_len_buf, name->val.len);
|
||||||
highbits = c >> 4;
|
asn1_tag_size = mbedtls_asn1_write_tag(&asn1_len_p,asn1_tag_len_buf,name->val.tag);
|
||||||
s[1] = nibble_to_hex_digit(highbits);
|
asn1_tag_len_buf_start = 10 - asn1_len_size - asn1_tag_size;
|
||||||
s[2] = nibble_to_hex_digit(lowbits);
|
for (i = 0, j = 1; i < asn1_len_size + asn1_tag_size; i++) {
|
||||||
|
|
||||||
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_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) {
|
if (j + 1 >= sizeof(s) - 1) {
|
||||||
return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL;
|
return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL;
|
||||||
}
|
}
|
||||||
if (i < asn1_len_size) {
|
c = asn1_tag_len_buf[asn1_tag_len_buf_start+i];
|
||||||
c = asn1_len_buf[asn1_len_start+i];
|
|
||||||
} else {
|
|
||||||
c = name->val.p[i-asn1_len_size];
|
|
||||||
}
|
|
||||||
lowbits = (c & 0x0F);
|
lowbits = (c & 0x0F);
|
||||||
highbits = c >> 4;
|
highbits = c >> 4;
|
||||||
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);
|
||||||
|
}
|
||||||
|
for (i = 0; i < name->val.len; i++) {
|
||||||
|
if (j + 1 >= sizeof(s) - 1) {
|
||||||
|
return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL;
|
||||||
|
}
|
||||||
|
c = name->val.p[i];
|
||||||
|
lowbits = (c & 0x0F);
|
||||||
|
highbits = c >> 4;
|
||||||
|
s[j++] = nibble_to_hex_digit(highbits);
|
||||||
|
s[j++] = nibble_to_hex_digit(lowbits);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
return MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE;
|
return MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE;
|
||||||
|
Reference in New Issue
Block a user