# HG changeset patch
# User Eike Rathke <er...@erack.de>
# Date 1423687143 -3600
# Node ID 659e014a1bfba9e75155a6df1223e8a7d1d7008f
# Parent  01f6559e4bb51bfe86e9f48812480bd4d57adc03
Allow fingerprint user input in crypt_getkeybystr() (part of #3695)

diff --git a/crypt-gpgme.c b/crypt-gpgme.c
--- a/crypt-gpgme.c
+++ b/crypt-gpgme.c
@@ -4188,32 +4188,24 @@
   crypt_key_t *matches = NULL;
   crypt_key_t **matches_endp = &matches;
   crypt_key_t *k;
-  const char *ps, *pl;
+  const char *ps, *pl, *pfcopy, *phint;
+
+  pfcopy = crypt_get_fingerprint_or_id (p, &phint, &pl, &ps);
 
   mutt_message (_("Looking for keys matching \"%s\"..."), p);
 
   *forced_valid = 0;
 
-  hints = crypt_add_string_to_hints (hints, p);
+  hints = crypt_add_string_to_hints (hints, phint);
   keys = get_candidates (hints, app, (abilities & KEYFLAG_CANSIGN));
   mutt_free_list (&hints);
 
   if (!keys)
+  {
+    FREE (&pfcopy);
     return NULL;
-
-  /* User input may be short or long key ID, independent of OPTPGPLONGIDS.
-   * crypt_key_t->keyid should always contain a long key ID without 0x.
-   * Strip leading "0x" before loops so it doesn't have to be done over and
-   * over again, and prepare pl and ps to simplify logic in the loop's inner
-   * condition.
-   */
-  pl = (!mutt_strncasecmp (p, "0x", 2) ? p + 2 : p);
-  ps = (mutt_strlen (pl) == 16 ? pl + 8 : pl);
-
-  /* If ps != pl it means a long ID (or name of 16 characters) was given, do
-   * not attempt to match short IDs then. Also, it is unnecessary to try to
-   * match pl against long IDs if ps == pl as pl could not be a long ID. */
-  
+  }
+
   for (k = keys; k; k = k->next)
     {
       if (abilities && !(k->flags & abilities))
@@ -4222,9 +4214,17 @@
       dprint (5, (debugfile, "crypt_getkeybystr: matching \"%s\" against "
                   "key %s, \"%s\": ",  p, crypt_long_keyid (k), k->uid));
 
+      /* If pfcopy != NULL it means a fingerprint was given, do not attempt to
+       * match long or short IDs then.
+       * If pl != NULL it means a long ID was given, do not attempt to match
+       * short IDs then.
+       * If ps != NULL it means a short ID was given.
+       */
       if (!*p
-          || (ps != pl && mutt_strcasecmp (pl, crypt_long_keyid (k)) == 0)
-          || (ps == pl && mutt_strcasecmp (ps, crypt_short_keyid (k)) == 0)
+          || (pfcopy && mutt_strcasecmp (pfcopy, crypt_fpr (k)) == 0)
+          || (!pfcopy
+            && ((pl && mutt_strcasecmp (pl, crypt_long_keyid (k)) == 0)
+              || (ps && !pl && mutt_strcasecmp (ps, crypt_short_keyid (k)) == 0)))
           || mutt_stristr (k->uid, p))
         {
           crypt_key_t *tmp;
@@ -4236,6 +4236,7 @@
         }
     }
   
+  FREE (&pfcopy);
   crypt_free_key (&keys);
   
   if (matches)

Attachment: signature.asc
Description: Digital signature

Reply via email to