Renamed epg-*-start -> epg-start-*.
[elisp/epg.git] / epg.el
diff --git a/epg.el b/epg.el
index 5456f78..176910a 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)))))
 
@@ -423,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)
@@ -488,8 +488,10 @@ 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)
+(defun epg-start-decrypt (context input-file)
   "Initiate a decrypt operation on INPUT-FILE.
 
 If you use this function, you will need to wait for the completion of
@@ -497,12 +499,25 @@ If you use this function, you will need to wait for the completion of
 `epg-reset' to clear a temporaly output file.
 If you are unsure, use synchronous version of this function
 `epg-decrypt-string' instead."
-  (epg-context-set-output-file context (epg-make-temp-file "epg-output"))
-  (epg-start context
+  (epg-context-set-output-file context (epg-make-temp-file "epg-start-output"))
+  (epg context
             (list "--decrypt" input-file))
   (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-start-decrypt 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"))
@@ -510,16 +525,12 @@ 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)))))
 
 ;;;###autoload
-(defun epg-verify-start (context signature &optional string)
+(defun epg-start-verify (context signature &optional string)
   "Initiate a verify operation on SIGNATURE.
 
 For a detached signature, both SIGNATURE and STRING should be string.
@@ -530,18 +541,17 @@ If you use this function, you will need to wait for the completion of
 `epg-reset' to clear a temporaly output file.
 If you are unsure, use synchronous version of this function
 `epg-verify-string' instead."
-  (epg-context-set-output-file context (epg-make-temp-file "epg-output"))
+  (epg-context-set-output-file context (epg-make-temp-file "epg-start-output"))
   (if string
       ;; Detached signature.
       (progn
-       (epg-start context
+       (epg context
                   (append (list "--verify")
                           (list signature "-")))
        (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))))
 
@@ -557,7 +567,7 @@ For a normal or a clear text signature, STRING should be nil."
        (progn
          (if string
              (write-region signature nil input-file))
-         (epg-verify-start context input-file string)
+         (epg-start-verify context input-file string)
          (epg-wait-for-completion context)
          (epg-context-result-for context 'verify))
       (epg-reset context)
@@ -565,7 +575,7 @@ For a normal or a clear text signature, STRING should be nil."
          (delete-file input-file)))))
 
 ;;;###autoload
-(defun epg-sign-start (context string &optional mode)
+(defun epg-start-sign (context string &optional mode)
   "Initiate a sign operation on STRING.
 
 If optional 3rd argument MODE is 'clearsign, it makes a clear text signature.
@@ -577,8 +587,8 @@ If you use this function, you will need to wait for the completion of
 `epg-reset' to clear a temporaly output file.
 If you are unsure, use synchronous version of this function
 `epg-sign-string' instead."
-  (epg-context-set-output-file context (epg-make-temp-file "epg-output"))
-  (epg-start context
+  (epg-context-set-output-file context (epg-make-temp-file "epg-start-output"))
+  (epg context
             (append (list (if (eq 'clearsign)
                               "--clearsign"
                             (if (or (eq mode t) (eq mode 'detached))
@@ -600,13 +610,13 @@ If MODE is t or 'detached, it makes a detached signature.
 Otherwise, it makes a normal signature."
   (unwind-protect
       (progn
-       (epg-sign-start context string mode)
+       (epg-start-sign context string mode)
        (epg-wait-for-completion context)
        (epg-read-output context))
     (epg-reset context)))
 
 ;;;###autoload
-(defun epg-encrypt-start (context string recipients
+(defun epg-start-encrypt (context string recipients
                                  &optional sign always-trust)
   "Initiate a encrypt operation on STRING.
 If RECIPIENTS is nil, it does symmetric encryption.
@@ -616,8 +626,8 @@ If you use this function, you will need to wait for the completion of
 `epg-reset' to clear a temporaly output file.
 If you are unsure, use synchronous version of this function
 `epg-encrypt-string' instead."
-  (epg-context-set-output-file context (epg-make-temp-file "epg-output"))
-  (epg-start context
+  (epg-context-set-output-file context (epg-make-temp-file "epg-start-output"))
+  (epg context
             (append (if always-trust '("--always-trust"))
                     (if recipients '("--encrypt") '("--symmetric"))
                     (if sign
@@ -631,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)))
 
@@ -642,7 +654,7 @@ If you are unsure, use synchronous version of this function
 If RECIPIENTS is nil, it does symmetric encryption."
   (unwind-protect
       (progn
-       (epg-encrypt-start context string recipients sign always-trust)
+       (epg-start-encrypt context string recipients sign always-trust)
        (epg-wait-for-completion context)
        (epg-read-output context))
     (epg-reset context)))