From 6d72a1c6494c2508f49b47a02fab21b1fa27a253 Mon Sep 17 00:00:00 2001 From: David Shaw Date: Sun, 24 Apr 2005 16:05:41 +0000 Subject: [PATCH] * trustdb.h, keyedit.c (keyedit_menu, menu_select_uid_namehash): Allow specifying user ID via the namehash from --with-colons --fixed-list-mode --list-keys. Suggested by Peter Palfrader. --- g10/ChangeLog | 6 ++++++ g10/keyedit.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- g10/trustdb.h | 3 +++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/g10/ChangeLog b/g10/ChangeLog index 87efc8773..d0fa9262a 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,9 @@ +2005-04-24 David Shaw + + * trustdb.h, keyedit.c (keyedit_menu, menu_select_uid_namehash): + Allow specifying user ID via the namehash from --with-colons + --fixed-list-mode --list-keys. Suggested by Peter Palfrader. + 2005-04-21 David Shaw * keyedit.c (sign_uids, keyedit_menu): When the user requests to diff --git a/g10/keyedit.c b/g10/keyedit.c index 7db46cf06..7a00695b2 100644 --- a/g10/keyedit.c +++ b/g10/keyedit.c @@ -62,6 +62,7 @@ static int menu_set_preferences( KBNODE pub_keyblock, KBNODE sec_keyblock ); static int menu_set_keyserver_url (const char *url, KBNODE pub_keyblock, KBNODE sec_keyblock ); static int menu_select_uid( KBNODE keyblock, int idx ); +static int menu_select_uid_namehash( KBNODE keyblock, const char *namehash ); static int menu_select_key( KBNODE keyblock, int idx ); static int count_uids( KBNODE keyblock ); static int count_uids_with_flag( KBNODE keyblock, unsigned flag ); @@ -1685,8 +1686,10 @@ keyedit_menu( const char *username, STRLIST locusr, break; case cmdSELUID: - if( menu_select_uid( cur_keyblock, arg_number ) ) - redisplay = 1; + if(strlen(arg_string)==NAMEHASH_LEN*2) + redisplay=menu_select_uid_namehash(cur_keyblock,arg_string); + else + redisplay=menu_select_uid(cur_keyblock,arg_number); break; case cmdSELKEY: @@ -3900,6 +3903,45 @@ menu_select_uid( KBNODE keyblock, int idx ) return 1; } +/* Search in the keyblock for a uid that matches namehash */ +static int +menu_select_uid_namehash( KBNODE keyblock, const char *namehash ) +{ + byte hash[NAMEHASH_LEN]; + KBNODE node; + int i; + + assert(strlen(namehash)==NAMEHASH_LEN*2); + + for(i=0;inext;node;node=node->next) + { + if(node->pkt->pkttype==PKT_USER_ID) + { + namehash_from_uid(node->pkt->pkt.user_id); + if(memcmp(node->pkt->pkt.user_id->namehash,hash,NAMEHASH_LEN)==0) + { + if(node->flag&NODFLG_SELUID) + node->flag &= ~NODFLG_SELUID; + else + node->flag |= NODFLG_SELUID; + + break; + } + } + } + + if(!node) + { + tty_printf(_("No user ID with hash %s\n"),namehash); + return 0; + } + + return 1; +} + /**************** * Select secondary keys * Returns: True if the selection changed; diff --git a/g10/trustdb.h b/g10/trustdb.h index 8bcaae51e..710c13b22 100644 --- a/g10/trustdb.h +++ b/g10/trustdb.h @@ -37,6 +37,9 @@ #define TRUST_FLAG_DISABLED 128 /* d: key/uid disabled */ #define TRUST_FLAG_PENDING_CHECK 256 /* a check-trustdb is pending */ +#define NAMEHASH_HASH DIGEST_ALGO_RMD160 +#define NAMEHASH_LEN 20 + /*-- trustdb.c --*/ void register_trusted_keyid(u32 *keyid); void register_trusted_key( const char *string );