]> git.baikalelectronics.ru Git - arm-tf.git/commitdiff
refactor(auth): remove code duplication
authorDemi Marie Obenour <demiobenour@gmail.com>
Thu, 19 Jan 2023 14:46:55 +0000 (09:46 -0500)
committerDemi Marie Obenour <demiobenour@gmail.com>
Mon, 27 Feb 2023 19:08:28 +0000 (14:08 -0500)
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 <demiobenour@gmail.com>
drivers/auth/mbedtls/mbedtls_x509_parser.c

index bbabd9b990fdce73c2ff036c381d07f8a14a823a..41024aa70d861d7e5416998814c995456a8f45ca 100644 (file)
@@ -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;
        }
 
        /*