]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
removed duplicate code.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Wed, 2 Nov 2011 09:56:03 +0000 (10:56 +0100)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Wed, 2 Nov 2011 09:56:03 +0000 (10:56 +0100)
lib/gnutls_str.c
lib/gnutls_str.h
lib/openpgp/output.c
lib/x509/output.c

index c7c8e9db2b0c769c2dc1a55835b44b57b5ca687e..9e8ed610d16f02d0145efb9476c63ddb0755fff1 100644 (file)
@@ -730,3 +730,41 @@ _gnutls_buffer_pop_data_prefix (gnutls_buffer_st * buf, void *data,
 
   return 0;
 }
+
+void _gnutls_buffer_hexprint (gnutls_buffer_st * str, const char *data, size_t len)
+{
+  size_t j;
+
+  if (len == 0)
+    _gnutls_buffer_append_str (str, "00");
+  else
+    {
+      for (j = 0; j < len; j++)
+        _gnutls_buffer_append_printf (str, "%.2x", (unsigned char) data[j]);
+    }
+}
+
+void
+_gnutls_buffer_hexdump (gnutls_buffer_st * str, const char *data, size_t len,
+         const char *spc)
+{
+  size_t j;
+
+  if (spc)
+    _gnutls_buffer_append_str (str, spc);
+  for (j = 0; j < len; j++)
+    {
+      if (((j + 1) % 16) == 0)
+        {
+          _gnutls_buffer_append_printf (str, "%.2x\n", (unsigned char) data[j]);
+          if (spc && j != (len - 1))
+            _gnutls_buffer_append_str (str, spc);
+        }
+      else if (j == (len - 1))
+        _gnutls_buffer_append_printf (str, "%.2x", (unsigned char) data[j]);
+      else
+        _gnutls_buffer_append_printf (str, "%.2x:", (unsigned char) data[j]);
+    }
+  if ((j % 16) != 0)
+    _gnutls_buffer_append_str (str, "\n");
+}
index 3b6562e4c4dc02824678b086e6a1aec88689fe09..3d1de007ff776515763a066b5a7a8ec744e10d9b 100644 (file)
@@ -92,6 +92,10 @@ int _gnutls_buffer_append_printf (gnutls_buffer_st * dest, const char *fmt,
                                   ...)
   __attribute__ ((format (printf, 2, 3)));
 
+void _gnutls_buffer_hexprint (gnutls_buffer_st * str, const char *data, size_t len);
+void _gnutls_buffer_hexdump (gnutls_buffer_st * str, const char *data, size_t len,
+         const char *spc);
+
 char *_gnutls_bin2hex (const void *old, size_t oldlen, char *buffer,
                        size_t buffer_size, const char *separator);
 int _gnutls_hex2bin (const opaque * hex_data, int hex_size, opaque * bin_data,
@@ -99,6 +103,7 @@ int _gnutls_hex2bin (const opaque * hex_data, int hex_size, opaque * bin_data,
 
 int _gnutls_hostname_compare (const char *certname, size_t certnamesize,
                               const char *hostname, int level);
+
 #define MAX_CN 256
 #define MAX_DN 1024
 
index d3a9405a898862bab9be479ec6efc054301d3999..2b5f12d59281f74e14769ae7944423aabd8bcdaf 100644 (file)
 #define addf _gnutls_buffer_append_printf
 #define adds _gnutls_buffer_append_str
 
-static void
-hexdump (gnutls_buffer_st * str, const char *data, size_t len,
-         const char *spc)
-{
-  size_t j;
-
-  if (spc)
-    adds (str, spc);
-  for (j = 0; j < len; j++)
-    {
-      if (((j + 1) % 16) == 0)
-        {
-          addf (str, "%.2x\n", (unsigned char) data[j]);
-          if (spc && j != (len - 1))
-            adds (str, spc);
-        }
-      else if (j == (len - 1))
-        addf (str, "%.2x", (unsigned char) data[j]);
-      else
-        addf (str, "%.2x:", (unsigned char) data[j]);
-    }
-  if ((j % 16) != 0)
-    adds (str, "\n");
-}
-
-static void
-hexprint (gnutls_buffer_st * str, const char *data, size_t len)
-{
-  size_t j;
-
-  if (len == 0)
-    adds (str, "00");
-  else
-    {
-      for (j = 0; j < len; j++)
-        addf (str, "%.2x", (unsigned char) data[j]);
-    }
-}
-
 static void
 print_key_usage (gnutls_buffer_st * str, gnutls_openpgp_crt_t cert,
                  unsigned int idx)
@@ -124,7 +85,7 @@ print_key_id (gnutls_buffer_st * str, gnutls_openpgp_crt_t cert, int idx)
   else
     {
       adds (str, _("\tID (hex): "));
-      hexprint (str, id, sizeof (id));
+      _gnutls_buffer_hexprint (str, id, sizeof (id));
       addf (str, "\n");
     }
 }
@@ -145,7 +106,7 @@ print_key_fingerprint (gnutls_buffer_st * str, gnutls_openpgp_crt_t cert)
   else
     {
       adds (str, _("\tFingerprint (hex): "));
-      hexprint (str, fpr, fpr_size);
+      _gnutls_buffer_hexprint (str, fpr, fpr_size);
       addf (str, "\n");
     }
 }
@@ -258,9 +219,9 @@ print_key_info (gnutls_buffer_st * str, gnutls_openpgp_crt_t cert, int idx)
             else
               {
                 addf (str, _("\t\tModulus (bits %d):\n"), bits);
-                hexdump (str, m.data, m.size, "\t\t\t");
+                _gnutls_buffer_hexdump (str, m.data, m.size, "\t\t\t");
                 adds (str, _("\t\tExponent:\n"));
-                hexdump (str, e.data, e.size, "\t\t\t");
+                _gnutls_buffer_hexdump (str, e.data, e.size, "\t\t\t");
 
                 gnutls_free (m.data);
                 gnutls_free (e.data);
@@ -285,13 +246,13 @@ print_key_info (gnutls_buffer_st * str, gnutls_openpgp_crt_t cert, int idx)
             else
               {
                 addf (str, _("\t\tPublic key (bits %d):\n"), bits);
-                hexdump (str, y.data, y.size, "\t\t\t");
+                _gnutls_buffer_hexdump (str, y.data, y.size, "\t\t\t");
                 adds (str, _("\t\tP:\n"));
-                hexdump (str, p.data, p.size, "\t\t\t");
+                _gnutls_buffer_hexdump (str, p.data, p.size, "\t\t\t");
                 adds (str, _("\t\tQ:\n"));
-                hexdump (str, q.data, q.size, "\t\t\t");
+                _gnutls_buffer_hexdump (str, q.data, q.size, "\t\t\t");
                 adds (str, _("\t\tG:\n"));
-                hexdump (str, g.data, g.size, "\t\t\t");
+                _gnutls_buffer_hexdump (str, g.data, g.size, "\t\t\t");
 
                 gnutls_free (p.data);
                 gnutls_free (q.data);
@@ -440,7 +401,7 @@ print_oneline (gnutls_buffer_st * str, gnutls_openpgp_crt_t cert)
     else
       {
         adds (str, _("fingerprint: "));
-        hexprint (str, fpr, fpr_size);
+        _gnutls_buffer_hexprint (str, fpr, fpr_size);
         addf (str, ", ");
       }
   }
index 6bf02ceb68506e04b06c97fe0486f98c23d2132f..0f326a6b8df3e73cc69f65f8fe589b35280090c0 100644 (file)
 
 #define ERROR_STR (char*) "(error)"
 
-static void
-hexdump (gnutls_buffer_st * str, const char *data, size_t len,
-         const char *spc)
-{
-  size_t j;
-
-  if (spc)
-    adds (str, spc);
-  for (j = 0; j < len; j++)
-    {
-      if (((j + 1) % 16) == 0)
-        {
-          addf (str, "%.2x\n", (unsigned char) data[j]);
-          if (spc && j != (len - 1))
-            adds (str, spc);
-        }
-      else if (j == (len - 1))
-        addf (str, "%.2x", (unsigned char) data[j]);
-      else
-        addf (str, "%.2x:", (unsigned char) data[j]);
-    }
-  if ((j % 16) != 0)
-    adds (str, "\n");
-}
-
-static void
-hexprint (gnutls_buffer_st * str, const char *data, size_t len)
-{
-  size_t j;
-
-  if (len == 0)
-    adds (str, "00");
-  else
-    {
-      for (j = 0; j < len; j++)
-        addf (str, "%.2x", (unsigned char) data[j]);
-    }
-}
-
-
 static void
 asciiprint (gnutls_buffer_st * str, const char *data, size_t len)
 {
@@ -165,7 +125,7 @@ print_proxy (gnutls_buffer_st * str, gnutls_x509_crt_t cert)
       adds (str, _("\t\t\tPolicy:\n\t\t\t\tASCII: "));
       asciiprint (str, policy, npolicy);
       adds (str, _("\n\t\t\t\tHexdump: "));
-      hexprint (str, policy, npolicy);
+      _gnutls_buffer_hexprint (str, policy, npolicy);
       adds (str, "\n");
     }
 }
@@ -258,7 +218,7 @@ print_ski (gnutls_buffer_st * str, gnutls_x509_crt_t cert)
     }
 
   adds (str, "\t\t\t");
-  hexprint (str, buffer, size);
+  _gnutls_buffer_hexprint (str, buffer, size);
   adds (str, "\n");
 
   gnutls_free (buffer);
@@ -327,7 +287,7 @@ print_aki (gnutls_buffer_st * str, int type, cert_type_t cert)
     }
 
   adds (str, "\t\t\t");
-  hexprint (str, buffer, size);
+  _gnutls_buffer_hexprint (str, buffer, size);
   adds (str, "\n");
 
   gnutls_free (buffer);
@@ -744,7 +704,7 @@ print_altname (gnutls_buffer_st * str, const char *prefix, int altname_type,
                 addf (str, _("%s\t\t\totherName OID: %.*s\n"), prefix,
                       (int) oidsize, oid);
                 addf (str, _("%s\t\t\totherName DER: "), prefix);
-                hexprint (str, buffer, size);
+                _gnutls_buffer_hexprint (str, buffer, size);
                 addf (str, _("\n%s\t\t\totherName ASCII: "), prefix);
                 asciiprint (str, buffer, size);
                 addf (str, "\n");
@@ -803,7 +763,7 @@ print_unique_ids (gnutls_buffer_st * str, const gnutls_x509_crt_t cert)
   if (result >= 0)
     {
       addf (str, ("\t\tIssuer Unique ID:\n"));
-      hexdump (str, buf, buf_size, "\t\t\t");
+      _gnutls_buffer_hexdump (str, buf, buf_size, "\t\t\t");
       if (buf_size == 16)
         {                       /* this could be a GUID */
           guiddump (str, buf, buf_size, "\t\t\t");
@@ -815,7 +775,7 @@ print_unique_ids (gnutls_buffer_st * str, const gnutls_x509_crt_t cert)
   if (result >= 0)
     {
       addf (str, ("\t\tSubject Unique ID:\n"));
-      hexdump (str, buf, buf_size, "\t\t\t");
+      _gnutls_buffer_hexdump (str, buf, buf_size, "\t\t\t");
       if (buf_size == 16)
         {                       /* this could be a GUID */
           guiddump (str, buf, buf_size, "\t\t\t");
@@ -1081,7 +1041,7 @@ print_extensions (gnutls_buffer_st * str, const char *prefix, int type,
           addf (str, "\n");
 
           addf (str, _("%s\t\t\tHexdump: "), prefix);
-          hexprint (str, buffer, extlen);
+          _gnutls_buffer_hexprint (str, buffer, extlen);
           adds (str, "\n");
 
           gnutls_free (buffer);
@@ -1113,7 +1073,7 @@ print_cert (gnutls_buffer_st * str, gnutls_x509_crt_t cert, int notsigned)
     else
       {
         adds (str, _("\tSerial Number (hex): "));
-        hexprint (str, serial, serial_size);
+        _gnutls_buffer_hexprint (str, serial, serial_size);
         adds (str, "\n");
       }
   }
@@ -1258,9 +1218,9 @@ print_cert (gnutls_buffer_st * str, gnutls_x509_crt_t cert, int notsigned)
               else
                 {
                   addf (str, _("\t\tModulus (bits %d):\n"), bits);
-                  hexdump (str, m.data, m.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, m.data, m.size, "\t\t\t");
                   addf (str, _("\t\tExponent (bits %d):\n"), e.size * 8);
-                  hexdump (str, e.data, e.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, e.data, e.size, "\t\t\t");
 
                   gnutls_free (m.data);
                   gnutls_free (e.data);
@@ -1282,9 +1242,9 @@ print_cert (gnutls_buffer_st * str, gnutls_x509_crt_t cert, int notsigned)
                 {
                   addf (str, _("\t\tCurve:\t%s\n"), gnutls_ecc_curve_get_name(curve));
                   addf (str, _("\t\tX:\n"));
-                  hexdump (str, x.data, x.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, x.data, x.size, "\t\t\t");
                   adds (str, _("\t\tY:\n"));
-                  hexdump (str, y.data, y.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, y.data, y.size, "\t\t\t");
 
                   gnutls_free (x.data);
                   gnutls_free (y.data);
@@ -1303,13 +1263,13 @@ print_cert (gnutls_buffer_st * str, gnutls_x509_crt_t cert, int notsigned)
               else
                 {
                   addf (str, _("\t\tPublic key (bits %d):\n"), bits);
-                  hexdump (str, y.data, y.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, y.data, y.size, "\t\t\t");
                   adds (str, _("\t\tP:\n"));
-                  hexdump (str, p.data, p.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, p.data, p.size, "\t\t\t");
                   adds (str, _("\t\tQ:\n"));
-                  hexdump (str, q.data, q.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, q.data, q.size, "\t\t\t");
                   adds (str, _("\t\tG:\n"));
-                  hexdump (str, g.data, g.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, g.data, g.size, "\t\t\t");
 
                   gnutls_free (p.data);
                   gnutls_free (q.data);
@@ -1388,7 +1348,7 @@ print_cert (gnutls_buffer_st * str, gnutls_x509_crt_t cert, int notsigned)
         }
 
       adds (str, _("\tSignature:\n"));
-      hexdump (str, buffer, size, "\t\t");
+      _gnutls_buffer_hexdump (str, buffer, size, "\t\t");
 
       gnutls_free (buffer);
     }
@@ -1413,7 +1373,7 @@ print_fingerprint (gnutls_buffer_st * str, gnutls_x509_crt_t cert,
     adds (str, _("\tMD5 fingerprint:\n\t\t"));
   else
     adds (str, _("\tSHA-1 fingerprint:\n\t\t"));
-  hexprint (str, buffer, size);
+  _gnutls_buffer_hexprint (str, buffer, size);
   adds (str, "\n");
 }
 
@@ -1432,7 +1392,7 @@ print_keyid (gnutls_buffer_st * str, gnutls_x509_crt_t cert)
     }
 
   adds (str, _("\tPublic Key Id:\n\t\t"));
-  hexprint (str, buffer, size);
+  _gnutls_buffer_hexprint (str, buffer, size);
   adds (str, "\n");
 }
 
@@ -1604,7 +1564,7 @@ print_oneline (gnutls_buffer_st * str, gnutls_x509_crt_t cert)
     else
       {
         addf (str, "SHA-1 fingerprint `");
-        hexprint (str, buffer, size);
+        _gnutls_buffer_hexprint (str, buffer, size);
         adds (str, "'");
       }
   }
@@ -1804,7 +1764,7 @@ print_crl (gnutls_buffer_st * str, gnutls_x509_crl_t crl, int notsigned)
                 addf (str, "error: get_number: %s\n", gnutls_strerror (err));
               else
                 {
-                  hexprint (str, nr, nr_size);
+                  _gnutls_buffer_hexprint (str, nr, nr_size);
                   addf (str, "\n");
                 }
 
@@ -1868,7 +1828,7 @@ print_crl (gnutls_buffer_st * str, gnutls_x509_crl_t crl, int notsigned)
               adds (str, "\n");
 
               adds (str, _("\t\t\tHexdump: "));
-              hexprint (str, buffer, extlen);
+              _gnutls_buffer_hexprint (str, buffer, extlen);
               adds (str, "\n");
 
               gnutls_free (buffer);
@@ -1905,7 +1865,7 @@ print_crl (gnutls_buffer_st * str, gnutls_x509_crl_t crl, int notsigned)
             struct tm t;
 
             adds (str, _("\t\tSerial Number (hex): "));
-            hexprint (str, serial, serial_size);
+            _gnutls_buffer_hexprint (str, serial, serial_size);
             adds (str, "\n");
 
             if (gmtime_r (&tim, &t) == NULL)
@@ -1966,7 +1926,7 @@ print_crl (gnutls_buffer_st * str, gnutls_x509_crl_t crl, int notsigned)
         }
 
       adds (str, _("\tSignature:\n"));
-      hexdump (str, buffer, size, "\t\t");
+      _gnutls_buffer_hexdump (str, buffer, size, "\t\t");
 
       gnutls_free (buffer);
     }
@@ -2074,9 +2034,9 @@ print_crq (gnutls_buffer_st * str, gnutls_x509_crq_t cert)
               else
                 {
                   addf (str, _("\t\tModulus (bits %d):\n"), bits);
-                  hexdump (str, m.data, m.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, m.data, m.size, "\t\t\t");
                   adds (str, _("\t\tExponent:\n"));
-                  hexdump (str, e.data, e.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, e.data, e.size, "\t\t\t");
 
                   gnutls_free (m.data);
                   gnutls_free (e.data);
@@ -2096,13 +2056,13 @@ print_crq (gnutls_buffer_st * str, gnutls_x509_crq_t cert)
               else
                 {
                   addf (str, _("\t\tPublic key (bits %d):\n"), bits);
-                  hexdump (str, y.data, y.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, y.data, y.size, "\t\t\t");
                   addf (str, _("\t\tP:\n"));
-                  hexdump (str, p.data, p.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, p.data, p.size, "\t\t\t");
                   addf (str, _("\t\tQ:\n"));
-                  hexdump (str, q.data, q.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, q.data, q.size, "\t\t\t");
                   addf (str, _("\t\tG:\n"));
-                  hexdump (str, g.data, g.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, g.data, g.size, "\t\t\t");
 
                   gnutls_free (p.data);
                   gnutls_free (q.data);
@@ -2238,7 +2198,7 @@ print_crq (gnutls_buffer_st * str, gnutls_x509_crq_t cert)
             adds (str, "\n");
 
             adds (str, _("\t\t\tHexdump: "));
-            hexprint (str, buffer, extlen);
+            _gnutls_buffer_hexprint (str, buffer, extlen);
             adds (str, "\n");
 
             gnutls_free (buffer);
@@ -2278,7 +2238,7 @@ print_crq_other (gnutls_buffer_st * str, gnutls_x509_crq_t crq)
     }
 
   adds (str, _("\tPublic Key Id:\n\t\t"));
-  hexprint (str, buffer, size);
+  _gnutls_buffer_hexprint (str, buffer, size);
   adds (str, "\n");
 
   gnutls_free (buffer);