1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

Use bin2hex if possible.

This commit is contained in:
Werner Koch 2008-11-03 10:54:18 +00:00
parent 8997c155e3
commit 338ddd0bb6
8 changed files with 34 additions and 53 deletions

View File

@ -1,3 +1,13 @@
2008-11-03 Werner Koch <wk@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@g10code.com>
* command.c (open_card): If connect error is SW_HOST_NO_CARD,

View File

@ -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;
}

View File

@ -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;

View File

@ -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",

View File

@ -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);

View File

@ -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;
}

View File

@ -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)
{

View File

@ -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);
}