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