Refactor parse_attribute_value_string
Signed-off-by: Agathiyan Bragadeesh <agathiyan.bragadeesh2@arm.com>
This commit is contained in:
parent
1aece47e8c
commit
de02ee268e
1 changed files with 8 additions and 12 deletions
|
@ -141,7 +141,7 @@ static int hexpair_to_int(const char *hexpair)
|
||||||
{
|
{
|
||||||
int n1 = hex_to_int(*hexpair);
|
int n1 = hex_to_int(*hexpair);
|
||||||
int n2 = hex_to_int(*(hexpair + 1));
|
int n2 = hex_to_int(*(hexpair + 1));
|
||||||
|
|
||||||
if (n1 != -1 && n2 != -1) {
|
if (n1 != -1 && n2 != -1) {
|
||||||
return (n1 << 4) | n2;
|
return (n1 << 4) | n2;
|
||||||
} else {
|
} else {
|
||||||
|
@ -154,13 +154,12 @@ static int parse_attribute_value_string(const char *s,
|
||||||
unsigned char *data,
|
unsigned char *data,
|
||||||
size_t *data_len)
|
size_t *data_len)
|
||||||
{
|
{
|
||||||
const char *c = s;
|
const char *c;
|
||||||
const char *end = c + len;
|
const char *end = s + len;
|
||||||
int hexpair = 0;
|
|
||||||
unsigned char *d = data;
|
unsigned char *d = data;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
while (c < end) {
|
for (c = s; c < end; c++) {
|
||||||
if (*c == '\\') {
|
if (*c == '\\') {
|
||||||
c++;
|
c++;
|
||||||
|
|
||||||
|
@ -169,22 +168,19 @@ static int parse_attribute_value_string(const char *s,
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
return MBEDTLS_ERR_X509_INVALID_NAME;
|
return MBEDTLS_ERR_X509_INVALID_NAME;
|
||||||
}
|
}
|
||||||
hexpair = 1;
|
|
||||||
*(d++) = n;
|
*(d++) = n;
|
||||||
c++;
|
c++;
|
||||||
|
continue;
|
||||||
} else if (c == end || !strchr(" ,=+<>#;\"\\", *c)) {
|
} else if (c == end || !strchr(" ,=+<>#;\"\\", *c)) {
|
||||||
return MBEDTLS_ERR_X509_INVALID_NAME;
|
return MBEDTLS_ERR_X509_INVALID_NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!hexpair) {
|
|
||||||
*(d++) = *c;
|
*(d++) = *c;
|
||||||
}
|
|
||||||
if (d - data == MBEDTLS_X509_MAX_DN_NAME_SIZE) {
|
if (d - data == MBEDTLS_X509_MAX_DN_NAME_SIZE) {
|
||||||
return MBEDTLS_ERR_X509_INVALID_NAME;
|
return MBEDTLS_ERR_X509_INVALID_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
hexpair = 0;
|
|
||||||
c++;
|
|
||||||
}
|
}
|
||||||
*data_len = d - data;
|
*data_len = d - data;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue