2 (eval-when-compile (require 'pgg))
4 (defun pgg-epg-encrypt-region (start end recipients &optional sign passphrase)
5 "This function is for internal use only.
7 Encrypt the current region between START and END.
9 If optional argument SIGN is non-nil, do a combined sign and encrypt.
11 If optional PASSPHRASE is not specified, it will be obtained from the
12 passphrase cache or user."
13 (let ((context (epg-make-context))
15 (epg-context-set-armor context t)
16 (epg-context-set-textmode context pgg-text-mode)
17 (setq cipher (epg-encrypt-string context (buffer-substring start end)
18 (if pgg-encrypt-for-me
19 (cons pgg-default-user-id recipients)
23 (set-buffer (get-buffer-create pgg-output-buffer))
28 (defun pgg-epg-encrypt-symmetric-region (start end &optional passphrase)
29 "This function is for internal use only.
31 Encrypt the current region between START and END with symmetric cipher.
33 If optional PASSPHRASE is not specified, it will be obtained from the
34 passphrase cache or user."
35 (pgg-epg-encrypt-region start end nil))
37 (defun pgg-epg-decrypt-region (start end &optional passphrase)
38 "This function is for internal use only.
40 Decrypt the current region between START and END.
42 If optional PASSPHRASE is not specified, it will be obtained from the
43 passphrase cache or user."
44 (let ((context (epg-make-context))
46 (epg-context-set-armor context t)
47 (epg-context-set-textmode context pgg-text-mode)
48 (setq plain (epg-decrypt-string context (buffer-substring start end)))
50 (set-buffer (get-buffer-create pgg-output-buffer))
55 (defun pgg-epg-sign-region (start end &optional cleartext passphrase)
56 "This function is for internal use only.
58 Make detached signature from text between START and END.
60 If optional PASSPHRASE is not specified, it will be obtained from the
61 passphrase cache or user."
62 (let ((context (epg-make-context))
64 (epg-context-set-armor context t)
65 (epg-context-set-textmode context pgg-text-mode)
66 (setq signature (epg-sign-string context (buffer-substring start end)
71 (set-buffer (get-buffer-create pgg-output-buffer))
75 (defvar pgg-epg-signature nil)
77 (defun pgg-epg-verify-region (start end &optional signature)
78 "This function is for internal use only.
80 Verify region between START and END as the detached signature SIGNATURE."
81 (let ((context (epg-make-context))
83 (epg-context-set-armor context t)
84 (epg-context-set-textmode context pgg-text-mode)
86 (epg-verify-file context signature (buffer-substring start end))
87 (epg-verify-string context (buffer-substring start end)))
88 (setq signature (reverse (epg-context-result-for context 'verify))
91 (set-buffer (get-buffer-create pgg-errors-buffer))
92 (make-local-variable 'pgg-epg-signature)
93 (setq pgg-epg-signature (car signature))
96 (insert (format "%s: %s %s %s\n"
97 (epg-signature-status (car pointer))
98 (epg-signature-key-id (car pointer))
99 (epg-signature-user-id (car pointer))
100 (epg-signature-validity (car pointer))))
101 (setq pointer (cdr pointer))))
104 (defun pgg-epg-insert-key ()
105 "This function is for internal use only.
107 Insert public key at point."
108 (let ((context (epg-make-context))
110 (epg-context-set-armor context t)
111 (epg-context-set-textmode context pgg-text-mode)
112 (insert (epg-export-keys context pgg-default-user-id))))
114 (defun pgg-epg-snarf-keys-region (start end)
115 "This function is for internal use only.
117 Add all public keys in region between START and END to the keyring."
118 (let ((context (epg-make-context))
120 (epg-context-set-armor context t)
121 (epg-context-set-textmode context pgg-text-mode)
122 (epg-import-keys context (buffer-substring start end))))
124 (defun mml2015-gpg-extract-signature-details ()
125 (if pgg-epg-signature
126 (let* ((expired (eq (epg-signature-status pgg-epg-signature)
128 (signer (cons (epg-signature-key-id pgg-epg-signature)
129 (epg-signature-user-id pgg-epg-signature)))
130 (fprint (epg-signature-fingerprint pgg-epg-signature))
132 (memq (epg-signature-validity pgg-epg-signature)
133 '(marginal fully ultimate))))
134 (cond ((and signer fprint)
136 (unless trust-good-enough-p
137 (concat "\nUntrusted, Fingerprint: "
138 (mml2015-gpg-pretty-print-fpr fprint)))
140 (format "\nWARNING: Signature from expired key (%s)"
143 "From unknown user")))
144 "From unknown user"))
148 ;;; pgg-epg.el ends here