more crypt simplifications
[apps/madmutt.git] / lib-crypt / crypt-gpgme.c
index 07bc706..5bd3173 100644 (file)
@@ -1197,8 +1197,7 @@ static int show_one_sig_status (gpgme_ctx_t ctx, int idx, STATE * s)
 
 /* Do the actual verification step. With IS_SMIME set to true we
    assume S/MIME (surprise!) */
-static int verify_one (BODY * sigbdy, STATE * s,
-                       const char *tempfile, int is_smime)
+int crypt_verify_one(BODY *sigbdy, STATE *s, FILE *fp, int is_smime)
 {
   int badsig = -1;
   int anywarn = 0;
@@ -1215,7 +1214,7 @@ static int verify_one (BODY * sigbdy, STATE * s,
   if (is_smime)
     gpgme_data_set_encoding (signature, GPGME_DATA_ENCODING_BASE64);
 
-  err = gpgme_data_new_from_file (&message, tempfile, 1);
+  err = gpgme_data_new_from_stream(&message, fp);
   if (err) {
     gpgme_data_release (signature);
     mutt_error (_("error allocating data object: %s\n"), gpgme_strerror (err));
@@ -1295,16 +1294,6 @@ static int verify_one (BODY * sigbdy, STATE * s,
   return badsig ? 1 : anywarn ? 2 : 0;
 }
 
-int crypt_pgp_verify_one (BODY * sigbdy, STATE * s, const char *tempfile)
-{
-  return verify_one (sigbdy, s, tempfile, 0);
-}
-
-int crypt_smime_verify_one (BODY * sigbdy, STATE * s, const char *tempfile)
-{
-  return verify_one (sigbdy, s, tempfile, 1);
-}
-
 /*
  * Implementation of `decrypt_part'.
  */
@@ -3689,16 +3678,36 @@ static char *find_keys (address_t * to, address_t * cc, address_t * bcc,
   return (keylist);
 }
 
-char *crypt_pgp_findkeys (address_t * to, address_t * cc, address_t * bcc)
+int crypt_get_keys (HEADER * msg, char **keylist)
 {
-  return find_keys (to, cc, bcc, APPLICATION_PGP);
-}
+  /* Do a quick check to make sure that we can find all of the encryption
+   * keys if the user has requested this service.
+   */
 
-char *crypt_smime_findkeys (address_t * to, address_t * cc, address_t * bcc)
-{
-  return find_keys (to, cc, bcc, APPLICATION_SMIME);
+  *keylist = NULL;
+
+  if (msg->security & ENCRYPT) {
+    if (msg->security & APPLICATION_PGP) {
+      set_option(OPTPGPCHECKTRUST);
+      *keylist = find_keys(msg->env->to, msg->env->cc, msg->env->bcc,
+                           APPLICATION_PGP);
+      unset_option(OPTPGPCHECKTRUST);
+      if (!*keylist)
+          return -1;
+    }
+
+    if (msg->security & APPLICATION_SMIME) {
+      *keylist = find_keys(msg->env->to, msg->env->cc, msg->env->bcc,
+                           APPLICATION_SMIME);
+      if (!*keylist)
+          return -1;
+    }
+  }
+
+  return (0);
 }
 
+
 int crypt_send_menu (HEADER * msg, int *redraw, int is_smime)
 {
   crypt_key_t *p;