aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Shaw <[email protected]>2004-03-03 05:47:51 +0000
committerDavid Shaw <[email protected]>2004-03-03 05:47:51 +0000
commit2d7fe1d3a1eaaf77957a6726280136a6dd02691b (patch)
tree73be1a1760719399e4766a94a01c4dc05b47fe0d
parent* packet.h, free-packet.c (free_encrypted, free_plaintext), parse-packet.c (diff)
downloadgnupg-2d7fe1d3a1eaaf77957a6726280136a6dd02691b.tar.gz
gnupg-2d7fe1d3a1eaaf77957a6726280136a6dd02691b.zip
* options.h, g10.c (main): Add a more flexible --keyid-format option to
replace the list-option (and eventually verify-option) show-long-keyids. The format can be short, long, 0xshort, and 0xlong. * keydb.h, keyid.c (keystr, keystrlen): New functions to generate a printable keyid. * keyedit.c (print_and_check_one_sig, show_key_with_all_names), keylist.c (list_keyblock_print): Use new keystr() function here to print keyids.
Diffstat (limited to '')
-rw-r--r--g10/ChangeLog12
-rw-r--r--g10/g10.c16
-rw-r--r--g10/keydb.h2
-rw-r--r--g10/keyedit.c30
-rw-r--r--g10/keyid.c53
-rw-r--r--g10/keylist.c88
-rw-r--r--g10/options.h13
7 files changed, 133 insertions, 81 deletions
diff --git a/g10/ChangeLog b/g10/ChangeLog
index f6b15f7cc..413e16248 100644
--- a/g10/ChangeLog
+++ b/g10/ChangeLog
@@ -1,5 +1,17 @@
2004-03-02 David Shaw <[email protected]>
+ * options.h, g10.c (main): Add a more flexible --keyid-format
+ option to replace the list-option (and eventually verify-option)
+ show-long-keyids. The format can be short, long, 0xshort, and
+ 0xlong.
+
+ * keydb.h, keyid.c (keystr, keystrlen): New functions to generate
+ a printable keyid.
+
+ * keyedit.c (print_and_check_one_sig, show_key_with_all_names),
+ keylist.c (list_keyblock_print): Use new keystr() function here to
+ print keyids.
+
* packet.h, free-packet.c (free_encrypted, free_plaintext),
parse-packet.c (copy_packet, skip_packet, skip_rest, read_rest,
parse_plaintext, parse_encrypted, parse_gpg_control): Use a flag
diff --git a/g10/g10.c b/g10/g10.c
index e4a72f6bd..03e93cc1a 100644
--- a/g10/g10.c
+++ b/g10/g10.c
@@ -335,6 +335,7 @@ enum cmd_and_opt_values
oNoMangleDosFilenames,
oEnableProgressFilter,
oMultifile,
+ oKeyidFormat,
oReaderPort,
octapiDriver,
@@ -665,6 +666,7 @@ static ARGPARSE_OPTS opts[] = {
{ oNoMangleDosFilenames, "no-mangle-dos-filenames", 0, "@" },
{ oEnableProgressFilter, "enable-progress-filter", 0, "@" },
{ oMultifile, "multifile", 0, "@" },
+ { oKeyidFormat, "keyid-format", 2, "@" },
{ oReaderPort, "reader-port", 2, "@"},
{ octapiDriver, "ctapi-driver", 2, "@"},
@@ -1447,6 +1449,7 @@ main( int argc, char **argv )
opt.mangle_dos_filenames=0;
opt.min_cert_level=2;
set_screen_dimensions();
+ opt.keyid_format=KF_SHORT;
#if defined (_WIN32)
set_homedir ( read_w32_registry_string( NULL,
"Software\\GNU\\GnuPG", "HomeDir" ));
@@ -2115,7 +2118,6 @@ main( int argc, char **argv )
{"show-notations",LIST_SHOW_NOTATIONS,NULL},
{"show-keyserver-urls",LIST_SHOW_KEYSERVER_URLS,NULL},
{"show-validity",LIST_SHOW_VALIDITY,NULL},
- {"show-long-keyids",LIST_SHOW_LONG_KEYIDS,NULL},
{"show-unusable-uids",LIST_SHOW_UNUSABLE_UIDS,NULL},
{"show-unusable-subkeys",LIST_SHOW_UNUSABLE_SUBKEYS,NULL},
{"show-keyring",LIST_SHOW_KEYRING,NULL},
@@ -2279,6 +2281,18 @@ main( int argc, char **argv )
case oNoMangleDosFilenames: opt.mangle_dos_filenames = 0; break;
case oEnableProgressFilter: opt.enable_progress_filter = 1; break;
case oMultifile: multifile=1; break;
+ case oKeyidFormat:
+ if(ascii_strcasecmp(pargs.r.ret_str,"short")==0)
+ opt.keyid_format=KF_SHORT;
+ else if(ascii_strcasecmp(pargs.r.ret_str,"long")==0)
+ opt.keyid_format=KF_LONG;
+ else if(ascii_strcasecmp(pargs.r.ret_str,"0xshort")==0)
+ opt.keyid_format=KF_0xSHORT;
+ else if(ascii_strcasecmp(pargs.r.ret_str,"0xlong")==0)
+ opt.keyid_format=KF_0xLONG;
+ else
+ log_error("unknown keyid-format \"%s\"\n",pargs.r.ret_str);
+ break;
default : pargs.err = configfp? 1:2; break;
}
diff --git a/g10/keydb.h b/g10/keydb.h
index 3d4db63c2..c70de0137 100644
--- a/g10/keydb.h
+++ b/g10/keydb.h
@@ -239,6 +239,8 @@ KEYDB_HANDLE get_ctx_handle(GETKEY_CTX ctx);
/*-- keyid.c --*/
int pubkey_letter( int algo );
void hash_public_key( MD_HANDLE md, PKT_public_key *pk );
+size_t keystrlen(void);
+const char *keystr(u32 *keyid);
u32 keyid_from_sk( PKT_secret_key *sk, u32 *keyid );
u32 keyid_from_pk( PKT_public_key *pk, u32 *keyid );
u32 keyid_from_sig( PKT_signature *sig, u32 *keyid );
diff --git a/g10/keyedit.c b/g10/keyedit.c
index a22005fb2..0b648dc9a 100644
--- a/g10/keyedit.c
+++ b/g10/keyedit.c
@@ -134,7 +134,7 @@ print_and_check_one_sig( KBNODE keyblock, KBNODE node,
break;
}
if( sigrc != '?' || print_without_key ) {
- tty_printf("%s%c%c %c%c%c%c%c%c ",
+ tty_printf("%s%c%c %c%c%c%c%c%c %s %s",
is_rev? "rev":"sig",sigrc,
(sig->sig_class-0x10>0 &&
sig->sig_class-0x10<4)?'0'+sig->sig_class-0x10:' ',
@@ -144,12 +144,8 @@ print_and_check_one_sig( KBNODE keyblock, KBNODE node,
sig->flags.notation?'N':' ',
sig->flags.expired?'X':' ',
(sig->trust_depth>9)?'T':
- (sig->trust_depth>0)?'0'+sig->trust_depth:' ');
- if(opt.list_options&LIST_SHOW_LONG_KEYIDS)
- tty_printf("%08lX%08lX",(ulong)sig->keyid[0],(ulong)sig->keyid[1]);
- else
- tty_printf("%08lX",(ulong)sig->keyid[1]);
- tty_printf(" %s", datestr_from_sig(sig));
+ (sig->trust_depth>0)?'0'+sig->trust_depth:' ',
+ keystr(sig->keyid),datestr_from_sig(sig));
if(opt.list_options&LIST_SHOW_SIG_EXPIRE)
tty_printf(" %s",expirestr_from_sig(sig));
tty_printf(" ");
@@ -161,12 +157,13 @@ print_and_check_one_sig( KBNODE keyblock, KBNODE node,
tty_printf( is_rev? _("[revocation]")
: _("[self-signature]") );
}
- else {
+ else
+ {
size_t n;
char *p = get_user_id( sig->keyid, &n );
- tty_print_utf8_string2( p, n, opt.screen_columns-37 );
+ tty_print_utf8_string2( p, n, opt.screen_columns-keystrlen()-26 );
m_free(p);
- }
+ }
tty_printf("\n");
if(sig->flags.policy_url && (opt.list_options&LIST_SHOW_POLICY_URLS))
@@ -2052,16 +2049,13 @@ show_key_with_all_names( KBNODE keyblock, int only_marked, int with_revoker,
}
keyid_from_pk(pk,NULL);
- tty_printf("%s%c %4u%c/",
+ tty_printf("%s%c %4u%c/%s ",
node->pkt->pkttype == PKT_PUBLIC_KEY? "pub":"sub",
(node->flag & NODFLG_SELKEY)? '*':' ',
nbits_from_pk( pk ),
- pubkey_letter( pk->pubkey_algo ));
-
- if(opt.list_options&LIST_SHOW_LONG_KEYIDS)
- tty_printf("%08lX",(ulong)pk->keyid[0]);
+ pubkey_letter( pk->pubkey_algo ),
+ keystr(pk->keyid));
- tty_printf("%08lX ",(ulong)pk->keyid[1]);
tty_printf(_("created: %s"),datestr_from_pk(pk));
tty_printf(" ");
if(pk->is_revoked)
@@ -2076,9 +2070,7 @@ show_key_with_all_names( KBNODE keyblock, int only_marked, int with_revoker,
{
if(opt.trust_model!=TM_ALWAYS)
{
- tty_printf(" ");
- if(opt.list_options&LIST_SHOW_LONG_KEYIDS)
- tty_printf(" ");
+ tty_printf("%*s",keystrlen()+13,"");
/* Ownertrust is only meaningful for the PGP or
classic trust models */
if(opt.trust_model==TM_PGP || opt.trust_model==TM_CLASSIC)
diff --git a/g10/keyid.c b/g10/keyid.c
index 5ae286e89..a2153ad76 100644
--- a/g10/keyid.c
+++ b/g10/keyid.c
@@ -144,6 +144,59 @@ do_fingerprint_md_sk( PKT_secret_key *sk )
return do_fingerprint_md( &pk );
}
+size_t
+keystrlen(void)
+{
+ switch(opt.keyid_format)
+ {
+ case KF_SHORT:
+ return 8;
+
+ case KF_LONG:
+ return 16;
+
+ case KF_0xSHORT:
+ return 10;
+
+ case KF_0xLONG:
+ return 18;
+
+ default:
+ BUG();
+ }
+}
+
+const char *
+keystr(u32 *keyid)
+{
+ static char keyid_str[19];
+
+ switch(opt.keyid_format)
+ {
+ case KF_SHORT:
+ sprintf(keyid_str,"%08lX",(ulong)keyid[1]);
+ break;
+
+ case KF_LONG:
+ sprintf(keyid_str,"%08lX%08lX",(ulong)keyid[0],(ulong)keyid[1]);
+ break;
+
+ case KF_0xSHORT:
+ sprintf(keyid_str,"0x%08lX",(ulong)keyid[1]);
+ break;
+
+ case KF_0xLONG:
+ sprintf(keyid_str,"0x%08lX%08lX",(ulong)keyid[0],(ulong)keyid[1]);
+ break;
+
+ default:
+ BUG();
+ }
+
+ return keyid_str;
+}
+
+
/****************
* Get the keyid from the secret key and put it into keyid
* if this is not NULL. Return the 32 low bits of the keyid.
diff --git a/g10/keylist.c b/g10/keylist.c
index f3fdb15be..8693b343f 100644
--- a/g10/keylist.c
+++ b/g10/keylist.c
@@ -605,9 +605,9 @@ list_keyblock_print ( KBNODE keyblock, int secret, int fpr, void *opaque )
struct sig_stats *stats=opaque;
int skip_sigs=0;
int newformat=((opt.list_options&LIST_SHOW_VALIDITY) && !secret)
- || (opt.list_options & (LIST_SHOW_LONG_KEYIDS
- | LIST_SHOW_UNUSABLE_UIDS
- | LIST_SHOW_UNUSABLE_SUBKEYS));
+ || (opt.list_options & (LIST_SHOW_UNUSABLE_UIDS
+ | LIST_SHOW_UNUSABLE_SUBKEYS))
+ || (keystrlen()>8);
/* get the keyid from the keyblock */
node = find_kbnode( keyblock, secret? PKT_SECRET_KEY : PKT_PUBLIC_KEY );
@@ -623,16 +623,10 @@ list_keyblock_print ( KBNODE keyblock, int secret, int fpr, void *opaque )
sk = node->pkt->pkt.secret_key;
keyid_from_sk( sk, keyid );
- printf("sec%c %4u%c/",(sk->protect.s2k.mode==1001)?'#':
- (sk->protect.s2k.mode==1002)?'>':' ',
- nbits_from_sk( sk ),pubkey_letter( sk->pubkey_algo ));
-
- if(opt.list_options&LIST_SHOW_LONG_KEYIDS)
- printf("%08lX%08lX",(ulong)keyid[0],(ulong)keyid[1]);
- else
- printf("%08lX",(ulong)keyid[1]);
-
- printf(" %s%s",datestr_from_sk( sk ),newformat?"":" " );
+ printf("sec%c %4u%c/%s %s%s",(sk->protect.s2k.mode==1001)?'#':
+ (sk->protect.s2k.mode==1002)?'>':' ',
+ nbits_from_sk( sk ),pubkey_letter( sk->pubkey_algo ),
+ keystr(keyid),datestr_from_sk( sk ),newformat?"":" " );
if(newformat && sk->expiredate )
printf(_(" [expires: %s]"), expirestr_from_sk( sk ) );
@@ -652,15 +646,9 @@ list_keyblock_print ( KBNODE keyblock, int secret, int fpr, void *opaque )
check_trustdb_stale();
- printf("pub %4u%c/",
- nbits_from_pk(pk),pubkey_letter(pk->pubkey_algo));
-
- if(opt.list_options&LIST_SHOW_LONG_KEYIDS)
- printf("%08lX%08lX",(ulong)keyid[0],(ulong)keyid[1]);
- else
- printf("%08lX",(ulong)keyid[1]);
-
- printf(" %s%s",datestr_from_pk( pk ),newformat?"":" " );
+ printf("pub %4u%c/%s %s%s",
+ nbits_from_pk(pk),pubkey_letter(pk->pubkey_algo),
+ keystr(keyid),datestr_from_pk( pk ),newformat?"":" " );
/* We didn't include this before in the key listing, but there
is room in the new format, so why not? */
@@ -685,7 +673,6 @@ list_keyblock_print ( KBNODE keyblock, int secret, int fpr, void *opaque )
for( kbctx=NULL; (node=walk_kbnode( keyblock, &kbctx, 0)) ; ) {
if( node->pkt->pkttype == PKT_USER_ID && !opt.fast_list_mode ) {
- int indent;
PKT_user_id *uid=node->pkt->pkt.user_id;
if((uid->is_expired || uid->is_revoked)
@@ -703,18 +690,20 @@ list_keyblock_print ( KBNODE keyblock, int secret, int fpr, void *opaque )
if(!any && newformat)
printf("\n");
- if(uid->is_revoked || uid->is_expired)
- printf("uid%*s[%s] ",
- (opt.list_options&LIST_SHOW_LONG_KEYIDS)?16:8,"",
- uid->is_revoked?_("revoked"):_("expired"));
- else if((opt.list_options&LIST_SHOW_VALIDITY) && pk)
+ if((uid->is_revoked || uid->is_expired)
+ || ((opt.list_options&LIST_SHOW_VALIDITY) && pk))
{
- const char *validity=
- trust_value_to_string(get_validity(pk,uid));
+ const char *validity;
+ int indent;
- /* Includes the 3 spaces for [, ], and " ". */
- indent=((opt.list_options&LIST_SHOW_LONG_KEYIDS)?23:15)
- -strlen(validity);
+ if(uid->is_revoked)
+ validity=_("revoked");
+ else if(uid->is_expired)
+ validity=_("expired");
+ else
+ validity=trust_value_to_string(get_validity(pk,uid));
+
+ indent=(keystrlen()+7)-strlen(validity);
if(indent<0)
indent=0;
@@ -722,8 +711,7 @@ list_keyblock_print ( KBNODE keyblock, int secret, int fpr, void *opaque )
printf("uid%*s[%s] ",indent,"",validity);
}
else if(newformat)
- printf("uid%*s",
- (opt.list_options&LIST_SHOW_LONG_KEYIDS)?26:18,"");
+ printf("uid%*s",keystrlen()+10,"");
else if(any)
printf("uid%*s",29,"");
@@ -761,13 +749,9 @@ list_keyblock_print ( KBNODE keyblock, int secret, int fpr, void *opaque )
}
keyid_from_pk( pk2, keyid2 );
- printf("sub %4u%c/",
- nbits_from_pk( pk2 ),pubkey_letter( pk2->pubkey_algo ));
- if(opt.list_options&LIST_SHOW_LONG_KEYIDS)
- printf("%08lX%08lX",(ulong)keyid2[0],(ulong)keyid2[1]);
- else
- printf("%08lX",(ulong)keyid2[1]);
- printf(" %s",datestr_from_pk(pk2));
+ printf("sub %4u%c/%s %s",
+ nbits_from_pk( pk2 ),pubkey_letter( pk2->pubkey_algo ),
+ keystr(keyid2),datestr_from_pk(pk2));
if( pk2->is_revoked )
printf(_(" [revoked: %s]"), revokestr_from_pk(pk2));
else if( pk2->has_expired )
@@ -792,15 +776,11 @@ list_keyblock_print ( KBNODE keyblock, int secret, int fpr, void *opaque )
}
keyid_from_sk( sk2, keyid2 );
- printf("ssb%c %4u%c/",
+ printf("ssb%c %4u%c/%s %s",
(sk->protect.s2k.mode==1001)?'#':
(sk->protect.s2k.mode==1002)?'>':' ',
- nbits_from_sk( sk2 ),pubkey_letter( sk2->pubkey_algo ));
- if(opt.list_options&LIST_SHOW_LONG_KEYIDS)
- printf("%08lX%08lX",(ulong)keyid2[0],(ulong)keyid2[1]);
- else
- printf("%08lX",(ulong)keyid2[1]);
- printf(" %s",datestr_from_sk( sk2 ) );
+ nbits_from_sk( sk2 ),pubkey_letter( sk2->pubkey_algo ),
+ keystr(keyid2),datestr_from_sk( sk2 ) );
if( sk2->expiredate )
printf(_(" [expires: %s]"), expirestr_from_sk( sk2 ) );
putchar('\n');
@@ -868,7 +848,7 @@ list_keyblock_print ( KBNODE keyblock, int secret, int fpr, void *opaque )
}
fputs( sigstr, stdout );
- printf("%c%c %c%c%c%c%c%c ",
+ printf("%c%c %c%c%c%c%c%c %s %s",
sigrc,(sig->sig_class-0x10>0 &&
sig->sig_class-0x10<4)?'0'+sig->sig_class-0x10:' ',
sig->flags.exportable?' ':'L',
@@ -877,12 +857,8 @@ list_keyblock_print ( KBNODE keyblock, int secret, int fpr, void *opaque )
sig->flags.notation?'N':' ',
sig->flags.expired?'X':' ',
(sig->trust_depth>9)?'T':
- (sig->trust_depth>0)?'0'+sig->trust_depth:' ');
- if(opt.list_options&LIST_SHOW_LONG_KEYIDS)
- printf("%08lX%08lX",(ulong)sig->keyid[0],(ulong)sig->keyid[1]);
- else
- printf("%08lX",(ulong)sig->keyid[1]);
- printf(" %s", datestr_from_sig(sig));
+ (sig->trust_depth>0)?'0'+sig->trust_depth:' ',
+ keystr(sig->keyid),datestr_from_sig(sig));
if(opt.list_options&LIST_SHOW_SIG_EXPIRE)
printf(" %s", expirestr_from_sig(sig));
printf(" ");
diff --git a/g10/options.h b/g10/options.h
index ef7a4b36f..9aabc23ce 100644
--- a/g10/options.h
+++ b/g10/options.h
@@ -107,6 +107,10 @@ struct
{
CO_GNUPG=0, CO_RFC2440, CO_RFC1991, CO_PGP2, CO_PGP6, CO_PGP7, CO_PGP8
} compliance;
+ enum
+ {
+ KF_SHORT, KF_LONG, KF_0xSHORT, KF_0xLONG
+ } keyid_format;
int pgp2_workarounds;
int shm_coprocess;
const char *set_filename;
@@ -248,11 +252,10 @@ struct
#define LIST_SHOW_NOTATIONS (1<<2)
#define LIST_SHOW_KEYSERVER_URLS (1<<3)
#define LIST_SHOW_VALIDITY (1<<4)
-#define LIST_SHOW_LONG_KEYIDS (1<<5)
-#define LIST_SHOW_UNUSABLE_UIDS (1<<6)
-#define LIST_SHOW_UNUSABLE_SUBKEYS (1<<7)
-#define LIST_SHOW_KEYRING (1<<8)
-#define LIST_SHOW_SIG_EXPIRE (1<<9)
+#define LIST_SHOW_UNUSABLE_UIDS (1<<5)
+#define LIST_SHOW_UNUSABLE_SUBKEYS (1<<6)
+#define LIST_SHOW_KEYRING (1<<7)
+#define LIST_SHOW_SIG_EXPIRE (1<<8)
#define VERIFY_SHOW_PHOTOS (1<<0)
#define VERIFY_SHOW_POLICY_URLS (1<<1)