From bf351aa129cd4460fb2fd9cb9c4029a38a1f6e8d Mon Sep 17 00:00:00 2001 From: ueno Date: Wed, 12 Apr 2006 05:46:45 +0000 Subject: [PATCH] Barf if cryptographic operation has failed. --- epg.el | 55 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/epg.el b/epg.el index cd5ecb6..60af26d 100644 --- a/epg.el +++ b/epg.el @@ -276,7 +276,8 @@ This function is for internal use only." (accept-process-output (epg-context-process context) 1)))) (defun epg-wait-for-completion (context) - (process-send-eof (epg-context-process context)) + (if (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 ;; because it may cause an interrupt during the sentinel execution. @@ -378,7 +379,7 @@ This function is for internal use only." (epg-context-result-for epg-context 'verify))))) (defun epg-status-TRUST_UNDEFINED (process string) - (let ((signature (car (epg-context-result-for-for epg-context 'verify)))) + (let ((signature (car (epg-context-result-for epg-context 'verify)))) (if (and signature (eq (epg-signature-status signature) 'good)) (epg-signature-set-validity signature 'unknown)))) @@ -407,9 +408,6 @@ This function is for internal use only." (eq (epg-signature-status signature) 'good)) (epg-signature-set-validity signature 'full)))) -(defun epg-status-DECRYPTION_FAILED (process string) - (epg-context-set-result-for epg-context 'decrypt 'failed)) - (defun epg-status-PROGRESS (process string) (if (string-match "\\`\\([^ ]+\\) \\([^ ]\\) \\([0-9]+\\) \\([0-9]+\\)" string) @@ -420,6 +418,42 @@ This function is for internal use only." (string-to-number (match-string 4 string)) (cdr (epg-context-progress-callback-info epg-context))))) +(defun epg-status-DECRYPTION_FAILED (process string) + (epg-context-set-result-for + epg-context 'error + (cons 'decryption-failed + (epg-context-result-for epg-context 'error)))) + +(defun epg-status-NODATA (process string) + (epg-context-set-result-for + epg-context 'error + (cons (cons 'no-data (string-to-number string)) + (epg-context-result-for epg-context 'error)))) + +(defun epg-status-UNEXPECTED (process string) + (epg-context-set-result-for + epg-context 'error + (cons (cons 'unexpected (string-to-number string)) + (epg-context-result-for epg-context 'error)))) + +(defun epg-status-KEYEXPIRED (process string) + (epg-context-set-result-for + epg-context 'error + (cons (cons 'key-expired string) + (epg-context-result-for epg-context 'error)))) + +(defun epg-status-KEYREVOKED (process string) + (epg-context-set-result-for + epg-context 'error + (cons 'key-revoked + (epg-context-result-for epg-context 'error)))) + +(defun epg-status-BADARMOR (process string) + (epg-context-set-result-for + epg-context 'error + (cons 'bad-armor + (epg-context-result-for epg-context 'error)))) + (defun epg-passphrase-callback-function (key-id handback) (read-passwd (if (eq key-id 'SYM) @@ -511,8 +545,9 @@ If you are unsure, use synchronous version of this function (progn (epg-decrypt-start context input-file) (epg-wait-for-completion context) - (unless (epg-context-result-for context 'decrypt) - (epg-read-output context))) + (if (epg-context-result-for context 'error) + (error "Decryption failed")) + (epg-read-output context)) (epg-reset context) (if (file-exists-p input-file) (delete-file input-file)))) @@ -589,7 +624,7 @@ If you are unsure, use synchronous version of this function `epg-sign-string' instead." (epg-context-set-output-file context (epg-make-temp-file "epg-output")) (epg-start context - (append (list (if (eq 'clearsign) + (append (list (if (eq mode 'clearsign) "--clearsign" (if (or (eq mode t) (eq mode 'detached)) "--detach-sign" @@ -612,6 +647,8 @@ Otherwise, it makes a normal signature." (progn (epg-sign-start context string mode) (epg-wait-for-completion context) + (if (epg-context-result-for context 'error) + (error "Sign failed")) (epg-read-output context)) (epg-reset context))) @@ -656,6 +693,8 @@ If RECIPIENTS is nil, it performs symmetric encryption." (progn (epg-encrypt-start context string recipients sign always-trust) (epg-wait-for-completion context) + (if (epg-context-result-for context 'error) + (error "Encrypt failed")) (epg-read-output context)) (epg-reset context))) -- 1.7.10.4