Duplicate mbedtls_asn1_find_named_data in asn1write.c to avoid dep.
This commit duplicates the public function mbedtls_asn1_find_named_data() defined in library/asn1parse.c within library/asn1write.c in order to avoid a dependency of the ASN.1 writing module on the ASN.1 parsing module. The duplication is unproblematic from a semantic and an efficiency perspective becasue it is just a short list traversal that doesn't actually do any ASN.1 parsing.
This commit is contained in:
parent
1ea604d3ee
commit
44da18a294
1 changed files with 24 additions and 2 deletions
|
@ -328,14 +328,36 @@ int mbedtls_asn1_write_octet_string( unsigned char **p, unsigned char *start,
|
||||||
return( (int) len );
|
return( (int) len );
|
||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( mbedtls_asn1_named_data **head,
|
|
||||||
|
/* This is a copy of the ASN.1 parsing function mbedtls_asn1_find_named_data(),
|
||||||
|
* which is replicated to avoid a dependency ASN1_WRITE_C on ASN1_PARSE_C. */
|
||||||
|
static mbedtls_asn1_named_data *asn1_find_named_data(
|
||||||
|
mbedtls_asn1_named_data *list,
|
||||||
|
const char *oid, size_t len )
|
||||||
|
{
|
||||||
|
while( list != NULL )
|
||||||
|
{
|
||||||
|
if( list->oid.len == len &&
|
||||||
|
memcmp( list->oid.p, oid, len ) == 0 )
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
list = list->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return( list );
|
||||||
|
}
|
||||||
|
|
||||||
|
mbedtls_asn1_named_data *mbedtls_asn1_store_named_data(
|
||||||
|
mbedtls_asn1_named_data **head,
|
||||||
const char *oid, size_t oid_len,
|
const char *oid, size_t oid_len,
|
||||||
const unsigned char *val,
|
const unsigned char *val,
|
||||||
size_t val_len )
|
size_t val_len )
|
||||||
{
|
{
|
||||||
mbedtls_asn1_named_data *cur;
|
mbedtls_asn1_named_data *cur;
|
||||||
|
|
||||||
if( ( cur = mbedtls_asn1_find_named_data( *head, oid, oid_len ) ) == NULL )
|
if( ( cur = asn1_find_named_data( *head, oid, oid_len ) ) == NULL )
|
||||||
{
|
{
|
||||||
// Add new entry if not present yet based on OID
|
// Add new entry if not present yet based on OID
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue