mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
Clarify structure of parsing with comments:
1. Parse through to get the required buffer length. 2. Having allocated a buffer, parse into the buffer. Signed-off-by: David Horstmann <david.horstmann@arm.com>
This commit is contained in:
@ -954,6 +954,8 @@ int mbedtls_oid_from_numeric_string(mbedtls_asn1_buf *oid,
|
|||||||
size_t encoded_len;
|
size_t encoded_len;
|
||||||
unsigned int component1, component2;
|
unsigned int component1, component2;
|
||||||
|
|
||||||
|
/* First pass - parse the string to get the length of buffer required */
|
||||||
|
|
||||||
ret = oid_parse_number(&component1, &str_ptr, str_bound);
|
ret = oid_parse_number(&component1, &str_ptr, str_bound);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
return ret;
|
return ret;
|
||||||
@ -1014,7 +1016,9 @@ int mbedtls_oid_from_numeric_string(mbedtls_asn1_buf *oid,
|
|||||||
}
|
}
|
||||||
oid->len = encoded_len;
|
oid->len = encoded_len;
|
||||||
|
|
||||||
/* Now that we've allocated the buffer, go back to the start and encode */
|
/* Second pass - now that we've allocated the buffer, go back to the
|
||||||
|
* start and encode */
|
||||||
|
|
||||||
str_ptr = oid_str;
|
str_ptr = oid_str;
|
||||||
unsigned char *out_ptr = oid->p;
|
unsigned char *out_ptr = oid->p;
|
||||||
unsigned char *out_bound = oid->p + oid->len;
|
unsigned char *out_bound = oid->p + oid->len;
|
||||||
|
Reference in New Issue
Block a user