From 31cb916d71d15fff73ca59e75103106cf8d3299f Mon Sep 17 00:00:00 2001 From: ueno Date: Mon, 17 Apr 2006 01:19:19 +0000 Subject: [PATCH] * epa.el (epa-keys-mode-map): Bind epa-decrypt-file, epa-verify-file, epa-sign-file, and epa-encrypt-file. (epa-decrypt-file): New function imported from epa-dired.el. (epa-verify-file): New function imported from epa-dired.el. (epa-sign-file): New function imported from epa-dired.el. (epa-encrypt-file): New function imported from epa-dired.el. --- ChangeLog | 9 ++++ epa-dired.el | 65 +++++---------------------- epa-setup.el | 4 +- epa.el | 139 ++++++++++++++++++++++++++++++++++++++++------------------ 4 files changed, 120 insertions(+), 97 deletions(-) diff --git a/ChangeLog b/ChangeLog index d20f304..a742569 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-04-17 Daiki Ueno + + * epa.el (epa-keys-mode-map): Bind epa-decrypt-file, + epa-verify-file, epa-sign-file, and epa-encrypt-file. + (epa-decrypt-file): New function imported from epa-dired.el. + (epa-verify-file): New function imported from epa-dired.el. + (epa-sign-file): New function imported from epa-dired.el. + (epa-encrypt-file): New function imported from epa-dired.el. + 2006-04-16 Daiki Ueno * epa.el (epa-select-keys): Renamed from epa-ask-keys; use diff --git a/epa-dired.el b/epa-dired.el index 9b2dc44..f1ed137 100644 --- a/epa-dired.el +++ b/epa-dired.el @@ -11,82 +11,41 @@ (fset 'epa-dired-prefix epa-dired-map) -(defun epa-dired-setup () - (add-hook 'dired-mode-hook 'epa-dired-mode-hook)) - (defun epa-dired-mode-hook () (define-key dired-mode-map ":" 'epa-dired-prefix)) -(defun epa-dired-decrypt-file (file) - (let* ((default-name (file-name-sans-extension file)) - (plain (read-file-name - (concat "To file (default " - (file-name-nondirectory default-name) - ") ") - (file-name-directory default-name) - default-name)) - (context (epg-make-context))) - (message "Decrypting %s..." (file-name-nondirectory file)) - (epg-decrypt-file context file plain) - (message "Decrypting %s...done" (file-name-nondirectory file)))) - (defun epa-dired-do-decrypt () (interactive) (let ((file-list (dired-get-marked-files))) (while file-list - (epa-dired-decrypt-file (car file-list)) + (epa-decrypt-file (car file-list)) (setq file-list (cdr file-list))))) -(defun epa-dired-verify-file (file) - (let* ((context (epg-make-context)) - (plain (if (equal (file-name-extension file) "sig") - (file-name-sans-extension file)))) - (message "Verifying %s..." (file-name-nondirectory file)) - (epg-verify-file context file plain) - (message "Verifying %s...done" (file-name-nondirectory file)))) - (defun epa-dired-do-verify () (interactive) (let ((file-list (dired-get-marked-files))) (while file-list - (epa-dired-verify-file (car file-list)) + (epa-verify-file (car file-list)) (setq file-list (cdr file-list))))) -(defun epa-dired-sign-file (file detached) - (let ((signature (concat file (if detached ".sig" ".gpg"))) - (context (epg-make-context))) - (message "Signing %s..." (file-name-nondirectory file)) - (epg-sign-file context file signature) - (message "Signing %s...done" (file-name-nondirectory file)))) - (defun epa-dired-do-sign (&optional detached) - (interactive "p") + (interactive "P") (let ((file-list (dired-get-marked-files))) (while file-list - (epa-dired-sign-file (expand-file-name (car file-list)) detached) - (setq file-list (cdr file-list))) - (revert-buffer))) - -(defun epa-dired-encrypt-file (file) - (let ((cipher (concat file ".gpg")) - (context (epg-make-context)) - (keys (epa-select-keys "Select recipents for encryption. -If no one is selected, symmetric encryption will be performed. "))) - (message "Encrypting %s..." (file-name-nondirectory file)) - (epg-encrypt-file context - file - (mapcar (lambda (key) - (epg-sub-key-id - (car (epg-key-sub-key-list key)))) - keys) - cipher) - (message "Encrypting %s...done" (file-name-nondirectory file)))) + (epa-sign-file (expand-file-name (car file-list)) detached) + (setq file-list (cdr file-list))))) (defun epa-dired-do-encrypt () (interactive) (let ((file-list (dired-get-marked-files))) (while file-list - (epa-dired-encrypt-file (car file-list)) + (epa-encrypt-file + (car file-list) + (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. "))) (setq file-list (cdr file-list))))) (provide 'epa-dired) diff --git a/epa-setup.el b/epa-setup.el index 3d3d3af..4b77f7d 100644 --- a/epa-setup.el +++ b/epa-setup.el @@ -1,5 +1,5 @@ -(require 'epa-dired) -(epa-dired-setup) +(autoload 'epa-dired-mode-hook "epa-dired") +(add-hook 'dired-mode-hook 'epa-dired-mode-hook) (provide 'epa-setup) diff --git a/epa.el b/epa.el index e85f4be..28629b2 100644 --- a/epa.el +++ b/epa.el @@ -140,6 +140,10 @@ (let ((keymap (make-sparse-keymap))) (define-key keymap "m" 'epa-mark) (define-key keymap "u" 'epa-unmark) + (define-key keymap "d" 'epa-decrypt-file) + (define-key keymap "v" 'epa-verify-file) + (define-key keymap "s" 'epa-sign-file) + (define-key keymap "e" 'epa-encrypt-file) (define-key keymap "n" 'next-line) (define-key keymap "p" 'previous-line) (define-key keymap " " 'scroll-up) @@ -224,48 +228,49 @@ (setq keys (cdr keys))))) (defun epa-select-keys (prompt &optional names) - (unless (and epa-keys-buffer - (buffer-live-p epa-keys-buffer)) - (setq epa-keys-buffer (generate-new-buffer "*Keys*"))) - (let ((inhibit-read-only t) - buffer-read-only - point) - (set-buffer epa-keys-buffer) - (erase-buffer) - (insert prompt "\n") - (widget-create 'link - :notify (lambda (&rest ignore) (exit-recursive-edit)) - :help-echo - (substitute-command-keys - "Click here or \\[exit-recursive-edit] to finish") - "OK") - (insert "\n\n") - (if names - (while names - (setq point (point)) - (epa-list-keys-1 (car names)) - (goto-char point) - (epa-mark) - (goto-char (point-max)) - (setq names (cdr names))) - (epa-list-keys-1 nil)) - (epa-keys-mode) - (goto-char (point-min)) - (pop-to-buffer (current-buffer)) - (unwind-protect - (progn - (recursive-edit) - (save-excursion - (set-buffer epa-keys-buffer) - (goto-char (point-min)) - (let (keys key) - (while (re-search-forward "^\\*" nil t) - (if (setq key (get-text-property (match-beginning 0) 'epa-key)) - (setq keys (cons key keys)))) - (nreverse keys)))) - (if (get-buffer-window epa-keys-buffer) - (delete-window (get-buffer-window epa-keys-buffer))) - (kill-buffer epa-keys-buffer)))) + (save-excursion + (unless (and epa-keys-buffer + (buffer-live-p epa-keys-buffer)) + (setq epa-keys-buffer (generate-new-buffer "*Keys*"))) + (let ((inhibit-read-only t) + buffer-read-only + point) + (set-buffer epa-keys-buffer) + (erase-buffer) + (insert prompt "\n") + (widget-create 'link + :notify (lambda (&rest ignore) (exit-recursive-edit)) + :help-echo + (substitute-command-keys + "Click here or \\[exit-recursive-edit] to finish") + "OK") + (insert "\n\n") + (if names + (while names + (setq point (point)) + (epa-list-keys-1 (car names)) + (goto-char point) + (epa-mark) + (goto-char (point-max)) + (setq names (cdr names))) + (epa-list-keys-1 nil)) + (epa-keys-mode) + (goto-char (point-min)) + (pop-to-buffer (current-buffer)) + (unwind-protect + (progn + (recursive-edit) + (save-excursion + (set-buffer epa-keys-buffer) + (goto-char (point-min)) + (let (keys key) + (while (re-search-forward "^\\*" nil t) + (if (setq key (get-text-property (match-beginning 0) 'epa-key)) + (setq keys (cons key keys)))) + (nreverse keys)))) + (if (get-buffer-window epa-keys-buffer) + (delete-window (get-buffer-window epa-keys-buffer))) + (kill-buffer epa-keys-buffer))))) (defun epa-show-key (key) (let* ((primary-sub-key (car (epg-key-sub-key-list key))) @@ -348,6 +353,56 @@ (interactive "P") (epa-mark (not arg))) +(defun epa-decrypt-file (file) + (interactive "fFile: ") + (let* ((default-name (file-name-sans-extension file)) + (plain (read-file-name + (concat "To file (default " + (file-name-nondirectory default-name) + ") ") + (file-name-directory default-name) + default-name)) + (context (epg-make-context))) + (message "Decrypting %s..." (file-name-nondirectory file)) + (epg-decrypt-file context file plain) + (message "Decrypting %s...done" (file-name-nondirectory file)))) + +(defun epa-verify-file (file) + (interactive "fFile: ") + (let* ((context (epg-make-context)) + (plain (if (equal (file-name-extension file) "sig") + (file-name-sans-extension file)))) + (message "Verifying %s..." (file-name-nondirectory file)) + (epg-verify-file context file plain) + (message "Verifying %s...done" (file-name-nondirectory file)))) + +(defun epa-sign-file (file detached) + (interactive + (list (expand-file-name (read-file-name "File: ")) + current-prefix-arg)) + (let ((signature (concat file (if detached ".sig" ".gpg"))) + (context (epg-make-context))) + (message "Signing %s..." (file-name-nondirectory file)) + (epg-sign-file context file signature) + (message "Signing %s...done" (file-name-nondirectory file)))) + +(defun epa-encrypt-file (file recipients) + (interactive + (list (expand-file-name (read-file-name "File: ")) + (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. ")))) + (let ((cipher (concat file ".gpg")) + (context (epg-make-context))) + (message "Encrypting %s..." (file-name-nondirectory file)) + (epg-encrypt-file context + file + recipients + cipher) + (message "Encrypting %s...done" (file-name-nondirectory file)))) + (provide 'epa) ;;; epa.el ends here -- 1.7.10.4