From dbf8095e7b3bcd6c9716806defcba8a05c54d461 Mon Sep 17 00:00:00 2001 From: ueno Date: Tue, 18 Apr 2006 10:00:18 +0000 Subject: [PATCH] * epa.el (epa-export-keys): New command. * epg.el (epg-start-export-keys): Accept a list of epg-key object instead of a regexp. --- ChangeLog | 6 +++++ epa.el | 79 ++++++++++++++++++++++++++++++++++++++++++------------------- epg.el | 51 ++++++++++++++++++++++++++------------- 3 files changed, 94 insertions(+), 42 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5524973..866a960 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2006-04-18 Daiki Ueno + * epa.el (epa-export-keys): New command. + * epg.el (epg-start-export-keys): Accept a list of epg-key object + instead of a regexp. + +2006-04-18 Daiki Ueno + * epa.el (epa-keys-mode-map): Bind epa-list-keys; epa-import-key. (epa-import-key): New command. diff --git a/epa.el b/epa.el index 462847b..61b26fa 100644 --- a/epa.el +++ b/epa.el @@ -153,8 +153,9 @@ (define-key keymap "v" 'epa-verify-file) (define-key keymap "s" 'epa-sign-file) (define-key keymap "e" 'epa-encrypt-file) - (define-key keymap "r" 'epa-delete-key) - (define-key keymap "i" 'epa-import-key) + (define-key keymap "r" 'epa-delete-keys) + (define-key keymap "i" 'epa-import-keys) + (define-key keymap "o" 'epa-export-keys) (define-key keymap "g" 'epa-list-keys) (define-key keymap "n" 'next-line) (define-key keymap "p" 'previous-line) @@ -275,6 +276,20 @@ (insert "\n") (setq keys (cdr keys))))) +(defun epa-marked-keys () + (or (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))) + (save-excursion + (beginning-of-line) + (get-text-property (point) 'epa-key)))) + (defun epa-select-keys (prompt &optional names) (save-excursion (unless (and epa-keys-buffer @@ -308,15 +323,7 @@ (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)))) + (epa-marked-keys)) (if (get-buffer-window epa-keys-buffer) (delete-window (get-buffer-window epa-keys-buffer))) (kill-buffer epa-keys-buffer))))) @@ -457,8 +464,8 @@ (interactive (list (expand-file-name (read-file-name "File: ")) (mapcar (lambda (key) - (epg-sub-key-id - (car (epg-key-sub-key-list 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")) @@ -470,28 +477,50 @@ If no one is selected, symmetric encryption will be performed. ")))) cipher) (message "Encrypting %s...done" (file-name-nondirectory file)))) -(defun epa-delete-key (key) +(defun epa-delete-keys (keys) (interactive - (list - (save-excursion - (beginning-of-line) - (get-text-property (point) 'epa-key)))) + (let ((keys (epa-marked-keys))) + (unless keys + (error "No keys selected")) + (list keys))) (let ((context (epg-make-context))) - (message "Deleting %s..." - (epg-sub-key-id (car (epg-key-sub-key-list key)))) - (epg-delete-key context key) + (message "Deleting...") + (epg-delete-keys context keys) (apply #'epa-list-keys epa-list-keys-arguments) - (message "Deleting %s...done" - (epg-sub-key-id (car (epg-key-sub-key-list key)))))) + (message "Deleting...done"))) -(defun epa-import-key (file) +(defun epa-import-keys (file) (interactive "fFile: ") (let ((context (epg-make-context))) (message "Importing %s..." (file-name-nondirectory file)) - (epg-import-key context file) + (epg-import-keys context file) (apply #'epa-list-keys epa-list-keys-arguments) (message "Importing %s...done" (file-name-nondirectory file)))) +(defun epa-export-keys (keys file) + (interactive + (let ((keys (epa-marked-keys)) + default-name) + (unless keys + (error "No keys selected")) + (setq default-name + (expand-file-name + (concat (epg-sub-key-id (epg-key-sub-key-list (car keys))) + ".gpg") + default-directory)) + (list keys + (expand-file-name + (read-file-name + (concat "To file (default " + (file-name-nondirectory default-name) + ") ") + (file-name-directory default-name) + default-name))))) + (let ((context (epg-make-context))) + (message "Exporting to %s..." (file-name-nondirectory file)) + (epg-export-keys context keys file) + (message "Exporting to %s...done" (file-name-nondirectory file)))) + (provide 'epa) ;;; epa.el ends here diff --git a/epg.el b/epg.el index ba5cc04..e5fb6cd 100644 --- a/epg.el +++ b/epg.el @@ -1178,31 +1178,46 @@ If RECIPIENTS is nil, it performs symmetric encryption." (epg-reset context))) ;;;###autoload -(defun epg-start-export-keys (context pattern) +(defun epg-start-export-keys (context keys) "Initiate an export keys operation. If you use this function, you will need to wait for the completion of `epg-gpg-program' by using `epg-wait-for-completion' and call `epg-reset' to clear a temporaly output file. If you are unsure, use synchronous version of this function -`epg-export-keys' instead." +`epg-export-keys-to-file' or `epg-export-keys-to-string' instead." (epg-context-set-result context nil) - (epg-context-set-output-file context (epg-make-temp-file "epg-output")) - (epg-start context (list "--export" pattern))) + (epg-start context (cons "--export" + (mapcar + (lambda (key) + (epg-sub-key-id (epg-key-sub-key-list key))) + keys)))) ;;;###autoload -(defun epg-export-keys (context pattern) - "Extract public keys matched with PATTERN and return them." +(defun epg-export-keys-to-file (context keys file) + "Extract public KEYS." (unwind-protect (progn - (epg-start-export-keys context pattern) + (if keys + (epg-context-set-output-file context file) + (epg-context-set-output-file context + (epg-make-temp-file "epg-output"))) + (epg-start-export-keys context keys) (epg-wait-for-completion context) (if (epg-context-result-for context 'error) (error "Export keys failed")) - (epg-read-output context)) + (unless file + (epg-read-output context))) + (unless file + (epg-delete-output-file context)) (epg-reset context))) ;;;###autoload +(defun epg-export-keys-to-string (context keys) + "Extract public KEYS and return them as a string." + (epg-export-keys-to-file context keys nil)) + +;;;###autoload (defun epg-start-import-keys (context keys) "Initiate an import keys operation. KEYS is a data object. @@ -1241,27 +1256,29 @@ If you are unsure, use synchronous version of this function (epg-import-keys-1 context (epg-make-data-from-string keys))) ;;;###autoload -(defun epg-start-delete-key (context key &optional allow-secret) - "Initiate an delete key operation. +(defun epg-start-delete-keys (context keys &optional allow-secret) + "Initiate an delete keys operation. If you use this function, you will need to wait for the completion of `epg-gpg-program' by using `epg-wait-for-completion' and call `epg-reset' to clear a temporaly output file. If you are unsure, use synchronous version of this function -`epg-delete-key' instead." +`epg-delete-keys' instead." (epg-context-set-result context nil) - (epg-context-set-output-file context (epg-make-temp-file "epg-output")) - (epg-start context (list (if allow-secret + (epg-start context (cons (if allow-secret "--delete-secret-key" "--delete-key") - (epg-sub-key-id (car (epg-key-sub-key-list key)))))) + (mapcar + (lambda (key) + (epg-sub-key-id (epg-key-sub-key-list key))) + keys)))) ;;;###autoload -(defun epg-delete-key (context key &optional allow-secret) - "Delete KEY from the key ring." +(defun epg-delete-keys (context keys &optional allow-secret) + "Delete KEYS from the key ring." (unwind-protect (progn - (epg-start-delete-key context key) + (epg-start-delete-keys context keys) (epg-wait-for-completion context t) (if (epg-context-result-for context 'error) (error "Delete key failed"))) -- 1.7.10.4