@@ -332,59 +332,56 @@ void mbedtls_asn1_sequence_free( mbedtls_asn1_sequence *seq )
332
332
}
333
333
}
334
334
335
- /*
336
- * Parses and splits an ASN.1 "SEQUENCE OF <tag>"
337
- */
338
- int mbedtls_asn1_get_sequence_of ( unsigned char * * p ,
339
- const unsigned char * end ,
340
- mbedtls_asn1_sequence * cur ,
341
- int tag )
335
+ typedef struct
342
336
{
343
- int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED ;
344
- size_t len ;
345
- mbedtls_asn1_buf * buf ;
346
-
347
- /* Get main sequence tag */
348
- if ( ( ret = mbedtls_asn1_get_tag ( p , end , & len ,
349
- MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
350
- return ( ret );
351
-
352
- if ( * p + len != end )
353
- return ( MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
337
+ int tag ;
338
+ mbedtls_asn1_sequence * cur ;
339
+ } asn1_get_sequence_of_cb_ctx_t ;
340
+
341
+ static int asn1_get_sequence_of_cb ( void * ctx ,
342
+ int tag ,
343
+ unsigned char * start ,
344
+ size_t len )
345
+ {
346
+ asn1_get_sequence_of_cb_ctx_t * cb_ctx =
347
+ (asn1_get_sequence_of_cb_ctx_t * ) ctx ;
348
+ mbedtls_asn1_sequence * cur =
349
+ cb_ctx -> cur ;
354
350
355
- while ( * p < end )
351
+ if ( cur -> buf . p != NULL )
356
352
{
357
- buf = & ( cur -> buf );
358
- buf -> tag = * * p ;
353
+ cur -> next =
354
+ mbedtls_calloc ( 1 , sizeof ( mbedtls_asn1_sequence ) ) ;
359
355
360
- if ( ( ret = mbedtls_asn1_get_tag ( p , end , & buf -> len , tag ) ) != 0 )
361
- return ( ret );
362
-
363
- buf -> p = * p ;
364
- * p += buf -> len ;
365
-
366
- /* Allocate and assign next pointer */
367
- if ( * p < end )
368
- {
369
- cur -> next = (mbedtls_asn1_sequence * )mbedtls_calloc ( 1 ,
370
- sizeof ( mbedtls_asn1_sequence ) );
371
-
372
- if ( cur -> next == NULL )
373
- return ( MBEDTLS_ERR_ASN1_ALLOC_FAILED );
356
+ if ( cur -> next == NULL )
357
+ return ( MBEDTLS_ERR_ASN1_ALLOC_FAILED );
374
358
375
- cur = cur -> next ;
376
- }
359
+ cur = cur -> next ;
377
360
}
378
361
379
- /* Set final sequence entry's next pointer to NULL */
380
- cur -> next = NULL ;
381
-
382
- if ( * p != end )
383
- return ( MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
362
+ cur -> buf .p = start ;
363
+ cur -> buf .len = len ;
364
+ cur -> buf .tag = tag ;
384
365
366
+ cb_ctx -> cur = cur ;
385
367
return ( 0 );
386
368
}
387
369
370
+ /*
371
+ * Parses and splits an ASN.1 "SEQUENCE OF <tag>"
372
+ */
373
+ int mbedtls_asn1_get_sequence_of ( unsigned char * * p ,
374
+ const unsigned char * end ,
375
+ mbedtls_asn1_sequence * cur ,
376
+ int tag )
377
+ {
378
+ asn1_get_sequence_of_cb_ctx_t cb_ctx = { tag , cur };
379
+ memset ( cur , 0 , sizeof ( mbedtls_asn1_sequence ) );
380
+ return ( mbedtls_asn1_traverse_sequence_of (
381
+ p , end , 0xFF , tag , 0 , 0 ,
382
+ asn1_get_sequence_of_cb , & cb_ctx ) );
383
+ }
384
+
388
385
int mbedtls_asn1_get_alg ( unsigned char * * p ,
389
386
const unsigned char * end ,
390
387
mbedtls_asn1_buf * alg , mbedtls_asn1_buf * params )
0 commit comments