@@ -343,6 +343,9 @@ int mbedtls_asn1_get_bitstring_null( unsigned char **p,
343
343
* \brief Parses and splits an ASN.1 "SEQUENCE OF <tag>".
344
344
* Updates the pointer to immediately behind the full sequence tag.
345
345
*
346
+ * This function allocates memory for the sequence elements. You can free
347
+ * the allocated memory with mbedtls_asn1_sequence_free().
348
+ *
346
349
* \note On error, this function may return a partial list in \p cur.
347
350
* You must set `cur->next = NULL` before calling this function!
348
351
* Otherwise it is impossible to distinguish a previously non-null
@@ -384,6 +387,28 @@ int mbedtls_asn1_get_sequence_of( unsigned char **p,
384
387
const unsigned char * end ,
385
388
mbedtls_asn1_sequence * cur ,
386
389
int tag );
390
+ /**
391
+ * \brief Free a heap-allocated linked list presentation of
392
+ * an ASN.1 sequence, including the first element.
393
+ *
394
+ * There are two common ways to manage the memory used for the representation
395
+ * of a parsed ASN.1 sequence:
396
+ * - Allocate a head node `mbedtls_asn1_sequence *head` with mbedtls_calloc().
397
+ * Pass this node as the `cur` argument to mbedtls_asn1_get_sequence_of().
398
+ * When you have finished processing the sequence,
399
+ * call mbedtls_asn1_sequence_free() on `head`.
400
+ * - Allocate a head node `mbedtls_asn1_sequence *head` in any manner,
401
+ * for example on the stack. Make sure that `head->next == NULL`.
402
+ * Pass `head` as the `cur` argument to mbedtls_asn1_get_sequence_of().
403
+ * When you have finished processing the sequence,
404
+ * call mbedtls_asn1_sequence_free() on `head->cur`,
405
+ * then free `head` itself in the appropriate manner.
406
+ *
407
+ * \param seq The address of the first sequence component. This may
408
+ * be \c NULL, in which case this functions returns
409
+ * immediately.
410
+ */
411
+ void mbedtls_asn1_sequence_free ( mbedtls_asn1_sequence * seq );
387
412
388
413
#if defined(MBEDTLS_BIGNUM_C )
389
414
/**
0 commit comments