aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2008-11-03 10:54:18 +0000
committerWerner Koch <[email protected]>2008-11-03 10:54:18 +0000
commit338ddd0bb63efac5466939f06a4772c55a6b14aa (patch)
tree91e5452da6a7c8e2936ce0b261cd42bd3705da38
parentCheck that the socket is well and served by us. (diff)
downloadgnupg-338ddd0bb63efac5466939f06a4772c55a6b14aa.tar.gz
gnupg-338ddd0bb63efac5466939f06a4772c55a6b14aa.zip
Use bin2hex if possible.
-rw-r--r--scd/ChangeLog10
-rw-r--r--scd/app-help.c4
-rw-r--r--scd/app-nks.c3
-rw-r--r--scd/app-openpgp.c23
-rw-r--r--scd/app-p15.c22
-rw-r--r--scd/app.c12
-rw-r--r--scd/card-p15.c9
-rw-r--r--scd/command.c4
8 files changed, 34 insertions, 53 deletions
diff --git a/scd/ChangeLog b/scd/ChangeLog
index 51599315f..53b01e9de 100644
--- a/scd/ChangeLog
+++ b/scd/ChangeLog
@@ -1,3 +1,13 @@
+2008-11-03 Werner Koch <[email protected]>
+
+ * 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 <[email protected]>
* command.c (open_card): If connect error is SW_HOST_NO_CARD,
diff --git a/scd/app-help.c b/scd/app-help.c
index 45c7586f7..7b9ce992d 100644
--- a/scd/app-help.c
+++ b/scd/app-help.c
@@ -39,7 +39,6 @@ app_help_get_keygrip_string (ksba_cert_t cert, char *hexkeygrip)
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 @@ app_help_get_keygrip_string (ksba_cert_t cert, char *hexkeygrip)
}
gcry_sexp_release (s_pkey);
- for (i=0; i < 20; i++)
- sprintf (hexkeygrip+i*2, "%02X", array[i]);
+ bin2hex (array, 20, hexkeygrip);
return 0;
}
diff --git a/scd/app-nks.c b/scd/app-nks.c
index ac28ba258..31ddae0bd 100644
--- a/scd/app-nks.c
+++ b/scd/app-nks.c
@@ -108,8 +108,7 @@ keygripstr_from_pk_file (int slot, int fid, char *r_gripstr)
}
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;
diff --git a/scd/app-openpgp.c b/scd/app-openpgp.c
index def42195f..a64d77cde 100644
--- a/scd/app-openpgp.c
+++ b/scd/app-openpgp.c
@@ -697,8 +697,7 @@ send_fpr_if_not_null (ctrl_t ctrl, const char *keyword,
;
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 @@ static void
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 @@ retrieve_fpr_from_card (app_t app, int keyno, char *fpr)
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 @@ send_keypair_info (app_t app, ctrl_t ctrl, int keyno)
unsigned char grip[20];
char gripstr[41];
char idbuf[50];
- int i;
err = get_public_key (app, keyno);
if (err)
@@ -1251,8 +1249,7 @@ send_keypair_info (app_t app, ctrl_t ctrl, int keyno)
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",
diff --git a/scd/app-p15.c b/scd/app-p15.c
index 4ac18d61a..4ebe7b2fd 100644
--- a/scd/app-p15.c
+++ b/scd/app-p15.c
@@ -2363,7 +2363,6 @@ send_certinfo (app_t app, ctrl_t ctrl, const char *certtype,
for (; certinfo; certinfo = certinfo->next)
{
char *buf, *p;
- int i;
buf = xtrymalloc (9 + certinfo->objidlen*2 + 1);
if (!buf)
@@ -2375,11 +2374,7 @@ send_certinfo (app_t app, ctrl_t ctrl, const char *certtype,
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 @@ send_keypairinfo (app_t app, ctrl_t ctrl, prkdf_object_t keyinfo)
{
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 @@ send_keypairinfo (app_t app, ctrl_t ctrl, prkdf_object_t keyinfo)
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 @@ static gpg_error_t
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 @@ do_getattr (app_t app, ctrl_t ctrl, const char *name)
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);
diff --git a/scd/app.c b/scd/app.c
index 0c8ddfbdd..b15c55e11 100644
--- a/scd/app.c
+++ b/scd/app.c
@@ -106,6 +106,7 @@ static void
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 @@ application_notify_card_removed (int slot)
}
-/* 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 @@ app_munge_serialno (app_t app)
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 @@ app_get_serial_and_stamp (app_t app, char **serial, time_t *stamp)
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;
}
diff --git a/scd/card-p15.c b/scd/card-p15.c
index b95825373..34a88f714 100644
--- a/scd/card-p15.c
+++ b/scd/card-p15.c
@@ -174,15 +174,12 @@ p15_enum_keypairs (CARD card, int idx,
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 @@ p15_enum_certs (CARD card, int idx, char **certid, int *type)
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)
{
diff --git a/scd/command.c b/scd/command.c
index f41252a32..849c9e33d 100644
--- a/scd/command.c
+++ b/scd/command.c
@@ -1704,7 +1704,6 @@ cmd_apdu (assuan_context_t ctx, char *line)
{
unsigned char *atr;
size_t atrlen;
- int i;
char hexbuf[400];
atr = apdu_get_atr (ctrl->reader_slot, &atrlen);
@@ -1713,8 +1712,7 @@ cmd_apdu (assuan_context_t ctx, char *line)
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);
}