@@ -316,6 +316,58 @@ int mbedtls_asn1_get_sequence_of( unsigned char **p,
316
316
mbedtls_asn1_sequence * cur ,
317
317
int tag );
318
318
319
+ /**
320
+ * \brief Traverse an ASN.1 SEQUENCE container and
321
+ * call a callback for each entry.
322
+ *
323
+ * \warning This function is still experimental and may change
324
+ * at any time.
325
+ *
326
+ * \param p The address of the pointer to the beginning of
327
+ * the ASN.1 SEQUENCE header. This is updated to
328
+ * point to the end of the ASN.1 SEQUENCE container
329
+ * on a successful invocation.
330
+ * \param end The end of the ASN.1 SEQUENCE container.
331
+ * \param tag_must_mask A mask to be applied to the ASN.1 tags found within
332
+ * the SEQUENCE before comparing to \p tag_must_value.
333
+ * \param tag_must_val The required value of each ASN.1 tag found in the
334
+ * SEQUENCE, after masking with \p tag_must_mask.
335
+ * Mismatching tags lead to an error.
336
+ * For example, a value of \c 0 for both \p tag_must_mask
337
+ * and \p tag_must_val means that every tag is allowed,
338
+ * while a value of \c 0xFF for \p tag_must_mask means
339
+ * that \p tag_must_val is the only allowed tag.
340
+ * \param tag_may_mask A mask to be applied to the ASN.1 tags found within
341
+ * the SEQUENCE before comparing to \p tag_may_value.
342
+ * \param tag_may_val The desired value of each ASN.1 tag found in the
343
+ * SEQUENCE, after masking with \p tag_may_mask.
344
+ * Mismatching tags will be silently ignored.
345
+ * For example, a value of \c 0 for \p tag_may_mask and
346
+ * \p tag_may_val means that any tag will be considered,
347
+ * while a value of \c 0xFF for \p tag_may_mask means
348
+ * that all tags with value different from \p tag_may_val
349
+ * will be ignored.
350
+ * \param cb The callback to trigger for each component
351
+ * in the ASN.1 SEQUENCE. If the callback returns
352
+ * a non-zero value, the function stops immediately,
353
+ * forwarding the callback's return value.
354
+ * \param ctx The context to be passed to the callback \p cb.
355
+ *
356
+ * \return \c 0 if successful the entire ASN.1 SEQUENCE
357
+ * was traversed without parsing or callback errors.
358
+ * \return A negative ASN.1 error code on a parsing failure.
359
+ * \return A non-zero error code forwarded from the callback
360
+ * \p cb in case the latter returns a non-zero value.
361
+ */
362
+ int mbedtls_asn1_traverse_sequence_of (
363
+ unsigned char * * p ,
364
+ const unsigned char * end ,
365
+ uint8_t tag_must_mask , uint8_t tag_must_val ,
366
+ uint8_t tag_may_mask , uint8_t tag_may_val ,
367
+ int (* cb )( void * ctx , int tag ,
368
+ unsigned char * start , size_t len ),
369
+ void * ctx );
370
+
319
371
#if defined(MBEDTLS_BIGNUM_C )
320
372
/**
321
373
* \brief Retrieve a MPI value from an integer ASN.1 tag.
0 commit comments