X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=epg-file.el;h=cd6f6a02bdaaebb15250c6e09b75fcdebab650fb;hb=95ff40c9179c88308fe96e1adb0ef220b67f265c;hp=d3f5da1a952fcd3b686db3fd19a6d1781344a80f;hpb=37d3d49548803d24469b5c5e6a792aa94ad5aa22;p=elisp%2Fepg.git diff --git a/epg-file.el b/epg-file.el index d3f5da1..cd6f6a0 100644 --- a/epg-file.el +++ b/epg-file.el @@ -1,5 +1,42 @@ +;;; epg-file.el --- transparent file encryption utility +;; Copyright (C) 1999, 2000, 2002, 2003, 2004, +;; 2005, 2006 Free Software Foundation, Inc. +;; 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: + +;; epg-file.el is based on hedgehog.el by Naoto Morishima. +;; http://www.morishima.net/~naoto/software/hedgehog/index.php.ja + +;;; Code: + (require 'epg) +(defgroup epg-file () + "Transparent file encryption utility of EasyPG." + :group 'epg) + (defcustom epg-file-name-regexp "\\.gpg\\'" "Regexp that matches filenames that are assumed to be encrypted with GnuPG." @@ -20,6 +57,8 @@ with GnuPG." (inhibit-file-name-operation operation)) (apply operation args))) +(defvar buffer-file-type) +(defvar last-coding-system-used) (defun epg-file-write-region (start end filename &optional append visit lockname mustbenew) (let* ((visit-file (if (stringp visit) @@ -29,7 +68,9 @@ with GnuPG." (coding-system (condition-case nil (epg-file-run-real-handler 'write-region (list start end "/")) - (file-error last-coding-system-used))) + (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. @@ -44,7 +85,8 @@ with GnuPG." (buffer-substring start end))) coding-system))) (with-temp-buffer - (set-buffer-multibyte nil) + (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. @@ -62,9 +104,17 @@ with GnuPG." (let ((coding-system-for-write 'binary) (coding-system-for-read 'binary) (context (epg-make-context)) + recipients + string cipher) - (when (setq cipher (epg-encrypt-string context (buffer-string) nil)) - (if (memq system-type '(ms-dos windows-nt)) + (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)) (epg-file-run-real-handler 'write-region @@ -80,11 +130,12 @@ with GnuPG." (when (or (eq visit t) (stringp visit)) (setq buffer-file-name filename) (set-visited-file-modtime)) - (when (stringp visit) - (setq buffer-file-name visit)) + (if (stringp visit) + (setq buffer-file-name visit)) (when (or (eq visit t) (eq visit nil) (stringp visit)) (message "Wrote %s" visit-file)) - (setq last-coding-system-used coding-system) + (if (boundp 'last-coding-system-used) + (setq last-coding-system-used coding-system)) nil)) (defun epg-file-insert-file-contents (filename &optional visit beg end replace) @@ -145,3 +196,7 @@ with GnuPG." (setq auto-mode-alist (cons (list epg-file-name-regexp nil 'strip-suffix) auto-mode-alist))) + +(provide 'epg-file) + +;;; epg-file.el ends here