5 (let ((keymap (make-sparse-keymap)))
6 (define-key keymap "d" 'epa-dired-do-decrypt)
7 (define-key keymap "v" 'epa-dired-do-verify)
8 (define-key keymap "s" 'epa-dired-do-sign)
9 (define-key keymap "e" 'epa-dired-do-encrypt)
12 (fset 'epa-dired-prefix epa-dired-map)
14 (defun epa-dired-setup ()
15 (add-hook 'dired-mode-hook 'epa-dired-mode-hook))
17 (defun epa-dired-mode-hook ()
18 (define-key dired-mode-map ":" 'epa-dired-prefix))
20 (defun epa-dired-decrypt-file (file)
21 (let* ((default-name (file-name-sans-extension file))
22 (plain (read-file-name
23 (concat "To file (default "
24 (file-name-nondirectory default-name)
26 (file-name-directory default-name)
28 (context (epg-make-context)))
29 (message "Decrypting %s..." (file-name-nondirectory file))
30 (epg-decrypt-file context file plain)
31 (message "Decrypting %s...done" (file-name-nondirectory file))))
33 (defun epa-dired-do-decrypt ()
35 (let ((file-list (dired-get-marked-files)))
37 (epa-dired-decrypt-file (car file-list))
38 (setq file-list (cdr file-list)))))
40 (defun epa-dired-verify-file (file)
41 (let* ((context (epg-make-context))
42 (plain (if (equal (file-name-extension file) "sig")
43 (file-name-sans-extension file))))
44 (message "Verifying %s..." (file-name-nondirectory file))
45 (epg-verify-file context file plain)
46 (message "Verifying %s...done" (file-name-nondirectory file))))
48 (defun epa-dired-do-verify ()
50 (let ((file-list (dired-get-marked-files)))
52 (epa-dired-verify-file (car file-list))
53 (setq file-list (cdr file-list)))))
55 (defun epa-dired-sign-file (file detached)
56 (let ((signature (concat file (if detached ".sig" ".gpg")))
57 (context (epg-make-context)))
58 (message "Signing %s..." (file-name-nondirectory file))
59 (epg-sign-file context file signature)
60 (message "Signing %s...done" (file-name-nondirectory file))))
62 (defun epa-dired-do-sign (&optional detached)
64 (let ((file-list (dired-get-marked-files)))
66 (epa-dired-sign-file (expand-file-name (car file-list)) detached)
67 (setq file-list (cdr file-list)))
70 (defun epa-dired-encrypt-file (keys file)
71 (let ((cipher (concat file ".gpg"))
72 (context (epg-make-context)))
73 (message "Encrypting %s..." (file-name-nondirectory file))
74 (epg-encrypt-file context
78 (car (epg-key-sub-key-list key))))
81 (message "Encrypting %s...done" (file-name-nondirectory file))))
83 (defun epa-dired-do-encrypt ()
85 (let ((file-list (dired-get-marked-files)))
87 (epa-ask-keys "Select recipents for encryption.
88 If no one is selected, symmetric encryption will be performed. "
89 #'epa-dired-encrypt-file nil
90 (expand-file-name (car file-list)))
91 (setq file-list (cdr file-list)))))
95 ;;; epa-dired.el ends here