* pgg-epg.el (pgg-epg-secret-key-id-list): New variable.
authorueno <ueno>
Thu, 20 Apr 2006 06:47:58 +0000 (06:47 +0000)
committerueno <ueno>
Thu, 20 Apr 2006 06:47:58 +0000 (06:47 +0000)
(pgg-epg-passphrase-callback): New function.

ChangeLog
pgg-epg.el

index 4457242..6bb926d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2006-04-20  Daiki Ueno  <ueno@unixuser.org>
 
+       * pgg-epg.el (pgg-epg-secret-key-id-list): New variable.
+       (pgg-epg-passphrase-callback): New function.
+
        * epa.el (epa-select-keys): Added "Cancel" button.
 
 2006-04-20  Daiki Ueno  <ueno@unixuser.org>
index bc093bb..a1705f5 100644 (file)
 (require 'epg)
 (eval-when-compile (require 'pgg))
 
+(defvar pgg-epg-secret-key-id-list nil)
+
+(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))))
+      (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))))))
+
 (defun pgg-epg-encrypt-region (start end recipients &optional sign passphrase)
   "This function is for internal use only.
 
@@ -41,11 +61,20 @@ passphrase cache or user."
        cipher)
     (epg-context-set-armor context t)
     (epg-context-set-textmode context pgg-text-mode)
-    (setq cipher (epg-encrypt-string context (buffer-substring start end)
-                                    (if pgg-encrypt-for-me
-                                        (cons pgg-default-user-id recipients)
-                                      recipients)
-                                    sign t))
+    (epg-context-set-passphrase-callback context #'pgg-epg-passphrase-callback)
+    (condition-case error
+       (setq cipher
+             (epg-encrypt-string context
+                                 (buffer-substring start end)
+                                 (if pgg-encrypt-for-me
+                                     (cons pgg-default-user-id recipients)
+                                   recipients)
+                                 sign t))
+      (error
+       (while pgg-epg-secret-key-id-list
+        (pgg-remove-passphrase-from-cache (car pgg-epg-secret-key-id-list))
+        (setq pgg-epg-secret-key-id-list (cdr pgg-epg-secret-key-id-list)))
+       (signal (car error) (cdr error))))
     (save-excursion
       (set-buffer (get-buffer-create pgg-output-buffer))
       (erase-buffer)
@@ -72,7 +101,14 @@ passphrase cache or user."
        plain)
     (epg-context-set-armor context t)
     (epg-context-set-textmode context pgg-text-mode)
-    (setq plain (epg-decrypt-string context (buffer-substring start end)))
+    (epg-context-set-passphrase-callback context #'pgg-epg-passphrase-callback)
+    (condition-case error
+       (setq plain (epg-decrypt-string context (buffer-substring start end)))
+      (error
+       (while pgg-epg-secret-key-id-list
+        (pgg-remove-passphrase-from-cache (car pgg-epg-secret-key-id-list))
+        (setq pgg-epg-secret-key-id-list (cdr pgg-epg-secret-key-id-list)))
+       (signal (car error) (cdr error))))
     (save-excursion
       (set-buffer (get-buffer-create pgg-output-buffer))
       (erase-buffer)
@@ -90,10 +126,19 @@ passphrase cache or user."
        signature)
     (epg-context-set-armor context t)
     (epg-context-set-textmode context pgg-text-mode)
-    (setq signature (epg-sign-string context (buffer-substring start end)
-                                    (if cleartext
-                                        'clearsign
-                                      'detached)))
+    (epg-context-set-passphrase-callback context #'pgg-epg-passphrase-callback)
+    (condition-case error
+       (setq signature
+             (epg-sign-string context
+                              (buffer-substring start end)
+                              (if cleartext
+                                  'clearsign
+                                'detached)))
+      (error
+       (while pgg-epg-secret-key-id-list
+        (pgg-remove-passphrase-from-cache (car pgg-epg-secret-key-id-list))
+        (setq pgg-epg-secret-key-id-list (cdr pgg-epg-secret-key-id-list)))
+       (signal (car error) (cdr error))))
     (save-excursion
       (set-buffer (get-buffer-create pgg-output-buffer))
       (erase-buffer)
@@ -145,14 +190,14 @@ Add all public keys in region between START and END to the keyring."
     (epg-import-keys context (buffer-substring start end))))
 
 (defun mml2015-gpg-extract-signature-details ()
-  (if pgg-epg-signature
-      (let* ((expired (eq (epg-signature-status pgg-epg-signature)
+  (if pgg-epg-signatures
+      (let* ((expired (eq (epg-signature-status (car pgg-epg-signatures))
                          'key-expired))
-            (signer (cons (epg-signature-key-id pgg-epg-signature)
-                          (epg-signature-user-id pgg-epg-signature)))
-            (fprint (epg-signature-fingerprint pgg-epg-signature))
+            (signer (cons (epg-signature-key-id (car pgg-epg-signatures))
+                          (epg-signature-user-id (car pgg-epg-signatures))))
+            (fprint (epg-signature-fingerprint (car pgg-epg-signatures)))
             (trust-good-enough-p
-             (memq (epg-signature-validity pgg-epg-signature)
+             (memq (epg-signature-validity (car pgg-epg-signatures))
                    '(marginal fully ultimate))))
        (cond ((and signer fprint)
               (concat (cdr signer)