1 ;;; pgg-epg.el --- Gnus/PGG backend of EasyPG.
2 ;; Copyright (C) 1999, 2000, 2002, 2003, 2004,
3 ;; 2005, 2006 Free Software Foundation, Inc.
4 ;; Copyright (C) 2006 Daiki Ueno
6 ;; Author: Daiki Ueno <ueno@unixuser.org>
7 ;; Keywords: PGP, GnuPG
9 ;; This file is part of EasyPG.
11 ;; This program is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; This program is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
29 (eval-when-compile (require 'pgg))
31 (defun pgg-epg-encrypt-region (start end recipients &optional sign passphrase)
32 "This function is for internal use only.
34 Encrypt the current region between START and END.
36 If optional argument SIGN is non-nil, do a combined sign and encrypt.
38 If optional PASSPHRASE is not specified, it will be obtained from the
39 passphrase cache or user."
40 (let ((context (epg-make-context))
42 (epg-context-set-armor context t)
43 (epg-context-set-textmode context pgg-text-mode)
44 (setq cipher (epg-encrypt-string context (buffer-substring start end)
45 (if pgg-encrypt-for-me
46 (cons pgg-default-user-id recipients)
50 (set-buffer (get-buffer-create pgg-output-buffer))
55 (defun pgg-epg-encrypt-symmetric-region (start end &optional passphrase)
56 "This function is for internal use only.
58 Encrypt the current region between START and END with symmetric cipher.
60 If optional PASSPHRASE is not specified, it will be obtained from the
61 passphrase cache or user."
62 (pgg-epg-encrypt-region start end nil))
64 (defun pgg-epg-decrypt-region (start end &optional passphrase)
65 "This function is for internal use only.
67 Decrypt the current region between START and END.
69 If optional PASSPHRASE is not specified, it will be obtained from the
70 passphrase cache or user."
71 (let ((context (epg-make-context))
73 (epg-context-set-armor context t)
74 (epg-context-set-textmode context pgg-text-mode)
75 (setq plain (epg-decrypt-string context (buffer-substring start end)))
77 (set-buffer (get-buffer-create pgg-output-buffer))
82 (defun pgg-epg-sign-region (start end &optional cleartext passphrase)
83 "This function is for internal use only.
85 Make detached signature from text between START and END.
87 If optional PASSPHRASE is not specified, it will be obtained from the
88 passphrase cache or user."
89 (let ((context (epg-make-context))
91 (epg-context-set-armor context t)
92 (epg-context-set-textmode context pgg-text-mode)
93 (setq signature (epg-sign-string context (buffer-substring start end)
98 (set-buffer (get-buffer-create pgg-output-buffer))
103 (defvar pgg-epg-verify-results nil)
105 (defun pgg-epg-verify-region (start end &optional signature)
106 "This function is for internal use only.
108 Verify region between START and END as the detached signature SIGNATURE."
109 (let ((context (epg-make-context))
111 (epg-context-set-armor context t)
112 (epg-context-set-textmode context pgg-text-mode)
114 (epg-verify-string context
116 (insert-file-contents signature)
118 (buffer-substring start end))
119 (epg-verify-string context (buffer-substring start end)))
120 (setq verify-results (reverse (epg-context-result-for context 'verify)))
122 (set-buffer (get-buffer-create pgg-errors-buffer))
123 (make-local-variable 'pgg-epg-verify-results)
124 (setq pgg-epg-verify-results (car verify-results))
126 (insert (mapconcat #'epg-verify-result-to-string verify-results "\n")))
129 (defun pgg-epg-insert-key ()
130 "This function is for internal use only.
132 Insert public key at point."
133 (let ((context (epg-make-context))
135 (epg-context-set-armor context t)
136 (epg-context-set-textmode context pgg-text-mode)
137 (insert (epg-export-keys context pgg-default-user-id))))
139 (defun pgg-epg-snarf-keys-region (start end)
140 "This function is for internal use only.
142 Add all public keys in region between START and END to the keyring."
143 (let ((context (epg-make-context))
145 (epg-context-set-armor context t)
146 (epg-context-set-textmode context pgg-text-mode)
147 (epg-import-keys context (buffer-substring start end))))
149 (defun mml2015-gpg-extract-verify-result-details ()
150 (if pgg-epg-verify-result
151 (let* ((expired (eq (epg-verify-result-status pgg-epg-verify-result)
153 (signer (cons (epg-verify-result-key-id pgg-epg-verify-result)
154 (epg-verify-result-user-id pgg-epg-verify-result)))
155 (fprint (epg-verify-result-fingerprint pgg-epg-verify-result))
157 (memq (epg-verify-result-validity pgg-epg-verify-result)
158 '(marginal fully ultimate))))
159 (cond ((and signer fprint)
161 (unless trust-good-enough-p
162 (concat "\nUntrusted, Fingerprint: "
163 (mml2015-gpg-pretty-print-fpr fprint)))
165 (format "\nWARNING: Signature from expired key (%s)"
168 "From unknown user")))
169 "From unknown user"))
173 ;;; pgg-epg.el ends here