X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/0bd4f3175d3d2e0d6ef892900688dcd0ab2166b3..db18c5fd6fca1633508dc77d687789f38d905dd1:/lisp/epa-file.el diff --git a/lisp/epa-file.el b/lisp/epa-file.el index c753d4c37a..f621a53e0f 100644 --- a/lisp/epa-file.el +++ b/lisp/epa-file.el @@ -6,10 +6,10 @@ ;; This file is part of GNU Emacs. -;; GNU Emacs is free software; you can redistribute it and/or modify +;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation; either version 3, or (at your option) -;; any later version. +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -17,75 +17,23 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with GNU Emacs; see the file COPYING. If not, write to the -;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -;; Boston, MA 02110-1301, USA. +;; along with GNU Emacs. If not, see . ;;; Code: (require 'epa) - -(defgroup epa-file nil - "The EasyPG Assistant hooks for transparent file encryption" - :version "23.1" - :group 'epa) - -(defun epa-file--file-name-regexp-set (variable value) - (set-default variable value) - (if (fboundp 'epa-file-name-regexp-update) - (epa-file-name-regexp-update))) - -(defcustom epa-file-name-regexp "\\.gpg\\(~\\|\\.~[0-9]+~\\)?\\'" - "Regexp which matches filenames to be encrypted with GnuPG. - -If you set this outside Custom while epa-file is already enabled, you -have to call `epa-file-name-regexp-update' after setting it to -properly update file-name-handler-alist. Setting this through Custom -does that automatically." - :type 'regexp - :group 'epa-file - :set 'epa-file--file-name-regexp-set) +(require 'epa-hook) (defcustom epa-file-cache-passphrase-for-symmetric-encryption nil "If non-nil, cache passphrase for symmetric encryption." :type 'boolean :group 'epa-file) -(defcustom epa-file-inhibit-auto-save t - "If non-nil, disable auto-saving when opening an encrypted file." - :type 'boolean - :group 'epa-file) - (defcustom epa-file-select-keys nil "If non-nil, always asks user to select recipients." :type 'boolean :group 'epa-file) -(defvar epa-file-encrypt-to nil - "*Recipient(s) used for encrypting files. -May either be a string or a list of strings.") - -;;;###autoload -(put 'epa-file-encrypt-to 'safe-local-variable - (lambda (val) - (or (stringp val) - (and (listp val) - (catch 'safe - (mapc (lambda (elt) - (unless (stringp elt) - (throw 'safe nil))) - val) - t))))) - -;;;###autoload -(put 'epa-file-encrypt-to 'permanent-local t) - -(defvar epa-file-handler - (cons epa-file-name-regexp 'epa-file-handler)) - -(defvar epa-file-auto-mode-alist-entry - (list epa-file-name-regexp nil 'epa-file)) - (defvar epa-file-passphrase-alist nil) (eval-and-compile @@ -98,11 +46,6 @@ May either be a string or a list of strings.") (defalias 'epa-file--decode-coding-string 'decode-coding-string) (defalias 'epa-file--decode-coding-string 'identity))) -(defun epa-file-name-regexp-update () - (interactive) - (unless (equal (car epa-file-handler) epa-file-name-regexp) - (setcar epa-file-handler epa-file-name-regexp))) - (defun epa-file-passphrase-callback-function (context key-id file) (if (and epa-file-cache-passphrase-for-symmetric-encryption (eq key-id 'SYM)) @@ -123,12 +66,13 @@ May either be a string or a list of strings.") passphrase)))) (epa-passphrase-callback-function context key-id nil))) +;;;###autoload (defun epa-file-handler (operation &rest args) (save-match-data (let ((op (get operation 'epa-file))) (if op - (apply op args) - (epa-file-run-real-handler operation args))))) + (apply op args) + (epa-file-run-real-handler operation args))))) (defun epa-file-run-real-handler (operation args) (let ((inhibit-file-name-handlers @@ -238,6 +182,9 @@ May either be a string or a list of strings.") context (if (stringp start) (epa-file--encode-coding-string start coding-system) + (unless start + (setq start (point-min) + end (point-max))) (epa-file--encode-coding-string (buffer-substring start end) coding-system)) (if (or epa-file-select-keys @@ -273,22 +220,18 @@ If no one is selected, symmetric encryption will be performed. " (message "Wrote %s" buffer-file-name)))) (put 'write-region 'epa-file 'epa-file-write-region) -(defun epa-file-find-file-hook () - (if (and buffer-file-name - (string-match epa-file-name-regexp buffer-file-name) - epa-file-inhibit-auto-save) - (auto-save-mode 0)) - (set-buffer-modified-p nil)) - (defun epa-file-select-keys () "Select recipients for encryption." (interactive) (make-local-variable 'epa-file-encrypt-to) (setq epa-file-encrypt-to + (mapcar + (lambda (key) + (epg-sub-key-id (car (epg-key-sub-key-list key)))) (epa-select-keys (epg-make-context) "Select recipents for encryption. -If no one is selected, symmetric encryption will be performed. "))) +If no one is selected, symmetric encryption will be performed. ")))) ;;;###autoload (defun epa-file-enable () @@ -297,7 +240,7 @@ If no one is selected, symmetric encryption will be performed. "))) (message "`epa-file' already enabled") (setq file-name-handler-alist (cons epa-file-handler file-name-handler-alist)) - (add-hook 'find-file-hooks 'epa-file-find-file-hook) + (add-hook 'find-file-hook 'epa-file-find-file-hook) (setq auto-mode-alist (cons epa-file-auto-mode-alist-entry auto-mode-alist)) (message "`epa-file' enabled"))) @@ -308,7 +251,7 @@ If no one is selected, symmetric encryption will be performed. "))) (progn (setq file-name-handler-alist (delq epa-file-handler file-name-handler-alist)) - (remove-hook 'find-file-hooks 'epa-file-find-file-hook) + (remove-hook 'find-file-hook 'epa-file-find-file-hook) (setq auto-mode-alist (delq epa-file-auto-mode-alist-entry auto-mode-alist)) (message "`epa-file' disabled"))