[svn] GnuPG - r4866 - trunk/scd

svn author wk cvs at cvs.gnupg.org
Mon Nov 3 11:54:19 CET 2008


Author: wk
Date: 2008-11-03 11:54:18 +0100 (Mon, 03 Nov 2008)
New Revision: 4866

Modified:
   trunk/scd/ChangeLog
   trunk/scd/app-help.c
   trunk/scd/app-nks.c
   trunk/scd/app-openpgp.c
   trunk/scd/app-p15.c
   trunk/scd/app.c
   trunk/scd/card-p15.c
   trunk/scd/command.c
Log:
Use bin2hex if possible.


Modified: trunk/scd/ChangeLog
===================================================================
--- trunk/scd/ChangeLog	2008-10-29 17:24:27 UTC (rev 4865)
+++ trunk/scd/ChangeLog	2008-11-03 10:54:18 UTC (rev 4866)
@@ -1,3 +1,13 @@
+2008-11-03  Werner Koch  <wk at g10code.com>
+
+	* app.c (app_get_serial_and_stamp): Use bin2hex.
+	* app-help.c (app_help_get_keygrip_string): Ditto.
+	* app-p15.c (send_certinfo, send_keypairinfo, do_getattr): Ditto.
+	* app-openpgp.c (send_fpr_if_not_null, send_key_data) 
+	(retrieve_fpr_from_card, send_keypair_info): Ditto.
+	* app-nks.c (keygripstr_from_pk_file): Ditto.
+	* command.c (cmd_apdu): Ditto.
+
 2008-10-21  Marcus Brinkmann  <marcus at g10code.com>
 
 	* command.c (open_card): If connect error is SW_HOST_NO_CARD,

Modified: trunk/scd/app-help.c
===================================================================
--- trunk/scd/app-help.c	2008-10-29 17:24:27 UTC (rev 4865)
+++ trunk/scd/app-help.c	2008-11-03 10:54:18 UTC (rev 4866)
@@ -39,7 +39,6 @@
   ksba_sexp_t p;
   size_t n;
   unsigned char array[20];
-  int i;
 
   p = ksba_cert_get_public_key (cert);
   if (!p)
@@ -58,8 +57,7 @@
     }
   gcry_sexp_release (s_pkey);
 
-  for (i=0; i < 20; i++)
-    sprintf (hexkeygrip+i*2, "%02X", array[i]);
+  bin2hex (array, 20, hexkeygrip);
 
   return 0;
 }

Modified: trunk/scd/app-nks.c
===================================================================
--- trunk/scd/app-nks.c	2008-10-29 17:24:27 UTC (rev 4865)
+++ trunk/scd/app-nks.c	2008-11-03 10:54:18 UTC (rev 4866)
@@ -108,8 +108,7 @@
     }
   else
     {
-      for (i=0; i < 20; i++)
-        sprintf (r_gripstr+i*2, "%02X", grip[i]);
+      bin2hex (grip, 20, r_gripstr);
     }
   gcry_sexp_release (sexp);
   return err;

Modified: trunk/scd/app-openpgp.c
===================================================================
--- trunk/scd/app-openpgp.c	2008-10-29 17:24:27 UTC (rev 4865)
+++ trunk/scd/app-openpgp.c	2008-11-03 10:54:18 UTC (rev 4866)
@@ -697,8 +697,7 @@
     ;
   if (i==20)
     return; /* All zero. */
-  for (i=0; i< 20; i++)
-    sprintf (buf+2*i, "%02X", fpr[i]);
+  bin2hex (fpr, 20, buf);
   if (number == -1)
     *numbuf = 0; /* Don't print the key number */
   else
@@ -729,10 +728,14 @@
 send_key_data (ctrl_t ctrl, const char *name, 
                const unsigned char *a, size_t alen)
 {
-  char *p, *buf = xmalloc (alen*2+1);
+  char *buf;
   
-  for (p=buf; alen; a++, alen--, p += 2)
-    sprintf (p, "%02X", *a);
+  buf = bin2hex (a, alen, NULL);
+  if (!buf)
+    {
+      log_error ("memory allocation error in send_key_data\n");
+      return;
+    }
 
   send_status_info (ctrl, "KEY-DATA",
                     name, (size_t)strlen(name), 
@@ -893,16 +896,12 @@
   void *relptr;
   unsigned char *value;
   size_t valuelen;
-  int i;
 
   assert (keyno >=0 && keyno <= 2);
 
   relptr = get_one_do (app, 0x00C5, &value, &valuelen, NULL);
   if (relptr && valuelen >= 60)
-    {
-      for (i = 0; i < 20; i++)
-        sprintf (fpr + (i * 2), "%02X", value[(keyno*20)+i]);
-    }
+    bin2hex (value+keyno*20, 20, fpr);
   else
     err = gpg_error (GPG_ERR_NOT_FOUND);
   xfree (relptr);
@@ -1235,7 +1234,6 @@
   unsigned char grip[20];
   char gripstr[41];
   char idbuf[50];
-  int i;
 
   err = get_public_key (app, keyno);
   if (err)
@@ -1251,8 +1249,7 @@
   if (err)
     goto leave;
   
-  for (i=0; i < 20; i++)
-    sprintf (gripstr+i*2, "%02X", grip[i]);
+  bin2hex (grip, 20, gripstr);
 
   sprintf (idbuf, "OPENPGP.%d", keyno);
   send_status_info (ctrl, "KEYPAIRINFO", 

Modified: trunk/scd/app-p15.c
===================================================================
--- trunk/scd/app-p15.c	2008-10-29 17:24:27 UTC (rev 4865)
+++ trunk/scd/app-p15.c	2008-11-03 10:54:18 UTC (rev 4866)
@@ -2363,7 +2363,6 @@
   for (; certinfo; certinfo = certinfo->next)
     {
       char *buf, *p;
-      int i;
 
       buf = xtrymalloc (9 + certinfo->objidlen*2 + 1);
       if (!buf)
@@ -2375,11 +2374,7 @@
           p += 5;
         }
       p = stpcpy (p, ".");
-      for (i=0; i < certinfo->objidlen; i++)
-        {
-          sprintf (p, "%02X", certinfo->objid[i]);
-          p += 2;
-        }
+      bin2hex (certinfo->objid, certinfo->objidlen, p);
 
       send_status_info (ctrl, "CERTINFO",
                         certtype, strlen (certtype),
@@ -2458,7 +2453,7 @@
     {
       char gripstr[40+1];
       char *buf, *p;
-      int i, j;
+      int j;
 
       buf = xtrymalloc (9 + keyinfo->objidlen*2 + 1);
       if (!buf)
@@ -2470,11 +2465,7 @@
           p += 5;
         }
       p = stpcpy (p, ".");
-      for (i=0; i < keyinfo->objidlen; i++)
-        {
-          sprintf (p, "%02X", keyinfo->objid[i]);
-          p += 2;
-        }
+      bin2hex (keyinfo->objid, keyinfo->objidlen, p);
 
       err = keygripstr_from_prkdf (app, keyinfo, gripstr);
       if (err)
@@ -2669,7 +2660,6 @@
 do_getattr (app_t app, ctrl_t ctrl, const char *name)
 {
   gpg_error_t err;
-  int i;
 
   if (!strcmp (name, "$AUTHKEYID"))
     {
@@ -2694,11 +2684,7 @@
               p += 5;
             }
           p = stpcpy (p, ".");
-          for (i=0; i < prkdf->objidlen; i++)
-            {
-              sprintf (p, "%02X", prkdf->objid[i]);
-              p += 2;
-            }
+          bin2hex (prkdf->objid, prkdf->objidlen, p);
 
           send_status_info (ctrl, name, buf, strlen (buf), NULL, 0);
           xfree (buf);

Modified: trunk/scd/app.c
===================================================================
--- trunk/scd/app.c	2008-10-29 17:24:27 UTC (rev 4865)
+++ trunk/scd/app.c	2008-11-03 10:54:18 UTC (rev 4866)
@@ -106,6 +106,7 @@
 dump_mutex_state (pth_mutex_t *m)
 {
 #ifdef _W32_PTH_H
+  (void)m;
   log_printf ("unknown under W32");
 #else
   if (!(m->mx_state & PTH_MUTEX_INITIALIZED))
@@ -186,7 +187,7 @@
 }
 
  
-/* This fucntion is used by the serialno command to check for an
+/* This function is used by the serialno command to check for an
    application conflict which may appear if the serialno command is
    used to request a specific application and the connection has
    already done a select_application. */
@@ -472,8 +473,7 @@
 gpg_error_t 
 app_get_serial_and_stamp (app_t app, char **serial, time_t *stamp)
 {
-  char *buf, *p;
-  int i;
+  char *buf;
 
   if (!app || !serial)
     return gpg_error (GPG_ERR_INV_VALUE);
@@ -482,12 +482,10 @@
   if (stamp)
     *stamp = 0; /* not available */
 
-  buf = xtrymalloc (app->serialnolen * 2 + 1);
+  buf = bin2hex (app->serialno, app->serialnolen, NULL);
   if (!buf)
     return gpg_error_from_syserror ();
-  for (p=buf, i=0; i < app->serialnolen; p +=2, i++)
-    sprintf (p, "%02X", app->serialno[i]);
-  *p = 0;
+
   *serial = buf;
   return 0;
 }

Modified: trunk/scd/card-p15.c
===================================================================
--- trunk/scd/card-p15.c	2008-10-29 17:24:27 UTC (rev 4865)
+++ trunk/scd/card-p15.c	2008-11-03 10:54:18 UTC (rev 4866)
@@ -174,15 +174,12 @@
   if (keyid)
     {
       char *p;
-      int i;
 
       *keyid = p = xtrymalloc (9+pinfo->id.len*2+1);
       if (!*keyid)
         return gpg_error (gpg_err_code_from_errno (errno));
       p = stpcpy (p, "P15-5015.");
-      for (i=0; i < pinfo->id.len; i++, p += 2)
-        sprintf (p, "%02X", pinfo->id.value[i]);
-      *p = 0;
+      bin2hex (pinfo->id.value, pinfo->id.len, p);
     }
   
   return rc;
@@ -218,9 +215,7 @@
       if (!*certid)
         return gpg_error (gpg_err_code_from_errno (errno));
       p = stpcpy (p, "P15-5015.");
-      for (i=0; i < cinfo->id.len; i++, p += 2)
-        sprintf (p, "%02X", cinfo->id.value[i]);
-      *p = 0;
+      bin2hex (cinfo->id.value, cinfo->id.len, p);
     }
   if (type)
     {

Modified: trunk/scd/command.c
===================================================================
--- trunk/scd/command.c	2008-10-29 17:24:27 UTC (rev 4865)
+++ trunk/scd/command.c	2008-11-03 10:54:18 UTC (rev 4866)
@@ -1704,7 +1704,6 @@
     {
       unsigned char *atr;
       size_t atrlen;
-      int i;
       char hexbuf[400];
       
       atr = apdu_get_atr (ctrl->reader_slot, &atrlen);
@@ -1713,8 +1712,7 @@
           rc = gpg_error (GPG_ERR_INV_CARD);
           goto leave;
         }
-      for (i=0; i < atrlen; i++)
-        sprintf (hexbuf+2*i, "%02X", atr[i]);
+      bin2hex (atr, atrlen, hexbuf);
       xfree (atr);
       send_status_info (ctrl, "CARD-ATR", hexbuf, strlen (hexbuf), NULL, 0);
     }




More information about the Gnupg-commits mailing list