* trustdb.h, keyedit.c (keyedit_menu, menu_select_uid_namehash): Allow
authorDavid Shaw <dshaw@jabberwocky.com>
Sun, 24 Apr 2005 16:05:41 +0000 (16:05 +0000)
committerDavid Shaw <dshaw@jabberwocky.com>
Sun, 24 Apr 2005 16:05:41 +0000 (16:05 +0000)
specifying user ID via the namehash from --with-colons
--fixed-list-mode --list-keys.  Suggested by Peter Palfrader.

g10/ChangeLog
g10/keyedit.c
g10/trustdb.h

index 87efc87..d0fa926 100644 (file)
@@ -1,3 +1,9 @@
+2005-04-24  David Shaw  <dshaw@jabberwocky.com>
+
+       * 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  <dshaw@jabberwocky.com>
 
        * keyedit.c (sign_uids, keyedit_menu): When the user requests to
index 7db46cf..7a00695 100644 (file)
@@ -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;i<NAMEHASH_LEN;i++)
+    hash[i]=hextobyte(&namehash[i*2]);
+
+  for(node=keyblock->next;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;
index 8bcaae5..710c13b 100644 (file)
@@ -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 );