* epa.el (epa-verify-region): New command.
authorueno <ueno>
Thu, 25 May 2006 05:50:28 +0000 (05:50 +0000)
committerueno <ueno>
Thu, 25 May 2006 05:50:28 +0000 (05:50 +0000)
ChangeLog
epa.el

index ad5496e..e0f1fce 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,7 @@
        * epa.el (epa-decrypt-file): Display verify result if the message
        is signed.
        (epa-decrypt-region): New command.
+       (epa-verify-region): New command.
 
 2006-05-11  Daiki Ueno  <ueno@unixuser.org>
 
diff --git a/epa.el b/epa.el
index b9524d7..6ebf0ac 100644 (file)
--- a/epa.el
+++ b/epa.el
@@ -625,7 +625,7 @@ If LOCAL is non-nil, the signature is marked as non exportable."
          (unless armor-end
            (error "No armor tail"))
          (goto-char armor-start)
-         (if (re-search-forward "^Charset: \\(.*\\)" nil t)
+         (if (re-search-forward "^Charset: \\(.*\\)" armor-end t)
              (setq charset (match-string 1)))
          (setq context (epg-make-context)
                plain (epg-decrypt-string
@@ -644,6 +644,40 @@ If LOCAL is non-nil, the signature is marked as non exportable."
                       (epg-verify-result-to-string
                        (epg-context-result-for context 'verify)))))))))
 
+;;;###autoload
+(defun epa-verify-region (start end)
+  "Verify OpenPGP armors in the current region between START and END."
+  (interactive "r")
+  (save-excursion
+    (save-restriction
+      (narrow-to-region start end)
+      (goto-char start)
+      (let (armor-start armor-end context)
+       (while (re-search-forward "-----BEGIN PGP\\( SIGNED\\)? MESSAGE-----$"
+                                 nil t)
+         (setq armor-start (match-beginning 0))
+         (if (match-beginning 1)       ;cleartext signed message
+             (progn
+               (unless (re-search-forward "^-----BEGIN PGP SIGNATURE-----$"
+                                          nil t)
+                 (error "Invalid cleartext signed message"))
+               (setq armor-end (re-search-forward
+                                "^-----END PGP SIGNATURE-----$"
+                                nil t)))
+           (setq armor-end (re-search-forward
+                            "^-----END PGP MESSAGE-----$"
+                            nil t)))
+         (unless armor-end
+           (error "No armor tail"))
+         (setq context (epg-make-context))
+         (epg-verify-string 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))))))))
+
 (provide 'epa)
 
 ;;; epa.el ends here