Make fields of ASN.1 data structures public

The structures mbedtls_asn1_buf, mbedtls_asn1_bitstring,
mbedtls_asn1_sequence and mbedtls_asn1_named_data are designed to allow
access to data after parsing. Make their fields public.

Document that chaining fields are essentially read-only.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine 2021-08-04 20:55:33 +02:00
parent b11d61e095
commit b89d9c0599

View file

@ -152,9 +152,9 @@ extern "C" {
*/ */
typedef struct mbedtls_asn1_buf typedef struct mbedtls_asn1_buf
{ {
int MBEDTLS_PRIVATE(tag); /**< ASN1 type, e.g. MBEDTLS_ASN1_UTF8_STRING. */ int tag; /**< ASN1 type, e.g. MBEDTLS_ASN1_UTF8_STRING. */
size_t MBEDTLS_PRIVATE(len); /**< ASN1 length, in octets. */ size_t len; /**< ASN1 length, in octets. */
unsigned char *MBEDTLS_PRIVATE(p); /**< ASN1 data, e.g. in ASCII. */ unsigned char *p; /**< ASN1 data, e.g. in ASCII. */
} }
mbedtls_asn1_buf; mbedtls_asn1_buf;
@ -163,9 +163,9 @@ mbedtls_asn1_buf;
*/ */
typedef struct mbedtls_asn1_bitstring typedef struct mbedtls_asn1_bitstring
{ {
size_t MBEDTLS_PRIVATE(len); /**< ASN1 length, in octets. */ size_t len; /**< ASN1 length, in octets. */
unsigned char MBEDTLS_PRIVATE(unused_bits); /**< Number of unused bits at the end of the string */ unsigned char unused_bits; /**< Number of unused bits at the end of the string */
unsigned char *MBEDTLS_PRIVATE(p); /**< Raw ASN1 data for the bit string */ unsigned char *p; /**< Raw ASN1 data for the bit string */
} }
mbedtls_asn1_bitstring; mbedtls_asn1_bitstring;
@ -174,8 +174,16 @@ mbedtls_asn1_bitstring;
*/ */
typedef struct mbedtls_asn1_sequence typedef struct mbedtls_asn1_sequence
{ {
mbedtls_asn1_buf MBEDTLS_PRIVATE(buf); /**< Buffer containing the given ASN.1 item. */ mbedtls_asn1_buf buf; /**< Buffer containing the given ASN.1 item. */
struct mbedtls_asn1_sequence *MBEDTLS_PRIVATE(next); /**< The next entry in the sequence. */
/** The next entry in the sequence.
*
* The details memory management for sequences are not documented and
* may change in future versions. Set this field to \p NULL when
* initializing a structure, and do not modify it except via Mbed TLS
* library functions.
*/
struct mbedtls_asn1_sequence *next;
} }
mbedtls_asn1_sequence; mbedtls_asn1_sequence;
@ -184,10 +192,24 @@ mbedtls_asn1_sequence;
*/ */
typedef struct mbedtls_asn1_named_data typedef struct mbedtls_asn1_named_data
{ {
mbedtls_asn1_buf MBEDTLS_PRIVATE(oid); /**< The object identifier. */ mbedtls_asn1_buf oid; /**< The object identifier. */
mbedtls_asn1_buf MBEDTLS_PRIVATE(val); /**< The named value. */ mbedtls_asn1_buf val; /**< The named value. */
struct mbedtls_asn1_named_data *MBEDTLS_PRIVATE(next); /**< The next entry in the sequence. */
unsigned char MBEDTLS_PRIVATE(next_merged); /**< Merge next item into the current one? */ /** The next entry in the sequence.
*
* The details memory management for named data sequences are not documented
* and may change in future versions. Set this field to \p NULL when
* initializing a structure, and do not modify it except via Mbed TLS
* library functions.
*/
struct mbedtls_asn1_named_data *next;
/** Merge next item into the current one?
*
* This field exists for the sake of Mbed TLS's X.509 certificate parsing
* code and may change in future versions of the library.
*/
unsigned char MBEDTLS_PRIVATE(next_merged);
} }
mbedtls_asn1_named_data; mbedtls_asn1_named_data;