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> 2008-10-21 Marcus Brinkmann <marcus@g10code.com>
* command.c (open_card): If connect error is SW_HOST_NO_CARD, * 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; ksba_sexp_t p;
size_t n; size_t n;
unsigned char array[20]; unsigned char array[20];
int i;
p = ksba_cert_get_public_key (cert); p = ksba_cert_get_public_key (cert);
if (!p) if (!p)
@ -58,8 +57,7 @@ app_help_get_keygrip_string (ksba_cert_t cert, char *hexkeygrip)
} }
gcry_sexp_release (s_pkey); gcry_sexp_release (s_pkey);
for (i=0; i < 20; i++) bin2hex (array, 20, hexkeygrip);
sprintf (hexkeygrip+i*2, "%02X", array[i]);
return 0; return 0;
} }

View File

@ -108,8 +108,7 @@ keygripstr_from_pk_file (int slot, int fid, char *r_gripstr)
} }
else else
{ {
for (i=0; i < 20; i++) bin2hex (grip, 20, r_gripstr);
sprintf (r_gripstr+i*2, "%02X", grip[i]);
} }
gcry_sexp_release (sexp); gcry_sexp_release (sexp);
return err; return err;

View File

@ -697,8 +697,7 @@ send_fpr_if_not_null (ctrl_t ctrl, const char *keyword,
; ;
if (i==20) if (i==20)
return; /* All zero. */ return; /* All zero. */
for (i=0; i< 20; i++) bin2hex (fpr, 20, buf);
sprintf (buf+2*i, "%02X", fpr[i]);
if (number == -1) if (number == -1)
*numbuf = 0; /* Don't print the key number */ *numbuf = 0; /* Don't print the key number */
else else
@ -729,10 +728,14 @@ static void
send_key_data (ctrl_t ctrl, const char *name, send_key_data (ctrl_t ctrl, const char *name,
const unsigned char *a, size_t alen) const unsigned char *a, size_t alen)
{ {
char *p, *buf = xmalloc (alen*2+1); char *buf;
for (p=buf; alen; a++, alen--, p += 2) buf = bin2hex (a, alen, NULL);
sprintf (p, "%02X", *a); if (!buf)
{
log_error ("memory allocation error in send_key_data\n");
return;
}
send_status_info (ctrl, "KEY-DATA", send_status_info (ctrl, "KEY-DATA",
name, (size_t)strlen(name), name, (size_t)strlen(name),
@ -893,16 +896,12 @@ retrieve_fpr_from_card (app_t app, int keyno, char *fpr)
void *relptr; void *relptr;
unsigned char *value; unsigned char *value;
size_t valuelen; size_t valuelen;
int i;
assert (keyno >=0 && keyno <= 2); assert (keyno >=0 && keyno <= 2);
relptr = get_one_do (app, 0x00C5, &value, &valuelen, NULL); relptr = get_one_do (app, 0x00C5, &value, &valuelen, NULL);
if (relptr && valuelen >= 60) if (relptr && valuelen >= 60)
{ bin2hex (value+keyno*20, 20, fpr);
for (i = 0; i < 20; i++)
sprintf (fpr + (i * 2), "%02X", value[(keyno*20)+i]);
}
else else
err = gpg_error (GPG_ERR_NOT_FOUND); err = gpg_error (GPG_ERR_NOT_FOUND);
xfree (relptr); xfree (relptr);
@ -1235,7 +1234,6 @@ send_keypair_info (app_t app, ctrl_t ctrl, int keyno)
unsigned char grip[20]; unsigned char grip[20];
char gripstr[41]; char gripstr[41];
char idbuf[50]; char idbuf[50];
int i;
err = get_public_key (app, keyno); err = get_public_key (app, keyno);
if (err) if (err)
@ -1251,8 +1249,7 @@ send_keypair_info (app_t app, ctrl_t ctrl, int keyno)
if (err) if (err)
goto leave; goto leave;
for (i=0; i < 20; i++) bin2hex (grip, 20, gripstr);
sprintf (gripstr+i*2, "%02X", grip[i]);
sprintf (idbuf, "OPENPGP.%d", keyno); sprintf (idbuf, "OPENPGP.%d", keyno);
send_status_info (ctrl, "KEYPAIRINFO", 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) for (; certinfo; certinfo = certinfo->next)
{ {
char *buf, *p; char *buf, *p;
int i;
buf = xtrymalloc (9 + certinfo->objidlen*2 + 1); buf = xtrymalloc (9 + certinfo->objidlen*2 + 1);
if (!buf) if (!buf)
@ -2375,11 +2374,7 @@ send_certinfo (app_t app, ctrl_t ctrl, const char *certtype,
p += 5; p += 5;
} }
p = stpcpy (p, "."); p = stpcpy (p, ".");
for (i=0; i < certinfo->objidlen; i++) bin2hex (certinfo->objid, certinfo->objidlen, p);
{
sprintf (p, "%02X", certinfo->objid[i]);
p += 2;
}
send_status_info (ctrl, "CERTINFO", send_status_info (ctrl, "CERTINFO",
certtype, strlen (certtype), certtype, strlen (certtype),
@ -2458,7 +2453,7 @@ send_keypairinfo (app_t app, ctrl_t ctrl, prkdf_object_t keyinfo)
{ {
char gripstr[40+1]; char gripstr[40+1];
char *buf, *p; char *buf, *p;
int i, j; int j;
buf = xtrymalloc (9 + keyinfo->objidlen*2 + 1); buf = xtrymalloc (9 + keyinfo->objidlen*2 + 1);
if (!buf) if (!buf)
@ -2470,11 +2465,7 @@ send_keypairinfo (app_t app, ctrl_t ctrl, prkdf_object_t keyinfo)
p += 5; p += 5;
} }
p = stpcpy (p, "."); p = stpcpy (p, ".");
for (i=0; i < keyinfo->objidlen; i++) bin2hex (keyinfo->objid, keyinfo->objidlen, p);
{
sprintf (p, "%02X", keyinfo->objid[i]);
p += 2;
}
err = keygripstr_from_prkdf (app, keyinfo, gripstr); err = keygripstr_from_prkdf (app, keyinfo, gripstr);
if (err) if (err)
@ -2669,7 +2660,6 @@ static gpg_error_t
do_getattr (app_t app, ctrl_t ctrl, const char *name) do_getattr (app_t app, ctrl_t ctrl, const char *name)
{ {
gpg_error_t err; gpg_error_t err;
int i;
if (!strcmp (name, "$AUTHKEYID")) if (!strcmp (name, "$AUTHKEYID"))
{ {
@ -2694,11 +2684,7 @@ do_getattr (app_t app, ctrl_t ctrl, const char *name)
p += 5; p += 5;
} }
p = stpcpy (p, "."); p = stpcpy (p, ".");
for (i=0; i < prkdf->objidlen; i++) bin2hex (prkdf->objid, prkdf->objidlen, p);
{
sprintf (p, "%02X", prkdf->objid[i]);
p += 2;
}
send_status_info (ctrl, name, buf, strlen (buf), NULL, 0); send_status_info (ctrl, name, buf, strlen (buf), NULL, 0);
xfree (buf); xfree (buf);

View File

@ -106,6 +106,7 @@ static void
dump_mutex_state (pth_mutex_t *m) dump_mutex_state (pth_mutex_t *m)
{ {
#ifdef _W32_PTH_H #ifdef _W32_PTH_H
(void)m;
log_printf ("unknown under W32"); log_printf ("unknown under W32");
#else #else
if (!(m->mx_state & PTH_MUTEX_INITIALIZED)) 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 application conflict which may appear if the serialno command is
used to request a specific application and the connection has used to request a specific application and the connection has
already done a select_application. */ already done a select_application. */
@ -472,8 +473,7 @@ app_munge_serialno (app_t app)
gpg_error_t gpg_error_t
app_get_serial_and_stamp (app_t app, char **serial, time_t *stamp) app_get_serial_and_stamp (app_t app, char **serial, time_t *stamp)
{ {
char *buf, *p; char *buf;
int i;
if (!app || !serial) if (!app || !serial)
return gpg_error (GPG_ERR_INV_VALUE); 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) if (stamp)
*stamp = 0; /* not available */ *stamp = 0; /* not available */
buf = xtrymalloc (app->serialnolen * 2 + 1); buf = bin2hex (app->serialno, app->serialnolen, NULL);
if (!buf) if (!buf)
return gpg_error_from_syserror (); 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; *serial = buf;
return 0; return 0;
} }

View File

@ -174,15 +174,12 @@ p15_enum_keypairs (CARD card, int idx,
if (keyid) if (keyid)
{ {
char *p; char *p;
int i;
*keyid = p = xtrymalloc (9+pinfo->id.len*2+1); *keyid = p = xtrymalloc (9+pinfo->id.len*2+1);
if (!*keyid) if (!*keyid)
return gpg_error (gpg_err_code_from_errno (errno)); return gpg_error (gpg_err_code_from_errno (errno));
p = stpcpy (p, "P15-5015."); p = stpcpy (p, "P15-5015.");
for (i=0; i < pinfo->id.len; i++, p += 2) bin2hex (pinfo->id.value, pinfo->id.len, p);
sprintf (p, "%02X", pinfo->id.value[i]);
*p = 0;
} }
return rc; return rc;
@ -218,9 +215,7 @@ p15_enum_certs (CARD card, int idx, char **certid, int *type)
if (!*certid) if (!*certid)
return gpg_error (gpg_err_code_from_errno (errno)); return gpg_error (gpg_err_code_from_errno (errno));
p = stpcpy (p, "P15-5015."); p = stpcpy (p, "P15-5015.");
for (i=0; i < cinfo->id.len; i++, p += 2) bin2hex (cinfo->id.value, cinfo->id.len, p);
sprintf (p, "%02X", cinfo->id.value[i]);
*p = 0;
} }
if (type) if (type)
{ {

View File

@ -1704,7 +1704,6 @@ cmd_apdu (assuan_context_t ctx, char *line)
{ {
unsigned char *atr; unsigned char *atr;
size_t atrlen; size_t atrlen;
int i;
char hexbuf[400]; char hexbuf[400];
atr = apdu_get_atr (ctrl->reader_slot, &atrlen); 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); rc = gpg_error (GPG_ERR_INV_CARD);
goto leave; goto leave;
} }
for (i=0; i < atrlen; i++) bin2hex (atr, atrlen, hexbuf);
sprintf (hexbuf+2*i, "%02X", atr[i]);
xfree (atr); xfree (atr);
send_status_info (ctrl, "CARD-ATR", hexbuf, strlen (hexbuf), NULL, 0); send_status_info (ctrl, "CARD-ATR", hexbuf, strlen (hexbuf), NULL, 0);
} }