Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
asn1.h File Reference
Generic ASN.1 parsing. More...
Go to the source code of this file.
Data Structures | |
| struct | mbedtls_asn1_buf |
| Type-length-value structure that allows for ASN1 using DER. More... | |
| struct | mbedtls_asn1_bitstring |
| Container for ASN1 bit strings. More... | |
| struct | mbedtls_asn1_sequence |
| Container for a sequence of ASN.1 items. More... | |
| struct | mbedtls_asn1_named_data |
| Container for a sequence or list of 'named' ASN.1 data items. More... | |
Functions to parse ASN.1 data structures | |
| typedef struct mbedtls_asn1_buf | mbedtls_asn1_buf |
| Type-length-value structure that allows for ASN1 using DER. | |
| typedef struct mbedtls_asn1_bitstring | mbedtls_asn1_bitstring |
| Container for ASN1 bit strings. | |
| typedef struct mbedtls_asn1_sequence | mbedtls_asn1_sequence |
| Container for a sequence of ASN.1 items. | |
| typedef struct mbedtls_asn1_named_data | mbedtls_asn1_named_data |
| Container for a sequence or list of 'named' ASN.1 data items. | |
| int | mbedtls_asn1_get_len (unsigned char **p, const unsigned char *end, size_t *len) |
| Get the length of an ASN.1 element. | |
| int | mbedtls_asn1_get_tag (unsigned char **p, const unsigned char *end, size_t *len, int tag) |
| Get the tag and length of the element. | |
| int | mbedtls_asn1_get_bool (unsigned char **p, const unsigned char *end, int *val) |
| Retrieve a boolean ASN.1 tag and its value. | |
| int | mbedtls_asn1_get_int (unsigned char **p, const unsigned char *end, int *val) |
| Retrieve an integer ASN.1 tag and its value. | |
| int | mbedtls_asn1_get_bitstring (unsigned char **p, const unsigned char *end, mbedtls_asn1_bitstring *bs) |
| Retrieve a bitstring ASN.1 tag and its value. | |
| int | mbedtls_asn1_get_bitstring_null (unsigned char **p, const unsigned char *end, size_t *len) |
| Retrieve a bitstring ASN.1 tag without unused bits and its value. | |
| int | mbedtls_asn1_get_sequence_of (unsigned char **p, const unsigned char *end, mbedtls_asn1_sequence *cur, int tag) |
| Parses and splits an ASN.1 "SEQUENCE OF <tag>". | |
| int | mbedtls_asn1_get_mpi (unsigned char **p, const unsigned char *end, mbedtls_mpi *X) |
| Retrieve an integer ASN.1 tag and its value. | |
| int | mbedtls_asn1_get_alg (unsigned char **p, const unsigned char *end, mbedtls_asn1_buf *alg, mbedtls_asn1_buf *params) |
| Retrieve an AlgorithmIdentifier ASN.1 sequence. | |
| int | mbedtls_asn1_get_alg_null (unsigned char **p, const unsigned char *end, mbedtls_asn1_buf *alg) |
| Retrieve an AlgorithmIdentifier ASN.1 sequence with NULL or no params. | |
| mbedtls_asn1_named_data * | mbedtls_asn1_find_named_data (mbedtls_asn1_named_data *list, const char *oid, size_t len) |
| Find a specific named_data entry in a sequence or list based on the OID. | |
| void | mbedtls_asn1_free_named_data (mbedtls_asn1_named_data *entry) |
| Free a mbedtls_asn1_named_data entry. | |
| void | mbedtls_asn1_free_named_data_list (mbedtls_asn1_named_data **head) |
| Free all entries in a mbedtls_asn1_named_data list. | |
Detailed Description
Generic ASN.1 parsing.
Definition in file asn1.h.
Typedef Documentation
| typedef struct mbedtls_asn1_bitstring mbedtls_asn1_bitstring |
Container for ASN1 bit strings.
| typedef struct mbedtls_asn1_buf mbedtls_asn1_buf |
Type-length-value structure that allows for ASN1 using DER.
| typedef struct mbedtls_asn1_named_data mbedtls_asn1_named_data |
Container for a sequence or list of 'named' ASN.1 data items.
| typedef struct mbedtls_asn1_sequence mbedtls_asn1_sequence |
Container for a sequence of ASN.1 items.
Function Documentation
| mbedtls_asn1_named_data* mbedtls_asn1_find_named_data | ( | mbedtls_asn1_named_data * | list, |
| const char * | oid, | ||
| size_t | len | ||
| ) |
Find a specific named_data entry in a sequence or list based on the OID.
- Parameters:
-
list The list to seek through oid The OID to look for len Size of the OID
- Returns:
- NULL if not found, or a pointer to the existing entry.
Definition at line 394 of file asn1parse.c.
| void mbedtls_asn1_free_named_data | ( | mbedtls_asn1_named_data * | entry ) |
Free a mbedtls_asn1_named_data entry.
- Parameters:
-
entry The named data entry to free. This function calls mbedtls_free() on `entry->oid.p` and `entry->val.p`.
Definition at line 371 of file asn1parse.c.
| void mbedtls_asn1_free_named_data_list | ( | mbedtls_asn1_named_data ** | head ) |
Free all entries in a mbedtls_asn1_named_data list.
- Parameters:
-
head Pointer to the head of the list of named data entries to free. This function calls mbedtls_asn1_free_named_data() and mbedtls_free() on each list element and sets *headtoNULL.
Definition at line 382 of file asn1parse.c.
| int mbedtls_asn1_get_alg | ( | unsigned char ** | p, |
| const unsigned char * | end, | ||
| mbedtls_asn1_buf * | alg, | ||
| mbedtls_asn1_buf * | params | ||
| ) |
Retrieve an AlgorithmIdentifier ASN.1 sequence.
Updates the pointer to immediately behind the full AlgorithmIdentifier.
- Parameters:
-
p On entry, *ppoints to the start of the ASN.1 element. On successful completion,*ppoints to the first byte beyond the AlgorithmIdentifier element. On error, the value of*pis undefined.end End of data. alg The buffer to receive the OID. params The buffer to receive the parameters. This is zeroized if there are no parameters.
- Returns:
- 0 if successful or a specific ASN.1 or MPI error code.
Definition at line 309 of file asn1parse.c.
| int mbedtls_asn1_get_alg_null | ( | unsigned char ** | p, |
| const unsigned char * | end, | ||
| mbedtls_asn1_buf * | alg | ||
| ) |
Retrieve an AlgorithmIdentifier ASN.1 sequence with NULL or no params.
Updates the pointer to immediately behind the full AlgorithmIdentifier.
- Parameters:
-
p On entry, *ppoints to the start of the ASN.1 element. On successful completion,*ppoints to the first byte beyond the AlgorithmIdentifier element. On error, the value of*pis undefined.end End of data. alg The buffer to receive the OID.
- Returns:
- 0 if successful or a specific ASN.1 or MPI error code.
Definition at line 353 of file asn1parse.c.
| int mbedtls_asn1_get_bitstring | ( | unsigned char ** | p, |
| const unsigned char * | end, | ||
| mbedtls_asn1_bitstring * | bs | ||
| ) |
Retrieve a bitstring ASN.1 tag and its value.
Updates the pointer to immediately behind the full tag.
- Parameters:
-
p On entry, *ppoints to the start of the ASN.1 element. On successful completion,*pis equal toend. On error, the value of*pis undefined.end End of data. bs On success, mbedtls_asn1_bitstring information about the parsed value.
- Returns:
- 0 if successful.
- MBEDTLS_ERR_ASN1_LENGTH_MISMATCH if the input contains extra data after a valid BIT STRING.
- An ASN.1 error code if the input does not start with a valid ASN.1 BIT STRING.
Definition at line 202 of file asn1parse.c.
| int mbedtls_asn1_get_bitstring_null | ( | unsigned char ** | p, |
| const unsigned char * | end, | ||
| size_t * | len | ||
| ) |
Retrieve a bitstring ASN.1 tag without unused bits and its value.
Updates the pointer to the beginning of the bit/octet string.
- Parameters:
-
p On entry, *ppoints to the start of the ASN.1 element. On successful completion,*ppoints to the first byte of the content of the BIT STRING. On error, the value of*pis undefined.end End of data. len On success, *lenis the length of the content in bytes.
- Returns:
- 0 if successful.
- MBEDTLS_ERR_ASN1_INVALID_DATA if the input starts with a valid BIT STRING with a nonzero number of unused bits.
- An ASN.1 error code if the input does not start with a valid ASN.1 BIT STRING.
Definition at line 235 of file asn1parse.c.
| int mbedtls_asn1_get_bool | ( | unsigned char ** | p, |
| const unsigned char * | end, | ||
| int * | val | ||
| ) |
Retrieve a boolean ASN.1 tag and its value.
Updates the pointer to immediately behind the full tag.
- Parameters:
-
p On entry, *ppoints to the start of the ASN.1 element. On successful completion,*ppoints to the first byte beyond the ASN.1 element. On error, the value of*pis undefined.end End of data. val On success, the parsed value ( 0or1).
- Returns:
- 0 if successful.
- An ASN.1 error code if the input does not start with a valid ASN.1 BOOLEAN.
Definition at line 123 of file asn1parse.c.
| int mbedtls_asn1_get_int | ( | unsigned char ** | p, |
| const unsigned char * | end, | ||
| int * | val | ||
| ) |
Retrieve an integer ASN.1 tag and its value.
Updates the pointer to immediately behind the full tag.
- Parameters:
-
p On entry, *ppoints to the start of the ASN.1 element. On successful completion,*ppoints to the first byte beyond the ASN.1 element. On error, the value of*pis undefined.end End of data. val On success, the parsed value.
- Returns:
- 0 if successful.
- An ASN.1 error code if the input does not start with a valid ASN.1 INTEGER.
-
MBEDTLS_ERR_ASN1_INVALID_LENGTH if the parsed value does not fit in an
int. - An ASN.1 error code if the input does not start with a valid ASN.1 INTEGER.
Definition at line 142 of file asn1parse.c.
| int mbedtls_asn1_get_len | ( | unsigned char ** | p, |
| const unsigned char * | end, | ||
| size_t * | len | ||
| ) |
Get the length of an ASN.1 element.
Updates the pointer to immediately behind the length.
- Parameters:
-
p On entry, *ppoints to the first byte of the length, i.e. immediately after the tag. On successful completion,*ppoints to the first byte after the length, i.e. the first byte of the content. On error, the value of*pis undefined.end End of data. len On successful completion, *lencontains the length read from the ASN.1 input.
- Returns:
- 0 if successful.
-
MBEDTLS_ERR_ASN1_OUT_OF_DATA if the ASN.1 element would end beyond
end. - MBEDTLS_ERR_ASN1_INVALID_LENGTH if the length is unparseable.
Definition at line 50 of file asn1parse.c.
| int mbedtls_asn1_get_mpi | ( | unsigned char ** | p, |
| const unsigned char * | end, | ||
| mbedtls_mpi * | X | ||
| ) |
Retrieve an integer ASN.1 tag and its value.
Updates the pointer to immediately behind the full tag.
- Parameters:
-
p On entry, *ppoints to the start of the ASN.1 element. On successful completion,*ppoints to the first byte beyond the ASN.1 element. On error, the value of*pis undefined.end End of data. X On success, the parsed value.
- Returns:
- 0 if successful.
- An ASN.1 error code if the input does not start with a valid ASN.1 INTEGER.
-
MBEDTLS_ERR_ASN1_INVALID_LENGTH if the parsed value does not fit in an
int. - An MPI error code if the parsed value is too large.
- An ASN.1 error code if the input does not start with a valid ASN.1 INTEGER.
Definition at line 184 of file asn1parse.c.
| int mbedtls_asn1_get_sequence_of | ( | unsigned char ** | p, |
| const unsigned char * | end, | ||
| mbedtls_asn1_sequence * | cur, | ||
| int | tag | ||
| ) |
Parses and splits an ASN.1 "SEQUENCE OF <tag>".
Updates the pointer to immediately behind the full sequence tag.
- Note:
- On error, this function may return a partial list in
cur. You must set `cur->next = NULL` before calling this function! Otherwise it is impossible to distinguish a previously non-null pointer from a pointer to an object allocated by this function. -
If the sequence is empty, this function does not modify
*cur. If the sequence is valid and non-empty, this function sets `cur->buf.tag` totag. This allows callers to distinguish between an empty sequence and a one-element sequence.
- Parameters:
-
p On entry, *ppoints to the start of the ASN.1 element. On successful completion,*pis equal toend. On error, the value of*pis undefined.end End of data. cur A mbedtls_asn1_sequence which this function fills. When this function returns, *curis the head of a linked list. Each node in this list is allocated with mbedtls_calloc() apart fromcuritself, and should therefore be freed with mbedtls_free(). The list describes the content of the sequence. The head of the list (i.e.*curitself) describes the first element, `*cur->next` describes the second element, etc. For each element, `buf.tag == tag`, `buf.len` is the length of the content of the content of the element, and `buf.p` points to the first byte of the content (i.e. immediately past the length of the element). Note that list elements may be allocated even on error.tag Each element of the sequence must have this tag.
- Returns:
- 0 if successful.
-
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH if the input contains extra data after a valid SEQUENCE OF
tag. - MBEDTLS_ERR_ASN1_ALLOC_FAILED if a memory allocation failed.
- An ASN.1 error code if the input does not start with a valid ASN.1 BIT STRING.
Definition at line 259 of file asn1parse.c.
| int mbedtls_asn1_get_tag | ( | unsigned char ** | p, |
| const unsigned char * | end, | ||
| size_t * | len, | ||
| int | tag | ||
| ) |
Get the tag and length of the element.
Check for the requested tag. Updates the pointer to immediately behind the tag and length.
- Parameters:
-
p On entry, *ppoints to the start of the ASN.1 element. On successful completion,*ppoints to the first byte after the length, i.e. the first byte of the content. On error, the value of*pis undefined.end End of data. len On successful completion, *lencontains the length read from the ASN.1 input.tag The expected tag.
- Returns:
- 0 if successful.
- MBEDTLS_ERR_ASN1_UNEXPECTED_TAG if the data does not start with the requested tag.
-
MBEDTLS_ERR_ASN1_OUT_OF_DATA if the ASN.1 element would end beyond
end. - MBEDTLS_ERR_ASN1_INVALID_LENGTH if the length is unparseable.
Definition at line 108 of file asn1parse.c.
Generated on Tue Jul 12 2022 13:55:05 by
1.7.2