mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-03 12:11:33 +01:00
gpg: Add function format_keyid.
* g10/options.h (opt.keyid_format): Add new value KF_DEFAULT. * g10/keyid.c (format_keyid): New function. (keystr): Use it. -- Signed-off-by: Neal H. Walfield <neal@g10code.com>
This commit is contained in:
parent
eae982ed6d
commit
a052c30d31
@ -786,6 +786,7 @@ char *pubkey_string (PKT_public_key *pk, char *buffer, size_t bufsize);
|
||||
#define PUBKEY_STRING_SIZE 32
|
||||
u32 v3_keyid (gcry_mpi_t a, u32 *ki);
|
||||
void hash_public_key( gcry_md_hd_t md, PKT_public_key *pk );
|
||||
const char *format_keyid (u32 *keyid, int format, char *buffer, int len);
|
||||
size_t keystrlen(void);
|
||||
const char *keystr(u32 *keyid);
|
||||
const char *keystr_with_sub (u32 *main_kid, u32 *sub_kid);
|
||||
|
80
g10/keyid.c
80
g10/keyid.c
@ -274,6 +274,53 @@ v3_keyid (gcry_mpi_t a, u32 *ki)
|
||||
}
|
||||
|
||||
|
||||
const char *
|
||||
format_keyid (u32 *keyid, int format, char *buffer, int len)
|
||||
{
|
||||
char tmp[KEYID_STR_SIZE];
|
||||
if (! buffer)
|
||||
buffer = tmp;
|
||||
|
||||
if (format == KF_DEFAULT)
|
||||
format = opt.keyid_format;
|
||||
if (format == KF_DEFAULT)
|
||||
format = KF_0xLONG;
|
||||
|
||||
switch (format)
|
||||
{
|
||||
case KF_SHORT:
|
||||
snprintf (buffer, len, "%08lX", (ulong)keyid[1]);
|
||||
break;
|
||||
|
||||
case KF_LONG:
|
||||
if (keyid[0])
|
||||
snprintf (buffer, len, "%08lX%08lX",
|
||||
(ulong)keyid[0], (ulong)keyid[1]);
|
||||
else
|
||||
snprintf (buffer, len, "%08lX", (ulong)keyid[1]);
|
||||
break;
|
||||
|
||||
case KF_0xSHORT:
|
||||
snprintf (buffer, len, "0x%08lX", (ulong)keyid[1]);
|
||||
break;
|
||||
|
||||
case KF_0xLONG:
|
||||
if(keyid[0])
|
||||
snprintf (buffer, len, "0x%08lX%08lX",
|
||||
(ulong)keyid[0],(ulong)keyid[1]);
|
||||
else
|
||||
snprintf (buffer, len, "0x%08lX", (ulong)keyid[1]);
|
||||
break;
|
||||
|
||||
default:
|
||||
BUG();
|
||||
}
|
||||
|
||||
if (buffer == tmp)
|
||||
return xstrdup (buffer);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
size_t
|
||||
keystrlen(void)
|
||||
{
|
||||
@ -301,38 +348,7 @@ const char *
|
||||
keystr (u32 *keyid)
|
||||
{
|
||||
static char keyid_str[KEYID_STR_SIZE];
|
||||
|
||||
switch (opt.keyid_format)
|
||||
{
|
||||
case KF_SHORT:
|
||||
snprintf (keyid_str, sizeof keyid_str, "%08lX", (ulong)keyid[1]);
|
||||
break;
|
||||
|
||||
case KF_LONG:
|
||||
if (keyid[0])
|
||||
snprintf (keyid_str, sizeof keyid_str, "%08lX%08lX",
|
||||
(ulong)keyid[0], (ulong)keyid[1]);
|
||||
else
|
||||
snprintf (keyid_str, sizeof keyid_str, "%08lX", (ulong)keyid[1]);
|
||||
break;
|
||||
|
||||
case KF_0xSHORT:
|
||||
snprintf (keyid_str, sizeof keyid_str, "0x%08lX", (ulong)keyid[1]);
|
||||
break;
|
||||
|
||||
case KF_0xLONG:
|
||||
if(keyid[0])
|
||||
snprintf (keyid_str, sizeof keyid_str, "0x%08lX%08lX",
|
||||
(ulong)keyid[0],(ulong)keyid[1]);
|
||||
else
|
||||
snprintf (keyid_str, sizeof keyid_str, "0x%08lX", (ulong)keyid[1]);
|
||||
break;
|
||||
|
||||
default:
|
||||
BUG();
|
||||
}
|
||||
|
||||
return keyid_str;
|
||||
return format_keyid (keyid, opt.keyid_format, keyid_str, sizeof (keyid_str));
|
||||
}
|
||||
|
||||
|
||||
|
@ -136,7 +136,7 @@ struct
|
||||
} compliance;
|
||||
enum
|
||||
{
|
||||
KF_SHORT, KF_LONG, KF_0xSHORT, KF_0xLONG
|
||||
KF_DEFAULT, KF_SHORT, KF_LONG, KF_0xSHORT, KF_0xLONG
|
||||
} keyid_format;
|
||||
int shm_coprocess;
|
||||
const char *set_filename;
|
||||
|
Loading…
x
Reference in New Issue
Block a user