Fixed passphrase caching.
authorueno <ueno>
Thu, 20 Apr 2006 08:12:39 +0000 (08:12 +0000)
committerueno <ueno>
Thu, 20 Apr 2006 08:12:39 +0000 (08:12 +0000)
pgg-epg.el

index a1705f5..39167da 100644 (file)
 
 (defun pgg-epg-passphrase-callback (key-id ignore)
   (if (eq key-id 'SYM)
-      (pgg-read-passphrase "GnuPG passphrase for symmetric encryption: ")
-    (let ((passphrase
-          (pgg-read-passphrase
-           (format "GnuPG passphrase for %s: "
-                   (if entry
-                       (cdr entry)
-                     pgg-gpg-key-id))
-           (if (eq pgg-gpg-key-id 'PIN)
-               "PIN"
-             pgg-gpg-key-id))))
+      (epg-passphrase-callback-function key-id nil)
+    (let* ((entry (assoc key-id epg-user-id-alist))
+          (passphrase
+           (pgg-read-passphrase
+            (format "GnuPG passphrase for %s: "
+                    (if entry
+                        (cdr entry)
+                      key-id))
+            (if (eq key-id 'PIN)
+                "PIN"
+              key-id))))
       (when passphrase
        (pgg-add-passphrase-to-cache key-id passphrase)
-       (copy-sequence passphrase)
        (setq pgg-epg-secret-key-id-list
-             (cons key-id pgg-epg-secret-key-id-list))))))
+             (cons key-id pgg-epg-secret-key-id-list))
+       (copy-sequence passphrase)))))
 
 (defun pgg-epg-encrypt-region (start end recipients &optional sign passphrase)
   "This function is for internal use only.
@@ -69,7 +70,8 @@ passphrase cache or user."
                                  (if pgg-encrypt-for-me
                                      (cons pgg-default-user-id recipients)
                                    recipients)
-                                 sign t))
+                                 sign t)
+             pgg-epg-secret-key-id-list nil)
       (error
        (while pgg-epg-secret-key-id-list
         (pgg-remove-passphrase-from-cache (car pgg-epg-secret-key-id-list))
@@ -103,7 +105,8 @@ passphrase cache or user."
     (epg-context-set-textmode context pgg-text-mode)
     (epg-context-set-passphrase-callback context #'pgg-epg-passphrase-callback)
     (condition-case error
-       (setq plain (epg-decrypt-string context (buffer-substring start end)))
+       (setq plain (epg-decrypt-string context (buffer-substring start end))
+             pgg-epg-secret-key-id-list nil)
       (error
        (while pgg-epg-secret-key-id-list
         (pgg-remove-passphrase-from-cache (car pgg-epg-secret-key-id-list))
@@ -133,7 +136,8 @@ passphrase cache or user."
                               (buffer-substring start end)
                               (if cleartext
                                   'clearsign
-                                'detached)))
+                                'detached))
+             pgg-epg-secret-key-id-list nil)
       (error
        (while pgg-epg-secret-key-id-list
         (pgg-remove-passphrase-from-cache (car pgg-epg-secret-key-id-list))