Fixed.
[elisp/epg.git] / epg.el
diff --git a/epg.el b/epg.el
index 2020ebc..241ee92 100644 (file)
--- a/epg.el
+++ b/epg.el
@@ -262,9 +262,9 @@ This function is for internal use only."
   (with-temp-buffer
     (set-buffer-multibyte nil)
     (if (file-exists-p (epg-context-output-file context))
-       (let ((coding-system-for-read (if (epg-context-output-file context)
+       (let ((coding-system-for-read (if (epg-context-textmode context)
                                          'raw-text
-                                     'binary)))
+                                       'binary)))
          (insert-file-contents (epg-context-output-file context))
          (buffer-string)))))
 
@@ -315,11 +315,17 @@ This function is for internal use only."
   (let ((passphrase
         (funcall (car (epg-context-passphrase-callback-info epg-context))
                  epg-key-id
-                 (cdr (epg-context-passphrase-callback-info epg-context)))))
-    (unwind-protect
-       (if passphrase
-           (process-send-string process (concat passphrase "\n")))
-      (fillarray passphrase 0))))
+                 (cdr (epg-context-passphrase-callback-info epg-context))))
+       string)
+    (if passphrase
+       (unwind-protect
+           (progn
+             (setq string (concat passphrase "\n"))
+             (fillarray passphrase 0)
+             (setq passphrase nil)
+             (process-send-string process string))
+         (if string
+             (fillarray string 0))))))
 
 (defun epg-status-GOODSIG (process string)
   (if (string-match "\\`\\([^ ]+\\) \\(.*\\)" string)
@@ -417,10 +423,10 @@ This function is for internal use only."
 (defun epg-passphrase-callback-function (key-id handback)
   (read-passwd
    (if (eq key-id 'SYM)
-       "GnuPG passphrase for symmetric encryption: "
+       "Passphrase for symmetric encryption: "
      (if (eq key-id 'PIN)
-        "GnuPG passphrase for PIN: "
-       (format "GnuPG passphrase for %s: "
+        "Passphrase for PIN: "
+       (format "Passphrase for %s: "
               (let ((entry (assoc key-id epg-user-id-alist)))
                 (if entry
                     (cdr entry)
@@ -482,6 +488,8 @@ This function is for internal use only."
       (setq alist (cdr alist)))
     (nreverse result)))
 
+(defalias 'epg-make-temp-file 'make-temp-file)
+
 ;;;###autoload
 (defun epg-decrypt-start (context input-file)
   "Initiate a decrypt operation on INPUT-FILE.
@@ -497,6 +505,19 @@ If you are unsure, use synchronous version of this function
   (epg-wait-for-status context '("BEGIN_DECRYPTION")))
 
 ;;;###autoload
+(defun epg-decrypt-file (context input-file)
+  "Decrypt INPUT-FILE and return the plain text."
+  (unwind-protect
+      (progn
+       (epg-decrypt-start context input-file)
+       (epg-wait-for-completion context)
+       (unless (epg-context-result-for context 'decrypt)
+         (epg-read-output context)))
+    (epg-reset context)
+    (if (file-exists-p input-file)
+       (delete-file input-file))))
+
+;;;###autoload
 (defun epg-decrypt-string (context string)
   "Decrypt STRING and return the plain text."
   (let ((input-file (epg-make-temp-file "epg-input"))
@@ -504,11 +525,7 @@ If you are unsure, use synchronous version of this function
     (unwind-protect
        (progn
          (write-region string nil input-file)
-         (epg-decrypt-start context input-file)
-         (epg-wait-for-completion context)
-         (unless (epg-context-result-for context 'decrypt)
-           (epg-read-output context)))
-      (epg-reset context)
+         (epg-decrypt-file context input-file))
       (if (file-exists-p input-file)
          (delete-file input-file)))))
 
@@ -534,8 +551,7 @@ If you are unsure, use synchronous version of this function
        (if (eq (process-status (epg-context-process context)) 'run)
            (process-send-string (epg-context-process context) string)))
     ;; Normal (or cleartext) signature.
-    (epg-start context
-              (list "--verify"))
+    (epg-start context (list "--verify"))
     (if (eq (process-status (epg-context-process context)) 'run)
        (process-send-string (epg-context-process context) signature))))
 
@@ -625,7 +641,9 @@ If you are unsure, use synchronous version of this function
                                      (list "-r" recipient))
                                    recipients))))
   (if sign
-      (epg-wait-for-status context '("BEGIN_SIGNING")))
+      (epg-wait-for-status context '("BEGIN_SIGNING"))
+    (if (null recipients)
+       (epg-wait-for-status context '("BEGIN_ENCRYPTION"))))
   (if (eq (process-status (epg-context-process context)) 'run)
       (process-send-string (epg-context-process context) string)))