* epg-config.el (epg-debug): Moved from epg.el.
[elisp/epg.git] / epg.el
diff --git a/epg.el b/epg.el
index 3615cb1..29f78f8 100644 (file)
--- a/epg.el
+++ b/epg.el
@@ -38,7 +38,6 @@
 (defvar epg-pending-status-list nil)
 (defvar epg-key-id nil)
 (defvar epg-context nil)
-(defvar epg-debug nil)
 (defvar epg-debug-buffer nil)
 
 ;; from gnupg/include/cipher.h
@@ -933,7 +932,8 @@ This function is for internal use only."
           (string-match "\\`passphrase\\." string))
       (let (inhibit-quit
            passphrase
-           passphrase-with-new-line)
+           passphrase-with-new-line
+           encoded-passphrase-with-new-line)
        (unwind-protect
            (condition-case nil
                (progn
@@ -948,10 +948,21 @@ This function is for internal use only."
                             (cdr (epg-context-passphrase-callback context)))))
                  (when passphrase
                    (setq passphrase-with-new-line (concat passphrase "\n"))
-                   (fillarray passphrase 0)
+                   (epg--clear-string passphrase)
                    (setq passphrase nil)
+                   (if epg-locale-coding-system
+                       (progn
+                         (setq encoded-passphrase-with-new-line
+                               (encode-coding-string
+                                passphrase-with-new-line
+                                epg-locale-coding-system))
+                         (epg--clear-string passphrase-with-new-line)
+                         (setq passphrase-with-new-line nil))
+                     (setq encoded-passphrase-with-new-line
+                           passphrase-with-new-line
+                           passphrase-with-new-line nil))
                    (process-send-string (epg-context-process context)
-                                        passphrase-with-new-line)))
+                                        encoded-passphrase-with-new-line)))
              (quit
               (epg-context-set-result-for
                context 'error
@@ -959,9 +970,11 @@ This function is for internal use only."
                      (epg-context-result-for context 'error)))
               (delete-process (epg-context-process context))))
          (if passphrase
-             (fillarray passphrase 0))
+             (epg--clear-string passphrase))
          (if passphrase-with-new-line
-             (fillarray passphrase-with-new-line 0))))))
+             (epg--clear-string passphrase-with-new-line))
+         (if encoded-passphrase-with-new-line
+             (epg--clear-string encoded-passphrase-with-new-line))))))
 
 (defun epg--status-GET_BOOL (context string)
   (let ((entry (assoc string epg-prompt-alist))
@@ -1294,7 +1307,9 @@ This function is for internal use only."
   (message "%s: %d%%/%d%%" what current total))
 
 (defun epg--list-keys-1 (context name mode)
-  (let ((args (append (list "--with-colons" "--no-greeting" "--batch"
+  (let ((args (append (if epg-gpg-home-directory
+                         (list "--homedir" epg-gpg-home-directory))
+                     (list "--with-colons" "--no-greeting" "--batch"
                            "--with-fingerprint"
                            "--with-fingerprint"
                            (if (memq mode '(t secret))
@@ -1471,6 +1486,11 @@ You can then use `write-region' to write new data into the file."
             (file-directory-p tempdir)
             (delete-directory tempdir))))))
 
+(if (fboundp 'clear-string)
+    (defalias 'epg--clear-string 'clear-string)
+  (defun epg--clear-string (string)
+    (fillarray string 0)))
+
 ;;;###autoload
 (defun epg-cancel (context)
   (if (buffer-live-p (process-buffer (epg-context-process context)))