annotate lisp/epa-file.el @ 94417:1a8916b995cf

* epa-file.el (auto-encryption-mode): Rename from epa-file-mode. (epa-file-handler): Put 'safe-magic and 'operations properties. * epa.el (epa-global-minor-modes, epa-mode, epa-menu) (epa-menu-items): Remove. * epa-dired.el (epa-dired-do-decrypt, epa-dired-do-verify) (epa-dired-do-sign, epa-dired-do-encrypt): Add autoload cookie. (epa-dired-mode, epa-global-dired-mode): Remove. * dired.el (dired-mode-map): Bind encryption/decryption commands. * menu-bar.el (menu-bar-encryption-decryption-menu): New menu item. * files.el (insert-file-contents-literally): Inhibit epa-file-handler.
author Dan Nicolaescu <dann@ics.uci.edu>
date Sun, 27 Apr 2008 19:49:15 +0000
parents d876f5372472
children 1ea022d5b378
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
91647
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
1 ;;; epa-file.el --- the EasyPG Assistant, transparent file encryption
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
2 ;; Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc.
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
3
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
5 ;; Keywords: PGP, GnuPG
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
6
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
8
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
11 ;; the Free Software Foundation; either version 3, or (at your option)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
12 ;; any later version.
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
13
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
17 ;; GNU General Public License for more details.
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
18
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
21 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
22 ;; Boston, MA 02110-1301, USA.
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
23
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
24 ;;; Code:
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
25
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
26 (require 'epa)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
27
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
28 (defgroup epa-file nil
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
29 "The EasyPG Assistant hooks for transparent file encryption"
91703
bda1e76bc03b * epa.el (epa-faces, epa):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 91687
diff changeset
30 :version "23.1"
91647
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
31 :group 'epa)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
32
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
33 (defun epa-file--file-name-regexp-set (variable value)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
34 (set-default variable value)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
35 (if (fboundp 'epa-file-name-regexp-update)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
36 (epa-file-name-regexp-update)))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
37
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
38 (defcustom epa-file-name-regexp "\\.gpg\\(~\\|\\.~[0-9]+~\\)?\\'"
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
39 "Regexp which matches filenames to be encrypted with GnuPG.
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
40
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
41 If you set this outside Custom while epa-file is already enabled, you
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
42 have to call `epa-file-name-regexp-update' after setting it to
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
43 properly update file-name-handler-alist. Setting this through Custom
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
44 does that automatically."
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
45 :type 'regexp
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
46 :group 'epa-file
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
47 :set 'epa-file--file-name-regexp-set)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
48
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
49 (defcustom epa-file-cache-passphrase-for-symmetric-encryption nil
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
50 "If non-nil, cache passphrase for symmetric encryption."
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
51 :type 'boolean
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
52 :group 'epa-file)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
53
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
54 (defcustom epa-file-inhibit-auto-save t
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
55 "If non-nil, disable auto-saving when opening an encrypted file."
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
56 :type 'boolean
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
57 :group 'epa-file)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
58
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
59 (defcustom epa-file-select-keys nil
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
60 "If non-nil, always asks user to select recipients."
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
61 :type 'boolean
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
62 :group 'epa-file)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
63
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
64 (defvar epa-file-encrypt-to nil
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
65 "*Recipient(s) used for encrypting files.
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
66 May either be a string or a list of strings.")
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
67
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
68 ;;;###autoload
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
69 (put 'epa-file-encrypt-to 'safe-local-variable
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
70 (lambda (val)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
71 (or (stringp val)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
72 (and (listp val)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
73 (catch 'safe
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
74 (mapc (lambda (elt)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
75 (unless (stringp elt)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
76 (throw 'safe nil)))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
77 val)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
78 t)))))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
79
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
80 ;;;###autoload
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
81 (put 'epa-file-encrypt-to 'permanent-local t)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
82
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
83 (defvar epa-file-handler
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
84 (cons epa-file-name-regexp 'epa-file-handler))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
85
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
86 (defvar epa-file-auto-mode-alist-entry
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
87 (list epa-file-name-regexp nil 'epa-file))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
88
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
89 (defvar epa-file-passphrase-alist nil)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
90
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
91 (eval-and-compile
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
92 (if (fboundp 'encode-coding-string)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
93 (defalias 'epa-file--encode-coding-string 'encode-coding-string)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
94 (defalias 'epa-file--encode-coding-string 'identity)))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
95
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
96 (eval-and-compile
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
97 (if (fboundp 'decode-coding-string)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
98 (defalias 'epa-file--decode-coding-string 'decode-coding-string)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
99 (defalias 'epa-file--decode-coding-string 'identity)))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
100
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
101 (defun epa-file-name-regexp-update ()
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
102 (interactive)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
103 (unless (equal (car epa-file-handler) epa-file-name-regexp)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
104 (setcar epa-file-handler epa-file-name-regexp)))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
105
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
106 (defun epa-file-passphrase-callback-function (context key-id file)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
107 (if (and epa-file-cache-passphrase-for-symmetric-encryption
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
108 (eq key-id 'SYM))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
109 (progn
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
110 (setq file (file-truename file))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
111 (let ((entry (assoc file epa-file-passphrase-alist))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
112 passphrase)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
113 (or (copy-sequence (cdr entry))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
114 (progn
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
115 (unless entry
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
116 (setq entry (list file)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
117 epa-file-passphrase-alist
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
118 (cons entry
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
119 epa-file-passphrase-alist)))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
120 (setq passphrase (epa-passphrase-callback-function context
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
121 key-id nil))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
122 (setcdr entry (copy-sequence passphrase))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
123 passphrase))))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
124 (epa-passphrase-callback-function context key-id nil)))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
125
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
126 (defun epa-file-handler (operation &rest args)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
127 (save-match-data
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
128 (let ((op (get operation 'epa-file)))
94417
1a8916b995cf * epa-file.el (auto-encryption-mode): Rename from epa-file-mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93002
diff changeset
129 (if (and op
1a8916b995cf * epa-file.el (auto-encryption-mode): Rename from epa-file-mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93002
diff changeset
130 (if (and (eq operation 'insert-file-contents)
1a8916b995cf * epa-file.el (auto-encryption-mode): Rename from epa-file-mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93002
diff changeset
131
1a8916b995cf * epa-file.el (auto-encryption-mode): Rename from epa-file-mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93002
diff changeset
132 (y-or-n-p ""
91647
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
133 (apply op args)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
134 (epa-file-run-real-handler operation args)))))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
135
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
136 (defun epa-file-run-real-handler (operation args)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
137 (let ((inhibit-file-name-handlers
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
138 (cons 'epa-file-handler
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
139 (and (eq inhibit-file-name-operation operation)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
140 inhibit-file-name-handlers)))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
141 (inhibit-file-name-operation operation))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
142 (apply operation args)))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
143
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
144 (defun epa-file-decode-and-insert (string file visit beg end replace)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
145 (if (fboundp 'decode-coding-inserted-region)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
146 (save-restriction
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
147 (narrow-to-region (point) (point))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
148 (let ((multibyte enable-multibyte-characters))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
149 (set-buffer-multibyte nil)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
150 (insert string)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
151 (set-buffer-multibyte multibyte)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
152 (decode-coding-inserted-region
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
153 (point-min) (point-max)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
154 (substring file 0 (string-match epa-file-name-regexp file))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
155 visit beg end replace)))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
156 (insert (epa-file--decode-coding-string string (or coding-system-for-read
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
157 'undecided)))))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
158
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
159 (defvar last-coding-system-used)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
160 (defun epa-file-insert-file-contents (file &optional visit beg end replace)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
161 (barf-if-buffer-read-only)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
162 (if (and visit (or beg end))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
163 (error "Attempt to visit less than an entire file"))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
164 (setq file (expand-file-name file))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
165 (let* ((local-copy
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
166 (condition-case inl
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
167 (epa-file-run-real-handler #'file-local-copy (list file))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
168 (error)))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
169 (local-file (or local-copy file))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
170 (context (epg-make-context))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
171 string length entry)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
172 (if visit
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
173 (setq buffer-file-name file))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
174 (epg-context-set-passphrase-callback
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
175 context
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
176 (cons #'epa-file-passphrase-callback-function
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
177 local-file))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
178 (epg-context-set-progress-callback context
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
179 #'epa-progress-callback-function)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
180 (unwind-protect
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
181 (progn
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
182 (if replace
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
183 (goto-char (point-min)))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
184 (condition-case error
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
185 (setq string (epg-decrypt-file context local-file nil))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
186 (error
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
187 (if (setq entry (assoc file epa-file-passphrase-alist))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
188 (setcdr entry nil))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
189 (signal 'file-error
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
190 (cons "Opening input file" (cdr error)))))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
191 (make-local-variable 'epa-file-encrypt-to)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
192 (setq epa-file-encrypt-to
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
193 (mapcar #'car (epg-context-result-for context 'encrypted-to)))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
194 (if (or beg end)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
195 (setq string (substring string (or beg 0) end)))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
196 (save-excursion
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
197 (save-restriction
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
198 (narrow-to-region (point) (point))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
199 (epa-file-decode-and-insert string file visit beg end replace)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
200 (setq length (- (point-max) (point-min))))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
201 (if replace
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
202 (delete-region (point) (point-max)))))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
203 (if (and local-copy
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
204 (file-exists-p local-copy))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
205 (delete-file local-copy)))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
206 (list file length)))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
207 (put 'insert-file-contents 'epa-file 'epa-file-insert-file-contents)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
208
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
209 (defun epa-file-write-region (start end file &optional append visit lockname
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
210 mustbenew)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
211 (if append
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
212 (error "Can't append to the file."))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
213 (setq file (expand-file-name file))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
214 (let* ((coding-system (or coding-system-for-write
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
215 (if (fboundp 'select-safe-coding-system)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
216 ;; This is needed since Emacs 22 has
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
217 ;; no-conversion setting for *.gpg in
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
218 ;; `auto-coding-alist'.
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
219 (let ((buffer-file-name
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
220 (file-name-sans-extension file)))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
221 (select-safe-coding-system
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
222 (point-min) (point-max)))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
223 buffer-file-coding-system)))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
224 (context (epg-make-context))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
225 (coding-system-for-write 'binary)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
226 string entry
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
227 (recipients
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
228 (cond
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
229 ((listp epa-file-encrypt-to) epa-file-encrypt-to)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
230 ((stringp epa-file-encrypt-to) (list epa-file-encrypt-to)))))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
231 (epg-context-set-passphrase-callback
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
232 context
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
233 (cons #'epa-file-passphrase-callback-function
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
234 file))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
235 (epg-context-set-progress-callback context
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
236 #'epa-progress-callback-function)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
237 (epg-context-set-armor context epa-armor)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
238 (condition-case error
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
239 (setq string
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
240 (epg-encrypt-string
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
241 context
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
242 (if (stringp start)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
243 (epa-file--encode-coding-string start coding-system)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
244 (epa-file--encode-coding-string (buffer-substring start end)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
245 coding-system))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
246 (if (or epa-file-select-keys
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
247 (not (local-variable-p 'epa-file-encrypt-to
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
248 (current-buffer))))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
249 (epa-select-keys
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
250 context
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
251 "Select recipents for encryption.
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
252 If no one is selected, symmetric encryption will be performed. "
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
253 recipients)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
254 (if epa-file-encrypt-to
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
255 (epg-list-keys context recipients)))))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
256 (error
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
257 (if (setq entry (assoc file epa-file-passphrase-alist))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
258 (setcdr entry nil))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
259 (signal 'file-error (cons "Opening output file" (cdr error)))))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
260 (epa-file-run-real-handler
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
261 #'write-region
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
262 (list string nil file append visit lockname mustbenew))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
263 (if (boundp 'last-coding-system-used)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
264 (setq last-coding-system-used coding-system))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
265 (if (eq visit t)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
266 (progn
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
267 (setq buffer-file-name file)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
268 (set-visited-file-modtime))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
269 (if (stringp visit)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
270 (progn
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
271 (set-visited-file-modtime)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
272 (setq buffer-file-name visit))))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
273 (if (or (eq visit t)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
274 (eq visit nil)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
275 (stringp visit))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
276 (message "Wrote %s" buffer-file-name))))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
277 (put 'write-region 'epa-file 'epa-file-write-region)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
278
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
279 (defun epa-file-find-file-hook ()
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
280 (if (and buffer-file-name
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
281 (string-match epa-file-name-regexp buffer-file-name)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
282 epa-file-inhibit-auto-save)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
283 (auto-save-mode 0))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
284 (set-buffer-modified-p nil))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
285
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
286 (defun epa-file-select-keys ()
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
287 "Select recipients for encryption."
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
288 (interactive)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
289 (make-local-variable 'epa-file-encrypt-to)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
290 (setq epa-file-encrypt-to
93002
d876f5372472 EasyPG: Fix bug with C-x C-s after M-x epa-file-select-keys.
Michael Olson <mwolson@gnu.org>
parents: 91731
diff changeset
291 (mapcar
d876f5372472 EasyPG: Fix bug with C-x C-s after M-x epa-file-select-keys.
Michael Olson <mwolson@gnu.org>
parents: 91731
diff changeset
292 (lambda (key)
d876f5372472 EasyPG: Fix bug with C-x C-s after M-x epa-file-select-keys.
Michael Olson <mwolson@gnu.org>
parents: 91731
diff changeset
293 (epg-sub-key-id (car (epg-key-sub-key-list key))))
91647
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
294 (epa-select-keys
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
295 (epg-make-context)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
296 "Select recipents for encryption.
93002
d876f5372472 EasyPG: Fix bug with C-x C-s after M-x epa-file-select-keys.
Michael Olson <mwolson@gnu.org>
parents: 91731
diff changeset
297 If no one is selected, symmetric encryption will be performed. "))))
91647
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
298
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
299 ;;;###autoload
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
300 (defun epa-file-enable ()
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
301 (interactive)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
302 (if (memq epa-file-handler file-name-handler-alist)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
303 (message "`epa-file' already enabled")
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
304 (setq file-name-handler-alist
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
305 (cons epa-file-handler file-name-handler-alist))
94417
1a8916b995cf * epa-file.el (auto-encryption-mode): Rename from epa-file-mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93002
diff changeset
306 (add-hook 'find-file-hook 'epa-file-find-file-hook)
91647
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
307 (setq auto-mode-alist (cons epa-file-auto-mode-alist-entry auto-mode-alist))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
308 (message "`epa-file' enabled")))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
309
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
310 ;;;###autoload
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
311 (defun epa-file-disable ()
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
312 (interactive)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
313 (if (memq epa-file-handler file-name-handler-alist)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
314 (progn
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
315 (setq file-name-handler-alist
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
316 (delq epa-file-handler file-name-handler-alist))
94417
1a8916b995cf * epa-file.el (auto-encryption-mode): Rename from epa-file-mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93002
diff changeset
317 (remove-hook 'find-file-hook 'epa-file-find-file-hook)
91647
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
318 (setq auto-mode-alist (delq epa-file-auto-mode-alist-entry
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
319 auto-mode-alist))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
320 (message "`epa-file' disabled"))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
321 (message "`epa-file' already disabled")))
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
322
91731
7efbdc83b944 EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents: 91703
diff changeset
323 ;;;###autoload
94417
1a8916b995cf * epa-file.el (auto-encryption-mode): Rename from epa-file-mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93002
diff changeset
324 (define-minor-mode auto-encryption-mode
91731
7efbdc83b944 EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents: 91703
diff changeset
325 "Toggle automatic file encryption and decryption.
7efbdc83b944 EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents: 91703
diff changeset
326 With prefix argument ARG, turn auto encryption on if positive, else off.
7efbdc83b944 EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents: 91703
diff changeset
327 Return the new status of auto encryption (non-nil means on)."
94417
1a8916b995cf * epa-file.el (auto-encryption-mode): Rename from epa-file-mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93002
diff changeset
328 :global t :init-value t :group 'epa-file :version "23.1"
91731
7efbdc83b944 EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents: 91703
diff changeset
329 (setq file-name-handler-alist
7efbdc83b944 EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents: 91703
diff changeset
330 (delq epa-file-handler file-name-handler-alist))
7efbdc83b944 EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents: 91703
diff changeset
331 (remove-hook 'find-file-hooks 'epa-file-find-file-hook)
7efbdc83b944 EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents: 91703
diff changeset
332 (setq auto-mode-alist (delq epa-file-auto-mode-alist-entry
7efbdc83b944 EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents: 91703
diff changeset
333 auto-mode-alist))
94417
1a8916b995cf * epa-file.el (auto-encryption-mode): Rename from epa-file-mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93002
diff changeset
334 (when auto-encryption-mode
91731
7efbdc83b944 EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents: 91703
diff changeset
335 (setq file-name-handler-alist
7efbdc83b944 EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents: 91703
diff changeset
336 (cons epa-file-handler file-name-handler-alist))
94417
1a8916b995cf * epa-file.el (auto-encryption-mode): Rename from epa-file-mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93002
diff changeset
337 (add-hook 'find-file-hook 'epa-file-find-file-hook)
1a8916b995cf * epa-file.el (auto-encryption-mode): Rename from epa-file-mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93002
diff changeset
338 (add-hook 'find-file-not-found-functions
1a8916b995cf * epa-file.el (auto-encryption-mode): Rename from epa-file-mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93002
diff changeset
339 'epa-file-find-file-not-found-functions)
91731
7efbdc83b944 EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents: 91703
diff changeset
340 (setq auto-mode-alist (cons epa-file-auto-mode-alist-entry
7efbdc83b944 EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents: 91703
diff changeset
341 auto-mode-alist))))
7efbdc83b944 EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents: 91703
diff changeset
342
94417
1a8916b995cf * epa-file.el (auto-encryption-mode): Rename from epa-file-mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93002
diff changeset
343 (put 'epa-file-handler 'safe-magic t)
1a8916b995cf * epa-file.el (auto-encryption-mode): Rename from epa-file-mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93002
diff changeset
344 (put 'epa-file-handler 'operations '(write-region insert-file-contents))
1a8916b995cf * epa-file.el (auto-encryption-mode): Rename from epa-file-mode.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 93002
diff changeset
345
91647
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
346 (provide 'epa-file)
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
347
91687
d125b90283d2 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 91647
diff changeset
348 ;; arch-tag: 5715152f-0eb1-4dbc-9008-07098775314d
91647
f9692dfe86e7 EasyPG: Initial check-in.
Michael Olson <mwolson@gnu.org>
parents:
diff changeset
349 ;;; epa-file.el ends here