# HG changeset patch # User Kevin McCarthy # Date 1423248570 28800 # Fri Feb 06 10:49:30 2015 -0800 # Node ID 5475ea594ba7451a6cc23ce70d6b8ccd37eb0cda # Parent 641480cff53addb92ac1bb0153580d164f1344a8 Pull is_numerical_keyid() into crypt.c. A subsequent patch (re?)-introduces a call to is_numerical_keyid inside find_keys(). Rather than duplicate the function, this patch pulls it into crypt.c, where find_keys() and pgp_findKeys() can both call it. diff --git a/crypt.c b/crypt.c --- a/crypt.c +++ b/crypt.c @@ -912,8 +912,28 @@ if (s->flags & M_DISPLAY && sigcnt) state_attach_puts (_("\n[-- End of signed data --]\n"), s); return rc; } +/* + * Used by pgp_findKeys and find_keys to check if a crypt-hook + * value is a key id. + */ + +short crypt_is_numerical_keyid (const char *s) +{ + /* or should we require the "0x"? */ + if (strncmp (s, "0x", 2) == 0) + s += 2; + if (strlen (s) % 8) + return 0; + while (*s) + if (strchr ("0123456789ABCDEFabcdef", *s++) == NULL) + return 0; + + return 1; +} + + diff --git a/mutt_crypt.h b/mutt_crypt.h --- a/mutt_crypt.h +++ b/mutt_crypt.h @@ -148,16 +148,19 @@ /* Check that we have a usable passphrase, ask if not. */ int crypt_valid_passphrase (int); /* Write the message body/part A described by state S to a the given TEMPFILE. */ int crypt_write_signed(BODY *a, STATE *s, const char *tempf); +/* Check if a string contains a numerical key */ +short crypt_is_numerical_keyid (const char *s); + /*-- cryptglue.c --*/ /* Show a message that a backend will be invoked. */ void crypt_invoke_message (int type); diff --git a/pgp.c b/pgp.c --- a/pgp.c +++ b/pgp.c @@ -26,16 +26,17 @@ * a message. */ #if HAVE_CONFIG_H # include "config.h" #endif #include "mutt.h" +#include "mutt_crypt.h" #include "mutt_curses.h" #include "pgp.h" #include "mime.h" #include "copy.h" #include #include #include @@ -1149,30 +1150,16 @@ t->disposition = DISPNONE; t->encoding = ENC7BIT; t->unlink = 1; /* ok to remove this file after sending. */ mutt_set_parameter ("name", "signature.asc", &t->parameter); return (a); } -static short is_numerical_keyid (const char *s) -{ - /* or should we require the "0x"? */ - if (strncmp (s, "0x", 2) == 0) - s += 2; - if (strlen (s) % 8) - return 0; - while (*s) - if (strchr ("0123456789ABCDEFabcdef", *s++) == NULL) - return 0; - - return 1; -} - /* This routine attempts to find the keyids of the recipients of a message. * It returns NULL if any of the keys can not be found. * If oppenc_mode is true, only keys that can be determined without * prompting will be used. */ char *pgp_findKeys (ADDRESS *adrlist, int oppenc_mode) { char *keyID, *keylist = NULL; @@ -1192,17 +1179,17 @@ k_info = NULL; if ((keyID = mutt_crypt_hook (p)) != NULL) { int r; snprintf (buf, sizeof (buf), _("Use keyID = \"%s\" for %s?"), keyID, p->mailbox); if ((r = mutt_yesorno (buf, M_YES)) == M_YES) { - if (is_numerical_keyid (keyID)) + if (crypt_is_numerical_keyid (keyID)) { if (strncmp (keyID, "0x", 2) == 0) keyID += 2; goto bypass_selection; /* you don't see this. */ } /* check for e-mail address */ if (strchr (keyID, '@') &&