mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-01-12 00:35:38 +00:00
Introduce a helper macro to check for ASN.1 string tags
This commit introduces a macro `MBEDTLS_ASN1_IS_STRING_TAG` that can be used to check if an ASN.1 tag is among the list of string tags: - MBEDTLS_ASN1_BMP_STRING - MBEDTLS_ASN1_UTF8_STRING - MBEDTLS_ASN1_T61_STRING - MBEDTLS_ASN1_IA5_STRING - MBEDTLS_ASN1_UNIVERSAL_STRING - MBEDTLS_ASN1_PRINTABLE_STRING - MBEDTLS_ASN1_BIT_STRING
This commit is contained in:
parent
ace04a6dc3
commit
b40dc58a83
|
@ -89,6 +89,18 @@
|
||||||
#define MBEDTLS_ASN1_CONSTRUCTED 0x20
|
#define MBEDTLS_ASN1_CONSTRUCTED 0x20
|
||||||
#define MBEDTLS_ASN1_CONTEXT_SPECIFIC 0x80
|
#define MBEDTLS_ASN1_CONTEXT_SPECIFIC 0x80
|
||||||
|
|
||||||
|
/* Slightly smaller way to check if tag is a string tag
|
||||||
|
* compared to canonical implementation. */
|
||||||
|
#define MBEDTLS_ASN1_IS_STRING_TAG( tag ) \
|
||||||
|
( ( tag ) < 32u && ( \
|
||||||
|
( ( 1u << ( tag ) ) & ( ( 1u << MBEDTLS_ASN1_BMP_STRING ) | \
|
||||||
|
( 1u << MBEDTLS_ASN1_UTF8_STRING ) | \
|
||||||
|
( 1u << MBEDTLS_ASN1_T61_STRING ) | \
|
||||||
|
( 1u << MBEDTLS_ASN1_IA5_STRING ) | \
|
||||||
|
( 1u << MBEDTLS_ASN1_UNIVERSAL_STRING ) | \
|
||||||
|
( 1u << MBEDTLS_ASN1_PRINTABLE_STRING ) | \
|
||||||
|
( 1u << MBEDTLS_ASN1_BIT_STRING ) ) ) != 0 ) )
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Bit masks for each of the components of an ASN.1 tag as specified in
|
* Bit masks for each of the components of an ASN.1 tag as specified in
|
||||||
* ITU X.690 (08/2015), section 8.1 "General rules for encoding",
|
* ITU X.690 (08/2015), section 8.1 "General rules for encoding",
|
||||||
|
|
|
@ -375,12 +375,11 @@ static int x509_get_attr_type_value( unsigned char **p,
|
||||||
return( MBEDTLS_ERR_X509_INVALID_NAME +
|
return( MBEDTLS_ERR_X509_INVALID_NAME +
|
||||||
MBEDTLS_ERR_ASN1_OUT_OF_DATA );
|
MBEDTLS_ERR_ASN1_OUT_OF_DATA );
|
||||||
|
|
||||||
if( **p != MBEDTLS_ASN1_BMP_STRING && **p != MBEDTLS_ASN1_UTF8_STRING &&
|
if( !MBEDTLS_ASN1_IS_STRING_TAG( **p ) )
|
||||||
**p != MBEDTLS_ASN1_T61_STRING && **p != MBEDTLS_ASN1_PRINTABLE_STRING &&
|
{
|
||||||
**p != MBEDTLS_ASN1_IA5_STRING && **p != MBEDTLS_ASN1_UNIVERSAL_STRING &&
|
|
||||||
**p != MBEDTLS_ASN1_BIT_STRING )
|
|
||||||
return( MBEDTLS_ERR_X509_INVALID_NAME +
|
return( MBEDTLS_ERR_X509_INVALID_NAME +
|
||||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG );
|
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG );
|
||||||
|
}
|
||||||
|
|
||||||
val = &cur->val;
|
val = &cur->val;
|
||||||
val->tag = *(*p)++;
|
val->tag = *(*p)++;
|
||||||
|
|
Loading…
Reference in a new issue