changes requested by @hanno-arm

- renamed `mbedtls_asn1_write_any_string` to `mbedtls_asn1_write_tagged_string`
 - renamed `x509_at_oid_from_name` to `x509_attr_descr_from_name`
This commit is contained in:
thomas-dee 2018-09-19 09:10:37 +02:00
parent 020c823f62
commit eba6c9bb50
3 changed files with 12 additions and 12 deletions

View File

@ -165,7 +165,7 @@ int mbedtls_asn1_write_int( unsigned char **p, unsigned char *start, int val );
* *
* \return the length written or a negative error code * \return the length written or a negative error code
*/ */
int mbedtls_asn1_write_any_string( unsigned char **p, unsigned char *start, int mbedtls_asn1_write_tagged_string( unsigned char **p, unsigned char *start,
int tag, const char *text, size_t text_len ); int tag, const char *text, size_t text_len );
/** /**
* \brief Write a printable string tag (MBEDTLS_ASN1_PRINTABLE_STRING) and * \brief Write a printable string tag (MBEDTLS_ASN1_PRINTABLE_STRING) and

View File

@ -253,7 +253,7 @@ int mbedtls_asn1_write_int( unsigned char **p, unsigned char *start, int val )
return( (int) len ); return( (int) len );
} }
int mbedtls_asn1_write_any_string( unsigned char **p, unsigned char *start, int tag, int mbedtls_asn1_write_tagged_string( unsigned char **p, unsigned char *start, int tag,
const char *text, size_t text_len ) const char *text, size_t text_len )
{ {
int ret; int ret;
@ -271,19 +271,19 @@ int mbedtls_asn1_write_any_string( unsigned char **p, unsigned char *start, int
int mbedtls_asn1_write_utf8_string( unsigned char **p, unsigned char *start, int mbedtls_asn1_write_utf8_string( unsigned char **p, unsigned char *start,
const char *text, size_t text_len ) const char *text, size_t text_len )
{ {
return( mbedtls_asn1_write_any_string(p, start, MBEDTLS_ASN1_UTF8_STRING, text, text_len) ); return( mbedtls_asn1_write_tagged_string(p, start, MBEDTLS_ASN1_UTF8_STRING, text, text_len) );
} }
int mbedtls_asn1_write_printable_string( unsigned char **p, unsigned char *start, int mbedtls_asn1_write_printable_string( unsigned char **p, unsigned char *start,
const char *text, size_t text_len ) const char *text, size_t text_len )
{ {
return( mbedtls_asn1_write_any_string(p, start, MBEDTLS_ASN1_PRINTABLE_STRING, text, text_len) ); return( mbedtls_asn1_write_tagged_string(p, start, MBEDTLS_ASN1_PRINTABLE_STRING, text, text_len) );
} }
int mbedtls_asn1_write_ia5_string( unsigned char **p, unsigned char *start, int mbedtls_asn1_write_ia5_string( unsigned char **p, unsigned char *start,
const char *text, size_t text_len ) const char *text, size_t text_len )
{ {
return( mbedtls_asn1_write_any_string(p, start, MBEDTLS_ASN1_IA5_STRING, text, text_len) ); return( mbedtls_asn1_write_tagged_string(p, start, MBEDTLS_ASN1_IA5_STRING, text, text_len) );
} }
int mbedtls_asn1_write_bitstring( unsigned char **p, unsigned char *start, int mbedtls_asn1_write_bitstring( unsigned char **p, unsigned char *start,

View File

@ -42,7 +42,7 @@ typedef struct {
#define ADD_STRLEN( s ) s, sizeof( s ) - 1 #define ADD_STRLEN( s ) s, sizeof( s ) - 1
// note: preset tag types as proposed in rfc3280 and widely used // note: preset tag types as proposed in RFC3280 and widely used
static const x509_attr_descriptor_t x509_attrs[] = static const x509_attr_descriptor_t x509_attrs[] =
{ {
{ ADD_STRLEN( "CN" ), MBEDTLS_OID_AT_CN, MBEDTLS_ASN1_UTF8_STRING }, { ADD_STRLEN( "CN" ), MBEDTLS_OID_AT_CN, MBEDTLS_ASN1_UTF8_STRING },
@ -76,7 +76,7 @@ static const x509_attr_descriptor_t x509_attrs[] =
{ NULL, 0, NULL, MBEDTLS_ASN1_NULL } { NULL, 0, NULL, MBEDTLS_ASN1_NULL }
}; };
static const x509_attr_descriptor_t *x509_at_oid_from_name( const char *name, size_t name_len ) static const x509_attr_descriptor_t *x509_attr_descr_from_name( const char *name, size_t name_len )
{ {
const x509_attr_descriptor_t *cur; const x509_attr_descriptor_t *cur;
@ -97,7 +97,7 @@ int mbedtls_x509_string_to_names( mbedtls_asn1_named_data **head, const char *na
const char *s = name, *c = s; const char *s = name, *c = s;
const char *end = s + strlen( s ); const char *end = s + strlen( s );
const char *oid = NULL; const char *oid = NULL;
const x509_attr_descriptor_t* oid_attr = NULL; const x509_attr_descriptor_t* attr_descr = NULL;
int in_tag = 1; int in_tag = 1;
char data[MBEDTLS_X509_MAX_DN_NAME_SIZE]; char data[MBEDTLS_X509_MAX_DN_NAME_SIZE];
char *d = data; char *d = data;
@ -109,13 +109,13 @@ int mbedtls_x509_string_to_names( mbedtls_asn1_named_data **head, const char *na
{ {
if( in_tag && *c == '=' ) if( in_tag && *c == '=' )
{ {
if( ( oid_attr = x509_at_oid_from_name( s, c - s ) ) == NULL ) if( ( attr_descr = x509_attr_descr_from_name( s, c - s ) ) == NULL )
{ {
ret = MBEDTLS_ERR_X509_UNKNOWN_OID; ret = MBEDTLS_ERR_X509_UNKNOWN_OID;
goto exit; goto exit;
} }
oid = oid_attr->oid; oid = attr_descr->oid;
s = c + 1; s = c + 1;
in_tag = 0; in_tag = 0;
d = data; d = data;
@ -144,7 +144,7 @@ int mbedtls_x509_string_to_names( mbedtls_asn1_named_data **head, const char *na
} }
// set tagType // set tagType
cur->val.tag = oid_attr->tag; cur->val.tag = attr_descr->tag;
while( c < end && *(c + 1) == ' ' ) while( c < end && *(c + 1) == ' ' )
c++; c++;
@ -214,7 +214,7 @@ static int x509_write_name( unsigned char **p, unsigned char *start, mbedtls_asn
size_t name_len = cur_name->val.len; size_t name_len = cur_name->val.len;
// Write correct string tag and value // Write correct string tag and value
MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_any_string( p, start, cur_name->val.tag, MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tagged_string( p, start, cur_name->val.tag,
(const char *) name, (const char *) name,
name_len ) ); name_len ) );
// Write OID // Write OID