From a9b1f2f3d182b4a37bba42df4ba759ef1486b2f7 Mon Sep 17 00:00:00 2001 From: ueno Date: Thu, 25 May 2006 06:55:13 +0000 Subject: [PATCH] * epa.el (epa-decrypt-region): New command. (epa-verify-region): New command. --- ChangeLog | 2 ++ epa.el | 54 +++++++++++++++++++++++++++++++++++------------------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index cda6f36..c476c69 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ * epa.el (epa-decrypt-file): Display verify result if the message is signed. + (epa-decrypt-region): New command. + (epa-verify-region): New command. (epa-decrypt-armor-in-region): New command. (epa-verify-armor-in-region): New command. (epa-sign-region): New command. diff --git a/epa.el b/epa.el index 12b5740..d56777c 100644 --- a/epa.el +++ b/epa.el @@ -548,6 +548,25 @@ If no one is selected, symmetric encryption will be performed. "))) (message "Encrypting %s...done" (file-name-nondirectory file)))) ;;;###autoload +(defun epa-decrypt-region (start end) + "Decrypt the current region between START and END." + (interactive "r") + (save-excursion + (let ((context (epg-make-context)) + charset plain coding-system) + (message "Decrypting...") + (setq plain (epg-decrypt-string context + (buffer-substring start end))) + (message "Decrypting...done") + (delete-region start end) + (goto-char start) + (insert (decode-coding-string plain coding-system-for-read)) + (if (epg-context-result-for context 'verify) + (message "%s" + (epg-verify-result-to-string + (epg-context-result-for context 'verify))))))) + +;;;###autoload (defun epa-decrypt-armor-in-region (start end) "Decrypt OpenPGP armors in the current region between START and END." (interactive "r") @@ -565,23 +584,26 @@ If no one is selected, symmetric encryption will be performed. "))) (goto-char armor-start) (if (re-search-forward "^Charset: \\(.*\\)" armor-end t) (setq charset (match-string 1))) - (message "Decrypting...") - (setq plain (epg-decrypt-string - (epg-make-context) - (buffer-substring armor-start armor-end))) - (message "Decrypting...done") - (delete-region armor-start armor-end) - (goto-char armor-start) (if coding-system-for-read (setq coding-system coding-system-for-read) (if charset (setq coding-system (intern (downcase charset))) (setq coding-system 'utf-8))) - (insert (decode-coding-string plain coding-system)) - (if (epg-context-result-for context 'verify) - (message "%s" - (epg-verify-result-to-string - (epg-context-result-for context 'verify))))))))) + (let ((coding-system-for-read coding-system)) + (epa-decrypt-region start end))))))) + +;;;###autoload +(defun epa-verify-region (start end) + "Verify the current region between START and END." + (interactive "r") + (let ((context (epg-make-context))) + (epg-verify-string context + (encode-coding-string + (buffer-substring start end) + coding-system-for-write)) + (message "%s" + (epg-verify-result-to-string + (epg-context-result-for context 'verify))))) ;;;###autoload (defun epa-verify-armor-in-region (start end) @@ -608,13 +630,7 @@ If no one is selected, symmetric encryption will be performed. "))) nil t))) (unless armor-end (error "No armor tail")) - (epg-verify-string (epg-make-context) - (encode-coding-string - (buffer-substring armor-start armor-end) - coding-system-for-write)) - (message "%s" - (epg-verify-result-to-string - (epg-context-result-for context 'verify)))))))) + (epa-verify-region armor-start armor-end)))))) ;;;###autoload (defun epa-sign-region (start end signers mode) -- 1.7.10.4