From: Demi Marie Obenour Date: Thu, 19 Jan 2023 14:46:55 +0000 (-0500) Subject: refactor(auth): remove code duplication X-Git-Tag: baikal/aarch64/sdk5.10~1^2~186^2~1 X-Git-Url: https://git.baikalelectronics.ru/?a=commitdiff_plain;h=6a7104a324ce67c5585c9a75ff9e48fa15408fa5;p=arm-tf.git refactor(auth): remove code duplication The unique IDs are handled identically, so just use a for loop to get both of them. Change-Id: I44baaa4747ca7f314d364a79dfcbce97315f5a92 Signed-off-by: Demi Marie Obenour --- diff --git a/drivers/auth/mbedtls/mbedtls_x509_parser.c b/drivers/auth/mbedtls/mbedtls_x509_parser.c index bbabd9b99..41024aa70 100644 --- a/drivers/auth/mbedtls/mbedtls_x509_parser.c +++ b/drivers/auth/mbedtls/mbedtls_x509_parser.c @@ -288,30 +288,24 @@ static int cert_parse(void *img, unsigned int img_len) /* * issuerUniqueID [1] IMPLICIT UniqueIdentifier OPTIONAL, - */ - ret = mbedtls_asn1_get_tag(&p, end, &len, - MBEDTLS_ASN1_CONTEXT_SPECIFIC | - MBEDTLS_ASN1_CONSTRUCTED | 1); - if (ret != 0) { - if (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) { - return IMG_PARSER_ERR_FORMAT; - } - } else { - p += len; - } - - /* * subjectUniqueID [2] IMPLICIT UniqueIdentifier OPTIONAL, + * -- technically these contain BIT STRINGs but that is not worth + * -- validating */ - ret = mbedtls_asn1_get_tag(&p, end, &len, - MBEDTLS_ASN1_CONTEXT_SPECIFIC | - MBEDTLS_ASN1_CONSTRUCTED | 2); - if (ret != 0) { + for (int i = 1; i < 3; i++) { + ret = mbedtls_asn1_get_tag(&p, end, &len, + MBEDTLS_ASN1_CONTEXT_SPECIFIC | + MBEDTLS_ASN1_CONSTRUCTED | i); + /* + * Unique IDs are obsolete, so MBEDTLS_ERR_ASN1_UNEXPECTED_TAG + * is the common case. + */ if (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) { - return IMG_PARSER_ERR_FORMAT; + if (ret != 0) { + return IMG_PARSER_ERR_FORMAT; + } + p += len; } - } else { - p += len; } /*