]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
simplified functions.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Sun, 10 Nov 2013 17:42:43 +0000 (18:42 +0100)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sun, 10 Nov 2013 17:42:43 +0000 (18:42 +0100)
lib/x509/common.c
lib/x509/extensions.c

index 53cae80c066fc9b12c4b123b3d5e40aaa3737c0b..8f0ca6b5622c999aabecdb9c80e2c31a64e7158a 100644 (file)
@@ -981,8 +981,8 @@ _gnutls_x509_decode_string(unsigned int etype,
 /* Reads a value from an ASN1 tree, and puts the output
  * in an allocated variable in the given datum.
  *
- * Note that this function always places allocates one plus
- * the required data size (to allow for a null byte).
+ * Note that this function always allocates one plus
+ * the required data size (and places a null byte).
  */
 int
 _gnutls_x509_read_value(ASN1_TYPE c, const char *root,
index 4777931802fbc1b8a7cbd947335e48183867ee14..4748421b68ea8dbc9b1c927c5768dfab2c14a91f 100644 (file)
@@ -38,10 +38,9 @@ get_extension(ASN1_TYPE asn, const char *root,
 {
        int k, result, len;
        char name[ASN1_MAX_NAME_SIZE], name2[ASN1_MAX_NAME_SIZE];
-       char str[1024];
        char str_critical[10];
        int critical = 0;
-       char extnID[128];
+       char extnID[MAX_OID_SIZE];
        gnutls_datum_t value;
        int indx_counter = 0;
 
@@ -54,23 +53,36 @@ get_extension(ASN1_TYPE asn, const char *root,
 
                snprintf(name, sizeof(name), "%s.?%u", root, k);
 
-               len = sizeof(str) - 1;
-               result = asn1_read_value(asn, name, str, &len);
+               _gnutls_str_cpy(name2, sizeof(name2), name);
+               _gnutls_str_cat(name2, sizeof(name2), ".extnID");
 
-               /* move to next
-                */
+               len = sizeof(extnID) - 1;
+               result = asn1_read_value(asn, name2, extnID, &len);
 
                if (result == ASN1_ELEMENT_NOT_FOUND) {
+                       gnutls_assert();
                        break;
+               } else if (result != ASN1_SUCCESS) {
+                       gnutls_assert();
+                       return _gnutls_asn2err(result);
                }
 
-               do {
+               /* Handle Extension 
+                */
+               if (strcmp(extnID, extension_id) == 0
+                   && indx == indx_counter++) {
+                       /* extension was found 
+                        */
 
+                       /* read the critical status.
+                        */
                        _gnutls_str_cpy(name2, sizeof(name2), name);
-                       _gnutls_str_cat(name2, sizeof(name2), ".extnID");
+                       _gnutls_str_cat(name2, sizeof(name2), ".critical");
 
-                       len = sizeof(extnID) - 1;
-                       result = asn1_read_value(asn, name2, extnID, &len);
+                       len = sizeof(str_critical);
+                       result =
+                           asn1_read_value(asn, name2,
+                                           str_critical, &len);
 
                        if (result == ASN1_ELEMENT_NOT_FOUND) {
                                gnutls_assert();
@@ -80,65 +92,32 @@ get_extension(ASN1_TYPE asn, const char *root,
                                return _gnutls_asn2err(result);
                        }
 
-                       /* Handle Extension 
+                       if (str_critical[0] == 'T')
+                               critical = 1;
+                       else
+                               critical = 0;
+
+                       /* read the value.
                         */
-                       if (strcmp(extnID, extension_id) == 0
-                           && indx == indx_counter++) {
-                               /* extension was found 
-                                */
+                       _gnutls_str_cpy(name2, sizeof(name2), name);
+                       _gnutls_str_cat(name2, sizeof(name2),
+                                       ".extnValue");
 
-                               /* read the critical status.
-                                */
-                               _gnutls_str_cpy(name2, sizeof(name2),
-                                               name);
-                               _gnutls_str_cat(name2, sizeof(name2),
-                                               ".critical");
-
-                               len = sizeof(str_critical);
-                               result =
-                                   asn1_read_value(asn, name2,
-                                                   str_critical, &len);
-
-                               if (result == ASN1_ELEMENT_NOT_FOUND) {
-                                       gnutls_assert();
-                                       break;
-                               } else if (result != ASN1_SUCCESS) {
-                                       gnutls_assert();
-                                       return _gnutls_asn2err(result);
-                               }
-
-                               if (str_critical[0] == 'T')
-                                       critical = 1;
-                               else
-                                       critical = 0;
-
-                               /* read the value.
-                                */
-                               _gnutls_str_cpy(name2, sizeof(name2),
-                                               name);
-                               _gnutls_str_cat(name2, sizeof(name2),
-                                               ".extnValue");
-
-                               result =
-                                   _gnutls_x509_read_value(asn, name2,
-                                                           &value);
-                               if (result < 0) {
-                                       gnutls_assert();
-                                       return result;
-                               }
-
-                               ret->data = value.data;
-                               ret->size = value.size;
-
-                               if (_critical)
-                                       *_critical = critical;
-
-                               return 0;
+                       result =
+                           _gnutls_x509_read_value(asn, name2, &value);
+                       if (result < 0) {
+                               gnutls_assert();
+                               return result;
                        }
 
+                       ret->data = value.data;
+                       ret->size = value.size;
+
+                       if (_critical)
+                               *_critical = critical;
 
+                       return 0;
                }
-               while (0);
        }
        while (1);
 
@@ -192,8 +171,7 @@ get_extension_oid(ASN1_TYPE asn, const char *root,
 {
        int k, result, len;
        char name[ASN1_MAX_NAME_SIZE], name2[ASN1_MAX_NAME_SIZE];
-       char str[1024];
-       char extnID[128];
+       char extnID[MAX_OID_SIZE];
        int indx_counter = 0;
 
        k = 0;
@@ -202,53 +180,38 @@ get_extension_oid(ASN1_TYPE asn, const char *root,
 
                snprintf(name, sizeof(name), "%s.?%u", root, k);
 
-               len = sizeof(str) - 1;
-               result = asn1_read_value(asn, name, str, &len);
+               _gnutls_str_cpy(name2, sizeof(name2), name);
+               _gnutls_str_cat(name2, sizeof(name2), ".extnID");
 
-               /* move to next
-                */
+               len = sizeof(extnID) - 1;
+               result = asn1_read_value(asn, name2, extnID, &len);
 
                if (result == ASN1_ELEMENT_NOT_FOUND) {
+                       gnutls_assert();
                        break;
+               } else if (result != ASN1_SUCCESS) {
+                       gnutls_assert();
+                       return _gnutls_asn2err(result);
                }
 
-               do {
-
-                       _gnutls_str_cpy(name2, sizeof(name2), name);
-                       _gnutls_str_cat(name2, sizeof(name2), ".extnID");
-
-                       len = sizeof(extnID) - 1;
-                       result = asn1_read_value(asn, name2, extnID, &len);
+               /* Handle Extension 
+                */
+               if (indx == indx_counter++) {
+                       len = strlen(extnID) + 1;
 
-                       if (result == ASN1_ELEMENT_NOT_FOUND) {
+                       if (*sizeof_oid < (unsigned) len) {
+                               *sizeof_oid = len;
                                gnutls_assert();
-                               break;
-                       } else if (result != ASN1_SUCCESS) {
-                               gnutls_assert();
-                               return _gnutls_asn2err(result);
+                               return GNUTLS_E_SHORT_MEMORY_BUFFER;
                        }
 
-                       /* Handle Extension 
-                        */
-                       if (indx == indx_counter++) {
-                               len = strlen(extnID) + 1;
-
-                               if (*sizeof_oid < (unsigned) len) {
-                                       *sizeof_oid = len;
-                                       gnutls_assert();
-                                       return
-                                           GNUTLS_E_SHORT_MEMORY_BUFFER;
-                               }
-
-                               memcpy(oid, extnID, len);
-                               *sizeof_oid = len - 1;
+                       memcpy(oid, extnID, len);
+                       *sizeof_oid = len - 1;
 
-                               return 0;
-                       }
+                       return 0;
+               }
 
 
-               }
-               while (0);
        }
        while (1);
 
@@ -398,7 +361,7 @@ set_extension(ASN1_TYPE asn, const char *root,
        int result;
        int k, len;
        char name[ASN1_MAX_NAME_SIZE], name2[ASN1_MAX_NAME_SIZE];
-       char extnID[128];
+       char extnID[MAX_OID_SIZE];
 
        /* Find the index of the given extension.
         */