Fix timing problem of Bug#2412.
[bpt/emacs.git] / lisp / epg.el
index b7d9732..3c80ef9 100644 (file)
@@ -1,6 +1,6 @@
 ;;; epg.el --- the EasyPG Library
 ;; Copyright (C) 1999, 2000, 2002, 2003, 2004,
-;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;;   2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 
 ;; Author: Daiki Ueno <ueno@unixuser.org>
 ;; Keywords: PGP, GnuPG
   (cons 'epg-context
        (vector (or protocol 'OpenPGP) armor textmode include-certs
                cipher-algorithm digest-algorithm compress-algorithm
-               #'epg-passphrase-callback-function
+               (list #'epg-passphrase-callback-function)
                nil
                nil nil nil nil nil nil)))
 
@@ -328,7 +328,9 @@ This function is for internal use only."
   "Set the function used to query passphrase."
   (unless (eq (car-safe context) 'epg-context)
     (signal 'wrong-type-argument (list 'epg-context-p context)))
-  (aset (cdr context) 7 passphrase-callback))
+  (aset (cdr context) 7 (if (consp passphrase-callback)
+                           passphrase-callback
+                         (list passphrase-callback))))
 
 (defun epg-context-set-progress-callback (context
                                          progress-callback)
@@ -336,7 +338,9 @@ This function is for internal use only."
 If optional argument HANDBACK is specified, it is passed to PROGRESS-CALLBACK."
   (unless (eq (car-safe context) 'epg-context)
     (signal 'wrong-type-argument (list 'epg-context-p context)))
-  (aset (cdr context) 8 progress-callback))
+  (aset (cdr context) 8 (if (consp progress-callback)
+                           progress-callback
+                         (list progress-callback))))
 
 (defun epg-context-set-signers (context signers)
   "Set the list of key-id for signing."
@@ -1164,12 +1168,15 @@ This function is for internal use only."
     (setq epg-pending-status-list status-list)
     (while (and (eq (process-status (epg-context-process context)) 'run)
                epg-pending-status-list)
-      (accept-process-output (epg-context-process context) 1))))
+      (accept-process-output (epg-context-process context) 1))
+    (if epg-pending-status-list
+       (epg-context-set-result-for context 'error 'exit))))
 
 (defun epg-wait-for-completion (context)
   "Wait until the `epg-gpg-program' process completes."
   (while (eq (process-status (epg-context-process context)) 'run)
-    (accept-process-output (epg-context-process context) 1)))
+    (accept-process-output (epg-context-process context) 1))
+  (sleep-for 0.1))
 
 (defun epg-reset (context)
   "Reset the CONTEXT."
@@ -1239,13 +1246,10 @@ This function is for internal use only."
              (progn
                (setq passphrase
                      (funcall
-                      (if (consp (epg-context-passphrase-callback context))
-                          (car (epg-context-passphrase-callback context))
-                        (epg-context-passphrase-callback context))
+                      (car (epg-context-passphrase-callback context))
                       context
                       epg-key-id
-                      (if (consp (epg-context-passphrase-callback context))
-                          (cdr (epg-context-passphrase-callback context)))))
+                      (cdr (epg-context-passphrase-callback context))))
                (when passphrase
                  (setq passphrase-with-new-line (concat passphrase "\n"))
                  (epg--clear-string passphrase)
@@ -1493,16 +1497,13 @@ This function is for internal use only."
   (if (and (epg-context-progress-callback context)
           (string-match "\\`\\([^ ]+\\) \\([^ ]\\) \\([0-9]+\\) \\([0-9]+\\)"
                         string))
-      (funcall (if (consp (epg-context-progress-callback context))
-                  (car (epg-context-progress-callback context))
-                (epg-context-progress-callback context))
+      (funcall (car (epg-context-progress-callback context))
               context
               (match-string 1 string)
               (match-string 2 string)
               (string-to-number (match-string 3 string))
               (string-to-number (match-string 4 string))
-              (if (consp (epg-context-progress-callback context))
-                  (cdr (epg-context-progress-callback context))))))
+              (cdr (epg-context-progress-callback context)))))
 
 (defun epg--status-ENC_TO (context string)
   (if (string-match "\\`\\([0-9A-Za-z]+\\) \\([0-9]+\\) \\([0-9]+\\)" string)
@@ -2015,8 +2016,12 @@ If you are unsure, use synchronous version of this function
            (process-send-eof (epg-context-process context))))
     ;; Normal (or cleartext) signature.
     (if (epg-data-file signature)
-       (epg--start context (list "--" (epg-data-file signature)))
-      (epg--start context '("-"))
+       (epg--start context (if (eq (epg-context-protocol context) 'CMS)
+                               (list "--verify" "--" (epg-data-file signature))
+                             (list "--" (epg-data-file signature))))
+      (epg--start context (if (eq (epg-context-protocol context) 'CMS)
+                             '("--verify" "-")
+                           '("-")))
       (if (eq (process-status (epg-context-process context)) 'run)
          (process-send-string (epg-context-process context)
                               (epg-data-string signature)))