From: ueno Date: Tue, 18 Apr 2006 09:21:13 +0000 (+0000) Subject: * epg.el (epg-delete-problem-alist): New constant. X-Git-Tag: epgsm-branchpoint~36 X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=9dfb007e62a86cb53bedea570f8f0e47ff73df01;p=elisp%2Fepg.git * epg.el (epg-delete-problem-alist): New constant. (epg-status-DELETE_PROBLEM): New function. (epg-start-delete-key): New function. (epg-delete-key): New function. (epg-wait-for-completion): Add the NO-EOF argument. --- diff --git a/ChangeLog b/ChangeLog index af8763a..42cd156 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,18 @@ 2006-04-18 Daiki Ueno + * epg.el (epg-delete-problem-alist): New constant. + (epg-status-DELETE_PROBLEM): New function. + (epg-start-delete-key): New function. + (epg-delete-key): New function. + (epg-wait-for-completion): Add the NO-EOF argument. + +2006-04-18 Daiki Ueno + * epg.el (epg-start): Insert the command-line arguments to the debug buffer. (epg-start-encrypt): Wait for BEGIN_ENCRYPTION. + (epg-start-delete-key): New function. + (epg-delete-key): New function. * epa.el (epa-key): New widget. (epa-key-widget-action): New function. diff --git a/epa.el b/epa.el index e0c0ab1..ec65290 100644 --- a/epa.el +++ b/epa.el @@ -143,7 +143,7 @@ (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))) @@ -153,6 +153,7 @@ (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) @@ -248,8 +249,10 @@ (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))) @@ -461,53 +464,19 @@ If no one is selected, symmetric encryption will be performed. ")))) 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) diff --git a/epg.el b/epg.el index 4ed5650..ba5cc04 100644 --- a/epg.el +++ b/epg.el @@ -98,6 +98,11 @@ (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) @@ -484,8 +489,9 @@ This function is for internal use only." 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 @@ -704,6 +710,13 @@ This function is for internal use only." (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) @@ -892,7 +905,7 @@ If PLAIN is nil, it returns the result as a string." (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))) @@ -973,7 +986,7 @@ For a normal or a clear text signature, SIGNED-TEXT should be nil." (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 @@ -1056,7 +1069,7 @@ Otherwise, it makes a normal signature." (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))) @@ -1135,7 +1148,7 @@ If RECIPIENTS is nil, it performs symmetric encryption." (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))) @@ -1211,7 +1224,7 @@ If you are unsure, use synchronous version of this function (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)) @@ -1227,6 +1240,33 @@ If you are unsure, use synchronous version of this function "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