"The EasyPG Assistant"
:group 'epg)
+(defcustom epa-armor nil
+ "If non-nil, epa commands create ASCII armored output."
+ :type 'boolean
+ :group 'epa)
+
+(defcustom epa-textmode nil
+ "If non-nil, epa commands treat input files as text."
+ :type 'boolean
+ :group 'epa)
+
+(defcustom epa-popup-info-window nil
+ "If non-nil, status information from epa commands is displayed on
+the separate window."
+ :type 'boolean
+ :group 'epa)
+
+(defcustom epa-info-window-height 5
+ "Number of lines used to display status information."
+ :type 'integer
+ :group 'epa)
+
(defgroup epa-faces nil
"Faces for epa-mode."
:group 'epa)
(defvar epa-key-buffer-alist nil)
(defvar epa-key nil)
(defvar epa-list-keys-arguments nil)
+(defvar epa-info-buffer nil)
(defvar epa-keys-mode-map
(let ((keymap (make-sparse-keymap)))
(define-key keymap "p" 'previous-line)
(define-key keymap " " 'scroll-up)
(define-key keymap [delete] 'scroll-down)
+ (define-key keymap "q" 'epa-exit-buffer)
+ keymap))
+
+(defvar epa-key-mode-map
+ (let ((keymap (make-sparse-keymap)))
(define-key keymap "q" 'bury-buffer)
keymap))
+(defvar epa-info-mode-map
+ (let ((keymap (make-sparse-keymap)))
+ (define-key keymap "q" 'delete-window)
+ keymap))
+
+(defvar epa-exit-buffer-function #'bury-buffer)
+
(define-widget 'epa-key 'push-button
"Button for representing a epg-key object."
:format "%[%v%]"
- :button-face-get 'epa-key-widget-button-face-get
- :value-create 'epa-key-widget-value-create
- :action 'epa-key-widget-action
- :help-echo 'epa-key-widget-help-echo)
+ :button-face-get 'epa--key-widget-button-face-get
+ :value-create 'epa--key-widget-value-create
+ :action 'epa--key-widget-action
+ :help-echo 'epa--key-widget-help-echo)
-(defun epa-key-widget-action (widget &optional event)
- (epa-show-key (widget-get widget :value)))
+(defun epa--key-widget-action (widget &optional event)
+ (epa--show-key (widget-get widget :value)))
-(defun epa-key-widget-value-create (widget)
+(defun epa--key-widget-value-create (widget)
(let* ((key (widget-get widget :value))
(primary-sub-key (car (epg-key-sub-key-list key)))
(primary-user-id (car (epg-key-user-id-list key))))
? ))
(epg-sub-key-id primary-sub-key)
" "
- (epg-user-id-name primary-user-id))))
+ (if (stringp (epg-user-id-string primary-user-id))
+ (epg-user-id-string primary-user-id)
+ (epg-decode-dn (epg-user-id-string primary-user-id))))))
-(defun epa-key-widget-button-face-get (widget)
+(defun epa--key-widget-button-face-get (widget)
(let ((validity (epg-sub-key-validity (car (epg-key-sub-key-list
(widget-get widget :value))))))
(if validity
(cdr (assq validity epa-validity-face-alist))
'default)))
-(defun epa-key-widget-help-echo (widget)
+(defun epa--key-widget-help-echo (widget)
(format "Show %s"
(epg-sub-key-id (car (epg-key-sub-key-list
(widget-get widget :value))))))
;; if buffer-file-name is not set.
(font-lock-set-defaults)
(widget-setup)
+ (make-local-variable 'epa-exit-buffer-function)
(run-hooks 'epa-keys-mode-hook))
-(defvar epa-key-mode-map
- (let ((keymap (make-sparse-keymap)))
- (define-key keymap "q" 'bury-buffer)
- keymap))
-
(defun epa-key-mode ()
- "Major mode for `epa-show-key'."
+ "Major mode for a key description."
(kill-all-local-variables)
(buffer-disable-undo)
(setq major-mode 'epa-key-mode
;; In XEmacs, auto-initialization of font-lock is not effective
;; if buffer-file-name is not set.
(font-lock-set-defaults)
+ (make-local-variable 'epa-exit-buffer-function)
(run-hooks 'epa-key-mode-hook))
+(defun epa-info-mode ()
+ "Major mode for `epa-info-buffer'."
+ (kill-all-local-variables)
+ (buffer-disable-undo)
+ (setq major-mode 'epa-info-mode
+ mode-name "Info"
+ truncate-lines t
+ buffer-read-only t)
+ (use-local-map epa-info-mode-map)
+ (run-hooks 'epa-info-mode-hook))
+
+(defun epa-mark (&optional arg)
+ "Mark the current line.
+If ARG is non-nil, unmark the current line."
+ (interactive "P")
+ (let ((inhibit-read-only t)
+ buffer-read-only
+ properties)
+ (beginning-of-line)
+ (setq properties (text-properties-at (point)))
+ (delete-char 1)
+ (insert (if arg " " "*"))
+ (set-text-properties (1- (point)) (point) properties)
+ (forward-line)))
+
+(defun epa-unmark (&optional arg)
+ "Unmark the current line.
+If ARG is non-nil, mark the current line."
+ (interactive "P")
+ (epa-mark (not arg)))
+
+(defun epa-toggle-mark ()
+ "Toggle the mark the current line."
+ (interactive)
+ (epa-mark (eq (char-after (save-excursion (beginning-of-line) (point))) ?*)))
+
+(defun epa-exit-buffer ()
+ "Exit the current buffer.
+`epa-exit-buffer-function' is called if it is set."
+ (interactive)
+ (funcall epa-exit-buffer-function))
+
;;;###autoload
-(defun epa-list-keys (&optional name mode)
+(defun epa-list-keys (&optional name mode protocol)
(interactive
(if current-prefix-arg
(let ((name (read-string "Pattern: "
(if epa-list-keys-arguments
(car epa-list-keys-arguments)))))
(list (if (equal name "") nil name)
- (y-or-n-p "Secret keys? ")))
- (or epa-list-keys-arguments (list nil nil))))
+ (y-or-n-p "Secret keys? ")
+ (intern (completing-read "Protocol? "
+ '(("OpenPGP") ("CMS"))
+ nil t))))
+ (or epa-list-keys-arguments (list nil nil nil))))
(unless (and epa-keys-buffer
(buffer-live-p epa-keys-buffer))
(setq epa-keys-buffer (generate-new-buffer "*Keys*")))
(set-buffer epa-keys-buffer)
(let ((inhibit-read-only t)
- buffer-read-only)
- (erase-buffer)
- (epa-list-keys-1 name mode)
+ buffer-read-only
+ (point (point-min))
+ (context (epg-make-context protocol)))
+ (unless (get-text-property point 'epa-list-keys)
+ (setq point (next-single-property-change point 'epa-list-keys)))
+ (when point
+ (delete-region point
+ (or (next-single-property-change point 'epa-list-keys)
+ (point-max)))
+ (goto-char point))
+ (epa-insert-keys context name mode)
(epa-keys-mode))
(make-local-variable 'epa-list-keys-arguments)
- (setq epa-list-keys-arguments (list name mode))
+ (setq epa-list-keys-arguments (list name mode protocol))
(goto-char (point-min))
(pop-to-buffer (current-buffer)))
-(defun epa-list-keys-1 (name mode)
- (let ((inhibit-read-only t)
- buffer-read-only
- (keys (epg-list-keys name mode))
- point)
- (while keys
- (setq point (point))
- (insert " ")
- (put-text-property point (point) 'epa-key (car keys))
- (widget-create 'epa-key :value (car keys))
- (insert "\n")
- (setq keys (cdr keys)))))
-
-(defun epa-marked-keys ()
+(defun epa-insert-keys (context name mode)
+ (save-excursion
+ (save-restriction
+ (narrow-to-region (point) (point))
+ (let ((keys (epg-list-keys context name mode))
+ point)
+ (while keys
+ (setq point (point))
+ (insert " ")
+ (add-text-properties point (point)
+ (list 'epa-key (car keys)
+ 'front-sticky nil
+ 'rear-nonsticky t
+ 'start-open t
+ 'end-open t))
+ (widget-create 'epa-key :value (car keys))
+ (insert "\n")
+ (setq keys (cdr keys))))
+ (add-text-properties (point-min) (point-max)
+ (list 'epa-list-keys t
+ 'front-sticky nil
+ 'rear-nonsticky t
+ 'start-open t
+ 'end-open t)))))
+
+(defun epa--marked-keys ()
(or (save-excursion
(set-buffer epa-keys-buffer)
(goto-char (point-min))
(nreverse keys)))
(save-excursion
(beginning-of-line)
- (get-text-property (point) 'epa-key))))
+ (let ((key (get-text-property (point) 'epa-key)))
+ (if key
+ (list key))))))
-(defun epa-select-keys (prompt &optional names)
+;;;###autoload
+(defun epa-select-keys (context prompt &optional names secret)
+ "Display a user's keyring and ask him to select keys.
+CONTEXT is an epg-context.
+PROMPT is a string to prompt with.
+NAMES is a list of strings to be matched with keys. If it is nil, all
+the keys are listed.
+If SECRET is non-nil, list secret keys instead of public keys."
(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)
+ buffer-read-only)
(set-buffer epa-keys-buffer)
(erase-buffer)
(insert prompt "\n")
(widget-create 'link
+ :notify (lambda (&rest ignore) (abort-recursive-edit))
+ :help-echo
+ (substitute-command-keys
+ "Click here or \\[abort-recursive-edit] to cancel")
+ "Cancel")
+ (widget-create 'link
:notify (lambda (&rest ignore) (exit-recursive-edit))
:help-echo
(substitute-command-keys
(insert "\n\n")
(if names
(while names
- (setq point (point))
- (epa-list-keys-1 (car names) nil)
- (goto-char point)
- (epa-mark)
+ (epa-insert-keys context (car names) secret)
+ (if (get-text-property (point) 'epa-list-keys)
+ (epa-mark))
(goto-char (point-max))
(setq names (cdr names)))
- (epa-list-keys-1 nil nil))
+ (if secret
+ (progn
+ (epa-insert-keys context nil secret)
+ (if (get-text-property (point) 'epa-list-keys)
+ (epa-mark)))
+ (epa-insert-keys context nil nil)))
(epa-keys-mode)
+ (setq epa-exit-buffer-function #'abort-recursive-edit)
(goto-char (point-min))
- (pop-to-buffer (current-buffer))
- (unwind-protect
- (progn
- (recursive-edit)
- (epa-marked-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)
+ (pop-to-buffer (current-buffer)))
+ (unwind-protect
+ (progn
+ (recursive-edit)
+ (epa--marked-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)))
(entry (assoc (epg-sub-key-id primary-sub-key)
epa-key-buffer-alist))
epg-key-validity-alist)))
" ")
" "
- (epg-user-id-name (car pointer))
+ (if (stringp (epg-user-id-string (car pointer)))
+ (epg-user-id-string (car pointer))
+ (epg-decode-dn (epg-user-id-string (car pointer))))
"\n")
(setq pointer (cdr pointer)))
(setq pointer (epg-key-sub-key-list key))
(cdr (assq (epg-sub-key-algorithm (car pointer))
epg-pubkey-algorithm-alist))
"\n\tCreated: "
- (epg-sub-key-creation-time (car pointer))
+ (format-time-string "%Y-%m-%d"
+ (epg-sub-key-creation-time (car pointer)))
(if (epg-sub-key-expiration-time (car pointer))
- (format "\n\tExpires: %s" (epg-sub-key-expiration-time
- (car pointer)))
+ (format "\n\tExpires: %s"
+ (format-time-string "%Y-%m-%d"
+ (epg-sub-key-expiration-time
+ (car pointer))))
"")
"\n\tCapabilities: "
(mapconcat #'symbol-name
(pop-to-buffer (current-buffer))
(epa-key-mode)))
-(defun epa-show-key-notify (widget &rest ignore)
- (epa-show-key (widget-get widget :value)))
-
-(defun epa-mark (&optional arg)
- "Mark the current line."
- (interactive "P")
- (let ((inhibit-read-only t)
- buffer-read-only
- properties)
- (beginning-of-line)
- (setq properties (text-properties-at (point)))
- (delete-char 1)
- (insert (if arg " " "*"))
- (set-text-properties (1- (point)) (point) properties)
- (forward-line)))
-
-(defun epa-unmark (&optional arg)
- "Unmark the current line."
- (interactive "P")
- (epa-mark (not arg)))
+(defun epa-display-info (info)
+ (if epa-popup-info-window
+ (progn
+ (unless epa-info-buffer
+ (setq epa-info-buffer (generate-new-buffer "*Info*")))
+ (save-excursion
+ (set-buffer epa-info-buffer)
+ (let ((inhibit-read-only t)
+ buffer-read-only)
+ (erase-buffer)
+ (insert info))
+ (epa-info-mode))
+ (pop-to-buffer epa-info-buffer)
+ (if (> (window-height) epa-info-window-height)
+ (shrink-window (- (window-height) epa-info-window-height)))
+ (goto-char (point-min)))
+ (message "%s" info)))
+
+(defun epa-passphrase-callback-function (context key-id handback)
+ (if (eq key-id 'SYM)
+ (read-passwd "Passphrase for symmetric encryption: "
+ (eq (epg-context-operation context) 'encrypt))
+ (read-passwd
+ (if (eq key-id 'PIN)
+ "Passphrase for PIN: "
+ (let ((entry (assoc key-id epg-user-id-alist)))
+ (if entry
+ (format "Passphrase for %s %s: " key-id (cdr entry))
+ (format "Passphrase for %s: " key-id)))))))
+
+(defun epa-progress-callback-function (context what char current total
+ handback)
+ (message "%s: %d%% (%d/%d)" what
+ (if (> total 0) (floor (* (/ current (float total)) 100)) 0)
+ current total))
+;;;###autoload
(defun epa-decrypt-file (file)
+ "Decrypt FILE."
(interactive "fFile: ")
(let* ((default-name (file-name-sans-extension file))
(plain (expand-file-name
(file-name-directory default-name)
default-name)))
(context (epg-make-context)))
+ (epg-context-set-passphrase-callback context
+ #'epa-passphrase-callback-function)
+ (epg-context-set-progress-callback context
+ #'epa-progress-callback-function)
(message "Decrypting %s..." (file-name-nondirectory file))
(epg-decrypt-file context file plain)
- (message "Decrypting %s...done" (file-name-nondirectory file))))
+ (message "Decrypting %s...done" (file-name-nondirectory file))
+ (if (epg-context-result-for context 'verify)
+ (epa-display-info (epg-verify-result-to-string
+ (epg-context-result-for context 'verify))))))
+;;;###autoload
(defun epa-verify-file (file)
+ "Verify FILE."
(interactive "fFile: ")
(let* ((context (epg-make-context))
(plain (if (equal (file-name-extension file) "sig")
- (file-name-sans-extension file)))
- signature)
+ (file-name-sans-extension file))))
+ (epg-context-set-progress-callback context
+ #'epa-progress-callback-function)
(message "Verifying %s..." (file-name-nondirectory file))
(epg-verify-file context file plain)
- (setq signature (reverse (epg-context-result-for context 'verify)))
- (with-output-to-temp-buffer "*epa-verify-file*"
- (set-buffer standard-output)
- (while signature
- (insert (format "%s: %s %s %s\n"
- (epg-signature-status (car signature))
- (epg-signature-key-id (car signature))
- (epg-signature-user-id (car signature))
- (epg-signature-validity (car signature))))
- (setq signature (cdr signature))))
- (shrink-window-if-larger-than-buffer
- (get-buffer-window "*epa-verify-file*"))
- (message "Verifying %s...done" (file-name-nondirectory file))))
-
-(defun epa-sign-file (file detached)
+ (message "Verifying %s...done" (file-name-nondirectory file))
+ (if (epg-context-result-for context 'verify)
+ (epa-display-info (epg-verify-result-to-string
+ (epg-context-result-for context 'verify))))))
+
+;;;###autoload
+(defun epa-sign-file (file signers mode)
+ "Sign FILE by SIGNERS keys selected."
(interactive
(list (expand-file-name (read-file-name "File: "))
- (y-or-n-p "Make a detached signature? ")))
- (let ((signature (concat file (if detached ".sig" ".gpg")))
+ (epa-select-keys (epg-make-context) "Select keys for signing.
+If no one is selected, default secret key is used. "
+ nil t)
+ (if (y-or-n-p "Make a detached signature? ")
+ 'detached
+ (if (y-or-n-p "Make a cleartext signature? ")
+ 'clear))))
+ (let ((signature (concat file
+ (if (or epa-armor
+ (not (memq mode '(nil t normal detached))))
+ ".asc"
+ (if (memq mode '(t detached))
+ ".sig"
+ ".gpg"))))
(context (epg-make-context)))
+ (epg-context-set-armor context epa-armor)
+ (epg-context-set-textmode context epa-textmode)
+ (epg-context-set-signers context signers)
+ (epg-context-set-passphrase-callback context
+ #'epa-passphrase-callback-function)
+ (epg-context-set-progress-callback context
+ #'epa-progress-callback-function)
(message "Signing %s..." (file-name-nondirectory file))
- (epg-sign-file context file signature (not (null detached)))
+ (epg-sign-file context file signature mode)
(message "Signing %s...done" (file-name-nondirectory file))))
+;;;###autoload
(defun epa-encrypt-file (file recipients)
+ "Encrypt FILE for 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"))
+ (epa-select-keys (epg-make-context) "Select recipients for encryption.
+If no one is selected, symmetric encryption will be performed. ")))
+ (let ((cipher (concat file (if epa-armor ".asc" ".gpg")))
(context (epg-make-context)))
+ (epg-context-set-armor context epa-armor)
+ (epg-context-set-textmode context epa-textmode)
+ (epg-context-set-passphrase-callback context
+ #'epa-passphrase-callback-function)
+ (epg-context-set-progress-callback context
+ #'epa-progress-callback-function)
(message "Encrypting %s..." (file-name-nondirectory file))
- (epg-encrypt-file context
- file
- recipients
- cipher)
+ (epg-encrypt-file context file recipients cipher)
(message "Encrypting %s...done" (file-name-nondirectory file))))
-(defun epa-delete-keys (keys)
+;;;###autoload
+(defun epa-decrypt-region (start end)
+ "Decrypt the current region between START and END.
+
+Don't use this command in Lisp programs!"
+ (interactive "r")
+ (save-excursion
+ (let ((context (epg-make-context))
+ plain)
+ (epg-context-set-passphrase-callback context
+ #'epa-passphrase-callback-function)
+ (epg-context-set-progress-callback context
+ #'epa-progress-callback-function)
+ (message "Decrypting...")
+ (setq plain (epg-decrypt-string context (buffer-substring start end)))
+ (message "Decrypting...done")
+ (delete-region start end)
+ (goto-char start)
+ (insert (decode-coding-string plain coding-system-for-read))
+ (if (epg-context-result-for context 'verify)
+ (epa-display-info (epg-verify-result-to-string
+ (epg-context-result-for context 'verify)))))))
+
+;;;###autoload
+(defun epa-decrypt-armor-in-region (start end)
+ "Decrypt OpenPGP armors in the current region between START and END.
+
+Don't use this command in Lisp programs!"
+ (interactive "r")
+ (save-excursion
+ (save-restriction
+ (narrow-to-region start end)
+ (goto-char start)
+ (let (armor-start armor-end charset coding-system)
+ (while (re-search-forward "-----BEGIN PGP MESSAGE-----$" nil t)
+ (setq armor-start (match-beginning 0)
+ armor-end (re-search-forward "^-----END PGP MESSAGE-----$"
+ nil t))
+ (unless armor-end
+ (error "No armor tail"))
+ (goto-char armor-start)
+ (if (re-search-forward "^Charset: \\(.*\\)" armor-end t)
+ (setq charset (match-string 1)))
+ (if coding-system-for-read
+ (setq coding-system coding-system-for-read)
+ (if charset
+ (setq coding-system (intern (downcase charset)))
+ (setq coding-system 'utf-8)))
+ (let ((coding-system-for-read coding-system))
+ (epa-decrypt-region start end)))))))
+
+;;;###autoload
+(defun epa-verify-region (start end)
+ "Verify the current region between START and END.
+
+Don't use this command in Lisp programs!"
+ (interactive "r")
+ (let ((context (epg-make-context)))
+ (epg-context-set-progress-callback context
+ #'epa-progress-callback-function)
+ (epg-verify-string context
+ (encode-coding-string
+ (buffer-substring start end)
+ coding-system-for-write))
+ (if (epg-context-result-for context 'verify)
+ (epa-display-info (epg-verify-result-to-string
+ (epg-context-result-for context 'verify))))))
+
+;;;###autoload
+(defun epa-verify-cleartext-in-region (start end)
+ "Verify OpenPGP cleartext signed messages in the current region
+between START and END.
+
+Don't use this command in Lisp programs!"
+ (interactive "r")
+ (save-excursion
+ (save-restriction
+ (narrow-to-region start end)
+ (goto-char start)
+ (let (armor-start armor-end)
+ (while (re-search-forward "-----BEGIN PGP SIGNED MESSAGE-----$"
+ nil t)
+ (setq armor-start (match-beginning 0))
+ (unless (re-search-forward "^-----BEGIN PGP SIGNATURE-----$"
+ nil t)
+ (error "Invalid cleartext signed message"))
+ (setq armor-end (re-search-forward
+ "^-----END PGP SIGNATURE-----$"
+ nil t))
+ (unless armor-end
+ (error "No armor tail"))
+ (epa-verify-region armor-start armor-end))))))
+
+;;;###autoload
+(defun epa-sign-region (start end signers mode)
+ "Sign the current region between START and END by SIGNERS keys selected.
+
+Don't use this command in Lisp programs!"
+ (interactive
+ (list (region-beginning) (region-end)
+ (epa-select-keys (epg-make-context) "Select keys for signing.
+If no one is selected, default secret key is used. "
+ nil t)
+ (if (y-or-n-p "Make a detached signature? ")
+ 'detached
+ (if (y-or-n-p "Make a cleartext signature? ")
+ 'clear))))
+ (save-excursion
+ (let ((context (epg-make-context))
+ signature)
+ (epg-context-set-armor context epa-armor)
+ (epg-context-set-textmode context epa-textmode)
+ (epg-context-set-signers context signers)
+ (epg-context-set-passphrase-callback context
+ #'epa-passphrase-callback-function)
+ (epg-context-set-progress-callback context
+ #'epa-progress-callback-function)
+ (message "Signing...")
+ (setq signature (epg-sign-string context
+ (encode-coding-string
+ (buffer-substring start end)
+ coding-system-for-write)
+ mode))
+ (message "Signing...done")
+ (delete-region start end)
+ (insert (decode-coding-string signature coding-system-for-read)))))
+
+;;;###autoload
+(defun epa-encrypt-region (start end recipients)
+ "Encrypt the current region between START and END for RECIPIENTS.
+
+Don't use this command in Lisp programs!"
+ (interactive
+ (list (region-beginning) (region-end)
+ (epa-select-keys (epg-make-context) "Select recipients for encryption.
+If no one is selected, symmetric encryption will be performed. ")))
+ (save-excursion
+ (let ((context (epg-make-context))
+ cipher)
+ (epg-context-set-armor context epa-armor)
+ (epg-context-set-textmode context epa-textmode)
+ (epg-context-set-passphrase-callback context
+ #'epa-passphrase-callback-function)
+ (epg-context-set-progress-callback context
+ #'epa-progress-callback-function)
+ (message "Encrypting...")
+ (setq cipher (epg-encrypt-string context
+ (encode-coding-string
+ (buffer-substring start end)
+ coding-system-for-write)
+ recipients))
+ (message "Encrypting...done")
+ (delete-region start end)
+ (insert cipher))))
+
+;;;###autoload
+(defun epa-delete-keys (keys &optional allow-secret)
+ "Delete selected KEYS.
+
+Don't use this command in Lisp programs!"
(interactive
- (let ((keys (epa-marked-keys)))
+ (let ((keys (epa--marked-keys)))
(unless keys
(error "No keys selected"))
- (list keys)))
+ (list keys
+ (eq (nth 1 epa-list-keys-arguments) t))))
(let ((context (epg-make-context)))
(message "Deleting...")
- (epg-delete-keys context keys)
- (apply #'epa-list-keys epa-list-keys-arguments)
- (message "Deleting...done")))
+ (epg-delete-keys context keys allow-secret)
+ (message "Deleting...done")
+ (apply #'epa-list-keys epa-list-keys-arguments)))
+;;;###autoload
(defun epa-import-keys (file)
+ "Import keys from FILE.
+
+Don't use this command in Lisp programs!"
(interactive "fFile: ")
(let ((context (epg-make-context)))
(message "Importing %s..." (file-name-nondirectory file))
- (epg-import-keys context file)
- (apply #'epa-list-keys epa-list-keys-arguments)
- (message "Importing %s...done" (file-name-nondirectory file))))
+ (epg-import-keys-from-file context (expand-file-name file))
+ (message "Importing %s...done" (file-name-nondirectory file))
+ (if (epg-context-result-for context 'import)
+ (epa-display-info (epg-import-result-to-string
+ (epg-context-result-for context 'import)))))
+;;;###autoload
(defun epa-export-keys (keys file)
+ "Export selected KEYS to FILE.
+
+Don't use this command in Lisp programs!"
(interactive
- (let ((keys (epa-marked-keys))
+ (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")
+ (concat (epg-sub-key-id (car (epg-key-sub-key-list (car keys))))
+ (if epa-armor ".asc" ".gpg"))
default-directory))
(list keys
(expand-file-name
(file-name-directory default-name)
default-name)))))
(let ((context (epg-make-context)))
+ (epg-context-set-armor context epa-armor)
(message "Exporting to %s..." (file-name-nondirectory file))
- (epg-export-keys context keys file)
+ (epg-export-keys-to-file context keys file)
(message "Exporting to %s...done" (file-name-nondirectory file))))
+;;;###autoload
+(defun epa-sign-keys (keys &optional local)
+ "Sign selected KEYS.
+If a prefix-arg is specified, the signature is marked as non exportable.
+
+Don't use this command in Lisp programs!"
+ (interactive
+ (let ((keys (epa--marked-keys)))
+ (unless keys
+ (error "No keys selected"))
+ (list keys current-prefix-arg)))
+ (let ((context (epg-make-context)))
+ (epg-context-set-passphrase-callback context
+ #'epa-passphrase-callback-function)
+ (epg-context-set-progress-callback context
+ #'epa-progress-callback-function)
+ (message "Signing keys...")
+ (epg-sign-keys context keys local)
+ (message "Signing keys...done")))
+(make-obsolete 'epa-sign-keys "Do not use.")
+
(provide 'epa)
;;; epa.el ends here