From d9a0c1d079435cd5041e28380e5236e9479f1a23 Mon Sep 17 00:00:00 2001 From: ueno Date: Mon, 17 Apr 2006 04:06:04 +0000 Subject: [PATCH] * epa-file.el: New implementation of epf.el. * epf.el: Abolished. --- COMPILE | 2 +- ChangeLog | 5 ++ Makefile.am | 2 +- epa-file.el | 72 +++++++++++++++++++++ epa-setup.el | 6 ++ epf.el | 199 ---------------------------------------------------------- epg.el | 3 +- 7 files changed, 87 insertions(+), 202 deletions(-) create mode 100644 epa-file.el delete mode 100644 epf.el diff --git a/COMPILE b/COMPILE index fb09266..6c6fd67 100644 --- a/COMPILE +++ b/COMPILE @@ -1,7 +1,7 @@ ;;; -*- Emacs-Lisp -*- (defvar epg-modules - '(epg epa epa-dired epa-setup)) + '(epg epa epa-dired epa-file epa-setup)) (defun epg-compile-modules (modules) (let ((load-path (cons nil load-path)) diff --git a/ChangeLog b/ChangeLog index 9764d16..b385a4b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2006-04-17 Daiki Ueno + * epa-file.el: New implementation of epf.el. + * epf.el: Abolished. + +2006-04-17 Daiki Ueno + * epa.el (epa-verify-file): Display verify result. * epg.el (epg-invalid-recipients-alist): New variable. diff --git a/Makefile.am b/Makefile.am index 5af9349..c64fe92 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,6 @@ AUTOMAKE_OPTIONS = no-dependencies -EXTRA_DIST = epg.el epa.el epa-dired.el pgg-epg.el +EXTRA_DIST = epg.el epa.el epa-dired.el epa-file.el pgg-epg.el CLEANFILES = auto-autoloads.el custom-load.el *.elc FLAGS ?= -batch -q -no-site-file diff --git a/epa-file.el b/epa-file.el new file mode 100644 index 0000000..e216999 --- /dev/null +++ b/epa-file.el @@ -0,0 +1,72 @@ +;;; epa-file.el --- the EasyPG Assistant hooks for transparent file encryption +;; Copyright (C) 2006 Daiki Ueno + +;; Author: Daiki Ueno +;; Keywords: PGP, GnuPG + +;; This file is part of EasyPG. + +;; This program 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 2, or (at your option) +;; any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; 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. + +;;; Code: + +(require 'epa) + +(defgroup 'epa-file + "The EasyPG Assistant hooks for transparent file encryption" + :group 'epa) + +(defcustom epa-file-name-regexp "\\.gpg\\'" + "Regexp which matches filenames to be encrypted with GnuPG." + :type 'regexp + :group 'epa-file) + +(defvar epa-file nil) + +(defun epa-find-file () + (when (string-match epa-file-name-regexp (buffer-file-name)) + (if (= (buffer-size) 0) + (progn + (set-auto-mode) + (hack-local-variables) + (auto-save-mode nil)) + (goto-char (point-min)) + (insert (epg-decrypt-file (epg-make-context) + (expand-file-name (buffer-file-name)) + nil)) + (delete-region (point) (point-max))) + (make-local-variable 'epa-file) + (setq epa-file (buffer-file-name)))) + +(defun epa-write-file () + (when epa-file + (write-region + (epg-encrypt-string + (epg-make-context) + (buffer-string) + (mapcar (lambda (key) + (epg-sub-key-id + (car (epg-key-sub-key-list key)))) + (epa-select-keys + "Select recipents for encryption. +If no one is selected, symmetric encryption will be performed. "))) + nil (expand-file-name (buffer-file-name))) + (set-buffer-modified-p nil) + t)) + +(provide 'epa-file) + +;;; epa-file.el ends here diff --git a/epa-setup.el b/epa-setup.el index 4b77f7d..5944deb 100644 --- a/epa-setup.el +++ b/epa-setup.el @@ -1,6 +1,12 @@ (autoload 'epa-dired-mode-hook "epa-dired") (add-hook 'dired-mode-hook 'epa-dired-mode-hook) +(autoload 'epa-find-file "epa-file") +(add-hook 'find-file-hooks 'epa-find-file) + +(autoload 'epa-write-file "epa-file") +(add-hook 'write-file-hooks 'epa-write-file) + (provide 'epa-setup) ;;; epa-setup.el ends here \ No newline at end of file diff --git a/epf.el b/epf.el deleted file mode 100644 index b554919..0000000 --- a/epf.el +++ /dev/null @@ -1,199 +0,0 @@ -;;; epf.el --- transparent file encryption utility -;; Copyright (C) 2006 Daiki Ueno - -;; Author: Daiki Ueno -;; Naoto Morishima -;; Keywords: PGP, GnuPG - -;; This file is part of EasyPG. - -;; This program 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 2, or (at your option) -;; any later version. - -;; This program is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; 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. - -;;; Commentary: - -;; epf.el is based on hedgehog.el by Naoto Morishima. -;; http://www.morishima.net/~naoto/software/hedgehog/index.php.ja - -;;; Code: - -(require 'epg) - -(defgroup epf () - "Transparent file encryption utility of EasyPG." - :group 'epg) - -(defcustom epf-name-regexp "\\.gpg\\'" - "Regexp that matches filenames that are assumed to be encrypted -with GnuPG." - :type 'regexp - :group 'epf) - -(defun epf-handler (operation &rest args) - (let ((epf-operation (get operation 'epf))) - (if epf-operation - (apply epf-operation args) - (epf-run-real-handler operation args)))) - -(defun epf-run-real-handler (operation args) - (let ((inhibit-file-name-handlers - (cons 'epf-handler - (and (eq inhibit-file-name-operation operation) - inhibit-file-name-handlers))) - (inhibit-file-name-operation operation)) - (apply operation args))) - -(defvar buffer-file-type) -(defvar last-coding-system-used) -(defun epf-write-region (start end filename &optional append visit - lockname mustbenew) - (let* ((visit-file (if (stringp visit) - (expand-file-name visit) - (expand-file-name filename))) - ;; XXX: Obtain the value returned by choose_write_coding_system - (coding-system (condition-case nil - (epf-run-real-handler - 'write-region (list start end "/")) - (file-error (if (boundp 'last-coding-system-used) - last-coding-system-used - buffer-file-coding-system)))) - ;; start and end are normally buffer positions - ;; specifying the part of the buffer to write. - ;; If start is nil, that means to use the entire buffer contents. - ;; If start is a string, then output that string to the file - ;; instead of any buffer contents; end is ignored. - (string (encode-coding-string (cond - ((stringp start) - start) - ((null start) - (buffer-string)) - (t - (buffer-substring start end))) - coding-system))) - (with-temp-buffer - (if (fboundp 'set-buffer-multibyte) - (set-buffer-multibyte nil)) - ;; Optional fourth argument append if non-nil means - ;; append to existing file contents (if any). If it is an integer, - ;; seek to that offset in the file before writing. - (if (and append (file-exists-p filename)) - ;; Enable passphrase cache on this temp buffer - (let ((coding-system-for-read 'binary)) - ;; set visit to t so that passphrase is cached - (insert-file-contents filename t) - (setq buffer-file-name nil))) - ;; Insert data to encrypt - (goto-char (if (integerp append) (1+ append) (point-max))) - (delete-region (point) (min (+ (point) (length string)) (point-max))) - (insert string) - - (let ((coding-system-for-write 'binary) - (coding-system-for-read 'binary) - (context (epg-make-context)) - recipients - string - cipher) - (while (not (equal (setq string - (read-string "To (end with an empty line): ")) - "")) - (setq recipients (cons string recipients))) - (when (setq cipher (epg-encrypt-string context (buffer-string) - recipients)) - (if (and (memq system-type '(ms-dos windows-nt)) - (boundp 'buffer-file-type)) - (setq buffer-file-type t)) - (epf-run-real-handler - 'write-region - (list cipher nil filename nil 'not-visit lockname mustbenew))))) - ;; Optional fifth argument visit, if t or a string, means - ;; set the last-save-file-modtime of buffer to this file's modtime - ;; and mark buffer not modified. - ;; If visit is a string, it is a second file name; - ;; the output goes to filename, but the buffer is marked as visiting visit. - ;; visit is also the file name to lock and unlock for clash detection. - ;; If visit is neither t nor nil nor a string, - ;; that means do not display the "Wrote file" message. - (when (or (eq visit t) (stringp visit)) - (setq buffer-file-name filename) - (set-visited-file-modtime)) - (if (stringp visit) - (setq buffer-file-name visit)) - (when (or (eq visit t) (eq visit nil) (stringp visit)) - (message "Wrote %s" visit-file)) - (if (boundp 'last-coding-system-used) - (setq last-coding-system-used coding-system)) - nil)) - -(defun epf-insert-file-contents (filename &optional visit beg end replace) - (barf-if-buffer-read-only) - (setq filename (expand-file-name filename)) - (let ((filename (expand-file-name filename)) - (length 0)) - (if (file-exists-p filename) - (let ((local-file - (let ((inhibit-file-name-operation - (when (eq inhibit-file-name-operation - 'insert-file-contents) - 'file-local-copy))) - (file-local-copy filename))) - (coding-system-for-read 'binary) - (context (epg-make-context)) - string) - (unwind-protect - (progn - (setq string (epg-decrypt-file context (or local-file - filename) - nil) - length (length string)) - (if replace - (goto-char (point-min))) - (save-excursion - (let ((buffer-file-name (if visit nil buffer-file-name))) - (save-restriction - (narrow-to-region (point) (point)) - (insert (decode-coding-string string 'undecided))) - (if replace - (delete-region (point) (point-max)))))) - (when (and local-file (file-exists-p local-file)) - (delete-file local-file))))) - ;; If second argument visit is non-nil, the buffer's visited filename - ;; and last save file modtime are set, and it is marked unmodified. - (when visit - (unlock-buffer) - (setq buffer-file-name filename) - (set-visited-file-modtime)) - - ;; If visiting and the file does not exist, visiting is completed - ;; before the error is signaled. - (if (and visit (not (file-exists-p filename))) - (signal 'file-error (list "Opening input file" filename))) - - ;; Returns list of absolute file name and number of characters inserted. - (list filename length))) - -(put 'write-region 'epf 'epf-write-region) -(put 'insert-file-contents 'epf 'epf-insert-file-contents) - -(unless (rassq 'epf-handler file-name-handler-alist) - (setq file-name-handler-alist - (cons (cons epf-name-regexp 'epf-handler) - file-name-handler-alist) - auto-mode-alist - (cons (list epf-name-regexp nil 'strip-suffix) - auto-mode-alist))) - -(provide 'epf) - -;;; epf.el ends here diff --git a/epg.el b/epg.el index f888ec5..e3ff7cd 100644 --- a/epg.el +++ b/epg.el @@ -375,7 +375,8 @@ This function is for internal use only." "Start `epg-gpg-program' in a subprocess with given ARGS." (let* ((args (append (list "--no-tty" "--status-fd" "1" - "--command-fd" "0") + "--command-fd" "0" + "--yes") (if (epg-context-armor context) '("--armor")) (if (epg-context-textmode context) '("--textmode")) (if (epg-context-output-file context) -- 1.7.10.4