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))
102 (defvar pgg-epg-signature nil)
104 (defun pgg-epg-verify-region (start end &optional signature)
105 "This function is for internal use only.
107 Verify region between START and END as the detached signature SIGNATURE."
108 (let ((context (epg-make-context))
110 (epg-context-set-armor context t)
111 (epg-context-set-textmode context pgg-text-mode)
113 (epg-verify-file context signature (buffer-substring start end))
114 (epg-verify-string context (buffer-substring start end)))
115 (setq signature (reverse (epg-context-result-for context 'verify))
118 (set-buffer (get-buffer-create pgg-errors-buffer))
119 (make-local-variable 'pgg-epg-signature)
120 (setq pgg-epg-signature (car signature))
123 (insert (format "%s: %s %s %s\n"
124 (epg-signature-status (car pointer))
125 (epg-signature-key-id (car pointer))
126 (epg-signature-user-id (car pointer))
127 (epg-signature-validity (car pointer))))
128 (setq pointer (cdr pointer))))
131 (defun pgg-epg-insert-key ()
132 "This function is for internal use only.
134 Insert public key at point."
135 (let ((context (epg-make-context))
137 (epg-context-set-armor context t)
138 (epg-context-set-textmode context pgg-text-mode)
139 (insert (epg-export-keys context pgg-default-user-id))))
141 (defun pgg-epg-snarf-keys-region (start end)
142 "This function is for internal use only.
144 Add all public keys in region between START and END to the keyring."
145 (let ((context (epg-make-context))
147 (epg-context-set-armor context t)
148 (epg-context-set-textmode context pgg-text-mode)
149 (epg-import-keys context (buffer-substring start end))))
151 (defun mml2015-gpg-extract-signature-details ()
152 (if pgg-epg-signature
153 (let* ((expired (eq (epg-signature-status pgg-epg-signature)
155 (signer (cons (epg-signature-key-id pgg-epg-signature)
156 (epg-signature-user-id pgg-epg-signature)))
157 (fprint (epg-signature-fingerprint pgg-epg-signature))
159 (memq (epg-signature-validity pgg-epg-signature)
160 '(marginal fully ultimate))))
161 (cond ((and signer fprint)
163 (unless trust-good-enough-p
164 (concat "\nUntrusted, Fingerprint: "
165 (mml2015-gpg-pretty-print-fpr fprint)))
167 (format "\nWARNING: Signature from expired key (%s)"
170 "From unknown user")))
171 "From unknown user"))
175 ;;; pgg-epg.el ends here