From 21596fe950a11148381396d72ca30d9d5bdcf377 Mon Sep 17 00:00:00 2001 From: ueno Date: Sun, 31 Dec 2006 02:03:34 +0000 Subject: [PATCH] * epa.el (epa--read-signature-type): New function. (epa-decrypt): New command. (epa-verify): New command. (epa-sign): New command. (epa-encrypt): New command. --- ChangeLog | 8 ++++ epa.el | 156 +++++++++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 123 insertions(+), 41 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1bae2e3..3643122 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-12-31 Daiki Ueno + + * epa.el (epa--read-signature-type): New function. + (epa-decrypt): New command. + (epa-verify): New command. + (epa-sign): New command. + (epa-encrypt): New command. + 2006-12-29 Daiki Ueno * EasyPG: Version 0.0.9 released. diff --git a/epa.el b/epa.el index 267637d..2af91fc 100644 --- a/epa.el +++ b/epa.el @@ -27,6 +27,8 @@ (require 'font-lock) (require 'widget) (eval-when-compile (require 'wid-edit)) +(require 'mail-utils) +(require 'derived) (defgroup epa nil "The EasyPG Assistant" @@ -642,6 +644,28 @@ If SECRET is non-nil, list secret keys instead of public keys." (epa-display-info (epg-verify-result-to-string (epg-context-result-for context 'verify)))))) +(defun epa--read-signature-type () + (let (type c) + (while (null type) + (message "Signature type (n,c,d,?) ") + (setq c (read-char)) + (cond ((eq c ?c) + (setq type 'clear)) + ((eq c ?d) + (setq type 'detached)) + ((eq c ??) + (with-output-to-temp-buffer "*Help*" + (save-excursion + (set-buffer standard-output) + (insert "\ +n - Create a normal signature +c - Create a cleartext signature +d - Create a detached signature +? - Show this help +")))) + (t + (setq type 'normal)))))) + ;;;###autoload (defun epa-sign-file (file signers mode) "Sign FILE by SIGNERS keys selected." @@ -653,26 +677,7 @@ If SECRET is non-nil, list secret keys instead of public keys." If no one is selected, default secret key is used. " nil t)) (if current-prefix-arg - (catch 'done - (while t - (message "Signature type (n,c,d,?) ") - (let ((c (read-char))) - (cond ((eq c ?c) - (throw 'done 'clear)) - ((eq c ?d) - (throw 'done 'detached)) - ((eq c ??) - (with-output-to-temp-buffer "*Help*" - (save-excursion - (set-buffer standard-output) - (insert "\ -n - Create a normal signature -c - Create a cleartext signature -d - Create a detached signature -? - Show this help -")))) - (t - (throw 'done nil)))))) + (epa--read-signature-type) 'clear))) (let ((signature (concat file (if (eq epa-protocol 'OpenPGP) @@ -774,7 +779,15 @@ Don't use this command in Lisp programs!" (setq coding-system (intern (downcase charset))) (setq coding-system 'utf-8))) (let ((coding-system-for-read coding-system)) - (epa-decrypt-region start end))))))) + (epa-decrypt-region armor-start armor-end))))))) + +;;;###autoload +(defun epa-decrypt () + "Decrypt OpenPGP armors in the current buffer. + +Don't use this command in Lisp programs!" + (interactive) + (epa-decrypt-armor-in-region (point-min) (point-max))) (if (fboundp 'select-safe-coding-system) (defalias 'epa--select-safe-coding-system 'select-safe-coding-system) @@ -826,6 +839,13 @@ Don't use this command in Lisp programs!" (epa-verify-region armor-start armor-end)))))) ;;;###autoload +(defun epa-verify () + "Verify OpenPGP cleartext signed messages in the current buffer. + +Don't use this command in Lisp programs!" + (epa-verify-cleartext-in-region (point-min) (point-max))) + +;;;###autoload (defun epa-sign-region (start end signers mode) "Sign the current region between START and END by SIGNERS keys selected. @@ -843,26 +863,7 @@ Don't use this command in Lisp programs!" If no one is selected, default secret key is used. " nil t)) (if current-prefix-arg - (catch 'done - (while t - (message "Signature type (n,c,d,?) ") - (let ((c (read-char))) - (cond ((eq c ?c) - (throw 'done 'clear)) - ((eq c ?d) - (throw 'done 'detached)) - ((eq c ??) - (with-output-to-temp-buffer "*Help*" - (save-excursion - (set-buffer standard-output) - (insert "\ -n - Create a normal signature -c - Create a cleartext signature -d - Create a detached signature -? - Show this help -")))) - (t - (throw 'done nil)))))) + (epa--read-signature-type) 'clear)))) (save-excursion (let ((context (epg-make-context epa-protocol)) @@ -899,6 +900,32 @@ d - Create a detached signature 'end-open t))))) ;;;###autoload +(defun epa-sign (start end signers mode) + "Sign the current buffer. + +Don't use this command in Lisp programs!" + (interactive + (progn + (goto-char (point-min)) + (if (and (or (eq major-mode 'mail-mode) + (eq (derived-mode-class major-mode) 'mail-mode)) + (search-forward mail-header-separator nil t)) + (forward-line)) + (setq epa-last-coding-system-specified + (or coding-system-for-write + (epa--select-safe-coding-system (point) (point-max)))) + (list (point) (point-max) + (if current-prefix-arg + (epa-select-keys (epg-make-context epa-protocol) + "Select keys for signing. +If no one is selected, default secret key is used. " + nil t)) + (if current-prefix-arg + (epa--read-signature-type) + 'clear)))) + (epa-sign-region start end signers mode)) + +;;;###autoload (defun epa-encrypt-region (start end recipients) "Encrypt the current region between START and END for RECIPIENTS. @@ -944,6 +971,53 @@ If no one is selected, symmetric encryption will be performed. ")))) 'end-open t))))) ;;;###autoload +(defun epa-encrypt (start end recipients) + "Encrypt the current buffer. + +Don't use this command in Lisp programs!" + (interactive + (let (recipients) + (goto-char (point-min)) + (when (or (eq major-mode 'mail-mode) + (eq (derived-mode-class major-mode) 'mail-mode)) + (save-restriction + (narrow-to-region (point) + (progn + (search-forward mail-header-separator nil 0) + (match-beginning 0))) + (setq recipients + (mail-strip-quoted-names + (mapconcat #'identity + (nconc (mail-fetch-field "to" nil nil t) + (mail-fetch-field "cc" nil nil t) + (mail-fetch-field "bcc" nil nil t)) + ",")))) + (if recipients + (setq recipients (delete "" (split-string recipients "[ \t\n]+")))) + (goto-char (point-min)) + (if (search-forward mail-header-separator nil t) + (forward-line))) + (setq epa-last-coding-system-specified + (or coding-system-for-write + (epa--select-safe-coding-system (point) (point-max)))) + (list (point) (point-max) + (if current-prefix-arg + (epa-select-keys + (epg-make-context epa-protocol) + "Select recipients for encryption. +If no one is selected, symmetric encryption will be performed. " + recipients) + (if recipients + (delq nil + (apply #'nconc + (mapcar + (lambda (recipient) + (epg-list-keys (epg-make-context epa-protocol) + (concat "<" recipient ">"))) + recipients)))))))) + (epa-encrypt-region start end recipients)) + +;;;###autoload (defun epa-delete-keys (keys &optional allow-secret) "Delete selected KEYS. -- 1.7.10.4