Reduce code-size of mbedtls_asn1_get_sequence_of()
Reduce nesting of branches and remove unnecessary check at the end
of the routine.
diff --git a/library/asn1parse.c b/library/asn1parse.c
index b844fc6..dffc67f 100644
--- a/library/asn1parse.c
+++ b/library/asn1parse.c
@@ -251,7 +251,7 @@
if( *p + len != end )
return( MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
- while( *p < end )
+ while( 1 )
{
buf = &(cur->buf);
buf->tag = **p;
@@ -262,25 +262,20 @@
buf->p = *p;
*p += buf->len;
- /* Allocate and assign next pointer */
- if( *p < end )
+ if( *p == end )
{
- cur->next = (mbedtls_asn1_sequence*)mbedtls_calloc( 1,
- sizeof( mbedtls_asn1_sequence ) );
-
- if( cur->next == NULL )
- return( MBEDTLS_ERR_ASN1_ALLOC_FAILED );
-
- cur = cur->next;
+ cur->next = NULL;
+ break;
}
+
+ cur->next = (mbedtls_asn1_sequence*)mbedtls_calloc( 1,
+ sizeof( mbedtls_asn1_sequence ) );
+ if( cur->next == NULL )
+ return( MBEDTLS_ERR_ASN1_ALLOC_FAILED );
+
+ cur = cur->next;
}
- /* Set final sequence entry's next pointer to NULL */
- cur->next = NULL;
-
- if( *p != end )
- return( MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
-
return( 0 );
}