(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.
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)
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)
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)
(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)