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