(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)
(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)
(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)))
(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