(defvar epa-keys-buffer nil)
(defvar epa-key-buffer-alist nil)
(defvar epa-key nil)
-(defvar epa-customize-buffer nil)
+(defvar epa-list-keys-arguments nil)
(defvar epa-keys-mode-map
(let ((keymap (make-sparse-keymap)))
(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 "n" 'next-line)
(define-key keymap "p" 'previous-line)
(define-key keymap " " 'scroll-up)
(let ((inhibit-read-only t)
buffer-read-only)
(erase-buffer)
- (epa-list-keys-1 name nil)
+ (epa-list-keys-1 name mode)
(epa-keys-mode))
+ (make-local-variable 'epa-list-keys-arguments)
+ (setq epa-list-keys-arguments (list name mode))
(goto-char (point-min))
(pop-to-buffer (current-buffer)))
cipher)
(message "Encrypting %s...done" (file-name-nondirectory file))))
-(defun epa-customize ()
- (interactive)
- (unless (and epa-customize-buffer
- (buffer-live-p epa-customize-buffer))
- (setq epa-customize-buffer (generate-new-buffer "*Customize*")))
- (let ((inhibit-read-only t)
- buffer-read-only
- (configuration (epg-configuration)))
- (set-buffer epa-customize-buffer)
- (erase-buffer)
- (insert (format "GnuPG %s\n\n" (cdr (assq 'version configuration))))
- (insert "Cipher:\n")
- (apply #'widget-create 'radio-button-choice
- :notify (lambda (widget &rest ignore)
- (message "Set %s" (widget-get widget :value)))
- (mapcar
- (lambda (algorithm)
- (list 'item
- :tag (cdr (assq algorithm epg-cipher-algorithm-alist))
- algorithm))
- (cdr (assq 'cipher configuration))))
- (insert "Digest:\n")
- (apply #'widget-create 'radio-button-choice
- :notify (lambda (widget &rest ignore)
- (message "Set %s" (widget-get widget :value)))
- (mapcar
- (lambda (algorithm)
- (list 'item
- :tag (cdr (assq algorithm epg-digest-algorithm-alist))
- algorithm))
- (cdr (assq 'digest configuration))))
- (insert "Compress:\n")
- (apply #'widget-create 'radio-button-choice
- :notify (lambda (widget &rest ignore)
- (message "Set %s" (widget-get widget :value)))
- (mapcar
- (lambda (algorithm)
- (list 'item
- :inline t
- :tag (cdr (assq algorithm epg-compress-algorithm-alist))
- algorithm))
- (cdr (assq 'compress configuration))))
- (insert "\n")
- (epa-list-keys-1 nil t)
- (epa-keys-mode)
- (goto-char (point-min))
- (pop-to-buffer (current-buffer))))
+(defun epa-delete-key (key)
+ (interactive
+ (list
+ (save-excursion
+ (beginning-of-line)
+ (get-text-property (point) 'epa-key))))
+ (let ((context (epg-make-context)))
+ (message "Deleting %s..."
+ (epg-sub-key-id (car (epg-key-sub-key-list key))))
+ (epg-delete-key context key)
+ (apply #'epa-list-keys epa-list-keys-arguments)
+ (message "Deleting %s...done"
+ (epg-sub-key-id (car (epg-key-sub-key-list key))))))
(provide 'epa)
(9 . "Not a secret key")
(10 . "Key not trusted")))
+(defconst epg-delete-problem-alist
+ '((1 . "No such key")
+ (2 . "Must delete secret key first")
+ (3 . "Ambigious specification")))
+
(defvar epg-key-validity-alist
'((?o . unknown)
(?i . invalid)
epg-pending-status-list)
(accept-process-output (epg-context-process context) 1))))
-(defun epg-wait-for-completion (context)
- (if (eq (process-status (epg-context-process context)) 'run)
+(defun epg-wait-for-completion (context &optional no-eof)
+ (if (and (not no-eof)
+ (eq (process-status (epg-context-process context)) 'run))
(process-send-eof (epg-context-process context)))
(while (eq (process-status (epg-context-process context)) 'run)
;; We can't use accept-process-output instead of sit-for here
(cons 'no-recipients
(epg-context-result-for epg-context 'error))))
+(defun epg-status-DELETE_PROBLEM (process string)
+ (if (string-match "\\`\\([0-9]+\\)" string)
+ (epg-context-set-result-for
+ epg-context 'error
+ (cons (cons 'delete-problem (string-to-number (match-string 1 string)))
+ (epg-context-result-for epg-context 'error)))))
+
(defun epg-passphrase-callback-function (key-id handback)
(read-passwd
(if (eq key-id 'SYM)
(epg-context-set-output-file context
(epg-make-temp-file "epg-output")))
(epg-start-decrypt context (epg-make-data-from-file cipher))
- (epg-wait-for-completion context)
+ (epg-wait-for-completion context t)
(if (epg-context-result-for context 'error)
(error "Decrypt failed: %S"
(epg-context-result-for context 'error)))
(epg-make-data-from-file signed-text))
(epg-start-verify context
(epg-make-data-from-file signature)))
- (epg-wait-for-completion context)
+ (epg-wait-for-completion context t)
(unless plain
(epg-read-output context)))
(unless plain
(epg-context-set-output-file context
(epg-make-temp-file "epg-output")))
(epg-start-sign context (epg-make-data-from-file plain) mode)
- (epg-wait-for-completion context)
+ (epg-wait-for-completion context t)
(if (epg-context-result-for context 'error)
(error "Sign failed: %S"
(epg-context-result-for context 'error)))
(epg-make-temp-file "epg-output")))
(epg-start-encrypt context (epg-make-data-from-file plain)
recipients sign always-trust)
- (epg-wait-for-completion context)
+ (epg-wait-for-completion context t)
(if (epg-context-result-for context 'error)
(error "Encrypt failed: %S"
(epg-context-result-for context 'error)))
(unwind-protect
(progn
(epg-start-import-keys context keys)
- (epg-wait-for-completion context)
+ (epg-wait-for-completion context (epg-data-file keys))
(if (epg-context-result-for context 'error)
(error "Import keys failed"))
(epg-read-output context))
"Add keys from a string KEYS."
(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.
+
+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-context-set-result context nil)
+ (epg-context-set-output-file context (epg-make-temp-file "epg-output"))
+ (epg-start context (list (if allow-secret
+ "--delete-secret-key"
+ "--delete-key")
+ (epg-sub-key-id (car (epg-key-sub-key-list key))))))
+
+;;;###autoload
+(defun epg-delete-key (context key &optional allow-secret)
+ "Delete KEY from the key ring."
+ (unwind-protect
+ (progn
+ (epg-start-delete-key context key)
+ (epg-wait-for-completion context t)
+ (if (epg-context-result-for context 'error)
+ (error "Delete key failed")))
+ (epg-reset context)))
+
(provide 'epg)
;;; epg.el ends here