From d700e937e37d3cf27db817e402133489fe762908 Mon Sep 17 00:00:00 2001 From: ueno Date: Wed, 3 Nov 1999 06:52:37 +0000 Subject: [PATCH] (lookup-key): New generic function. (encrypt-region): Use `lookup-key'; cache passphrase if the encryption has been done successfully. (sign-region): Likewise. (decrypt-region): Use `lookup-key'. --- pgg-pgp.el | 48 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/pgg-pgp.el b/pgg-pgp.el index 7529c5c..1db8d65 100644 --- a/pgg-pgp.el +++ b/pgg-pgp.el @@ -111,12 +111,32 @@ ) )) +(luna-define-method lookup-key ((scheme pgg-scheme-pgp) string) + (let ((args (list "+batchmode" "+language=en" "-kv" string))) + (pgg-pgp-process-region (point)(point) nil + pgg-pgp-program args) + (with-current-buffer pgg-output-buffer + (goto-char (point-min)) + (cond + ((re-search-forward "^pub\\s +[0-9]+/" nil t);PGP 2.* + (buffer-substring (point)(+ 8 (point)))) + ((re-search-forward "^Type" nil t);PGP 6.* + (beginning-of-line 2) + (substring + (nth 2 (split-string + (buffer-substring (point) + (progn (end-of-line) (point))) + )) + 2)))) + )) + (luna-define-method encrypt-region ((scheme pgg-scheme-pgp) start end recipients) (let* ((pgg-pgp-user-id pgg-default-user-id) (passphrase (pgg-read-passphrase - (format "PGP passphrase for %s: " pgg-pgp-user-id))) + (format "PGP passphrase for %s: " pgg-pgp-user-id) + (luna-send scheme 'lookup-key scheme pgg-pgp-user-id))) (args `("+encrypttoself=off +verbose=1" "+batchmode" "+language=us" "-fate" @@ -126,8 +146,14 @@ (pgg-pgp-process-region start end passphrase pgg-pgp-program args) (with-current-buffer pgg-output-buffer - (when (zerop (buffer-size)) - (insert-buffer-substring pgg-errors-buffer))) + (if (zerop (buffer-size)) + (insert-buffer-substring pgg-errors-buffer) + (let ((packet + (cdr (assq 1 (pgg-parse-armor-region + (point-min)(point-max)))))) + (pgg-add-passphrase-cache + (cdr (assq 'key-identifier packet)) + passphrase)))) )) (luna-define-method decrypt-region ((scheme pgg-scheme-pgp) @@ -135,7 +161,8 @@ (let* ((pgg-pgp-user-id pgg-default-user-id) (passphrase (pgg-read-passphrase - (format "PGP passphrase for %s: " pgg-pgp-user-id))) + (format "PGP passphrase for %s: " pgg-pgp-user-id) + (luna-send scheme 'lookup-key scheme pgg-pgp-user-id))) (args '("+verbose=1" "+batchmode" "+language=us" "-f"))) (pgg-pgp-process-region start end passphrase @@ -150,15 +177,22 @@ (let* ((pgg-pgp-user-id pgg-default-user-id) (passphrase (pgg-read-passphrase - (format "PGP passphrase for %s: " pgg-pgp-user-id))) + (format "PGP passphrase for %s: " pgg-pgp-user-id) + (luna-send scheme 'lookup-key scheme pgg-pgp-user-id))) (args (list "-fbast" "+verbose=1" "+language=us" "+batchmode" "-u" pgg-pgp-user-id))) (pgg-pgp-process-region start end passphrase pgg-pgp-program args) (with-current-buffer pgg-output-buffer - (when (zerop (buffer-size)) - (insert-buffer-substring pgg-errors-buffer))) + (if (zerop (buffer-size)) + (insert-buffer-substring pgg-errors-buffer) + (let ((packet + (cdr (assq 2 (pgg-parse-armor-region + (point-min)(point-max)))))) + (pgg-add-passphrase-cache + (cdr (assq 'key-identifier packet)) + passphrase)))) )) (luna-define-method verify-region ((scheme pgg-scheme-pgp) -- 1.7.10.4