From: Kevin McCarthy Date: Mon, 30 Mar 2015 22:45:51 +0000 (-0700) Subject: Pull is_numerical_keyid() into crypt.c. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=85d0c2373da5190b3be0518db3160315a71544ac;p=neomutt 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 index 446352b07..0d5f456c5 100644 --- a/crypt.c +++ b/crypt.c @@ -997,3 +997,25 @@ const char* crypt_get_fingerprint_or_id (char *p, const char **pphint, *pps = ps; return pfcopy; } + + +/* + * 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 index 8619c5c50..dc92ff3f0 100644 --- a/mutt_crypt.h +++ b/mutt_crypt.h @@ -167,6 +167,9 @@ int crypt_write_signed(BODY *a, STATE *s, const char *tempf); const char* crypt_get_fingerprint_or_id (char *p, const char **pphint, const char **ppl, const char **pps); +/* Check if a string contains a numerical key */ +short crypt_is_numerical_keyid (const char *s); + /*-- cryptglue.c --*/ diff --git a/pgp.c b/pgp.c index 7d041c8b5..5d022bed9 100644 --- a/pgp.c +++ b/pgp.c @@ -31,6 +31,7 @@ #endif #include "mutt.h" +#include "mutt_crypt.h" #include "mutt_curses.h" #include "pgp.h" #include "mime.h" @@ -1166,20 +1167,6 @@ BODY *pgp_sign_message (BODY *a) 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 @@ -1209,7 +1196,7 @@ char *pgp_findKeys (ADDRESS *adrlist, int oppenc_mode) 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;