Skip to content

Commit 155fd3b

Browse files
author
Hanno Becker
committed
ASN.1: Introduce helper function to free ASN.1 sequence
1 parent 334df44 commit 155fd3b

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

include/mbedtls/asn1.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,16 @@ int mbedtls_asn1_get_bitstring( unsigned char **p, const unsigned char *end,
275275
int mbedtls_asn1_get_bitstring_null( unsigned char **p, const unsigned char *end,
276276
size_t *len );
277277

278+
/**
279+
* \brief Free a heap-allocated linked list presentation of
280+
* an ASN.1 sequence, including the first element.
281+
*
282+
* \param seq The address of the first sequence component. This may
283+
* be \c NULL, in which case this functions returns
284+
* immediately.
285+
*/
286+
void mbedtls_asn1_sequence_free( mbedtls_asn1_sequence *seq );
287+
278288
/**
279289
* \brief This function parses and splits an ASN.1 "SEQUENCE OF <tag>"
280290
* and updates the source buffer pointer to immediately behind

library/asn1parse.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,16 @@ int mbedtls_asn1_get_bitstring_null( unsigned char **p, const unsigned char *end
229229
return( 0 );
230230
}
231231

232-
232+
void mbedtls_asn1_sequence_free( mbedtls_asn1_sequence *seq )
233+
{
234+
while( seq != NULL )
235+
{
236+
mbedtls_asn1_sequence *next = seq->next;
237+
mbedtls_platform_zeroize( seq, sizeof( *seq ) );
238+
mbedtls_free( seq );
239+
seq = next;
240+
}
241+
}
233242

234243
/*
235244
* Parses and splits an ASN.1 "SEQUENCE OF <tag>"

0 commit comments

Comments
 (0)