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.


 crypt.c      |  20 ++++++++++++++++++++
 mutt_crypt.h |   3 +++
 pgp.c        |  17 ++---------------
 3 files changed, 25 insertions(+), 15 deletions(-)


# HG changeset patch
# User Kevin McCarthy <ke...@8t8.us>
# Date 1363403034 25200
# Branch HEAD
# Node ID 7082744ee06bb5388cb1de22147b20b210d06efc
# Parent  62ba80fe6a73584a0ea8150400b8e8e2a58cc02c
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 <sys/wait.h>
 #include <string.h>
 #include <stdlib.h>
@@ -1126,30 +1127,16 @@
   t->use_disp = 0;
   t->disposition = DISPNONE;
   t->encoding = ENC7BIT;
   t->unlink = 1; /* ok to remove this file after sending. */
 
   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 auto_mode is true, only keys that can be determined without
  * prompting will be used.
  */
 char *pgp_findKeys (ADDRESS *adrlist, int auto_mode)
 {
   char *keyID, *keylist = NULL;
@@ -1169,17 +1156,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, '@') && 

Reply via email to