From a11a4144afcb3121ff262c6fc1130ee7dc4fae7b Mon Sep 17 00:00:00 2001 From: ueno Date: Sun, 12 Nov 2006 08:16:43 +0000 Subject: [PATCH] * epg.el (epg-error): New error. (epg--check-decrypt): New function. (epg-decrypt-file): Use it. (epg-decrypt-string): Use it. --- ChangeLog | 5 +++++ epg.el | 43 +++++++++++++++++++++++++++---------------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5e513d9..371e7cb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2006-11-12 Daiki Ueno + * epg.el (epg-error): New error. + (epg--check-decrypt): New function. + (epg-decrypt-file): Use it. + (epg-decrypt-string): Use it. + * epa.el (epa-decrypt-file): Expand file name. (epa-verify-file): Ditto. (epa-import-keys): Ditto. diff --git a/epg.el b/epg.el index 02a98a1..c092e92 100644 --- a/epg.el +++ b/epg.el @@ -158,6 +158,8 @@ (defvar epg-prompt-alist nil) +(put 'epg-error 'error-conditions '(epg-error error)) + (defun epg-make-data-from-file (file) "Make a data object from FILE." (cons 'epg-data (vector file nil))) @@ -1439,21 +1441,21 @@ This function is for internal use only." (cdr (epg-context-progress-callback context)))))) (defun epg--status-DECRYPTION_FAILED (context string) - (epg-context-set-result-for - context 'error - (cons '(decryption-failed) - (epg-context-result-for context 'error)))) + (epg-context-set-result-for context 'decryption-failed t)) + +(defun epg--status-DECRYPTION_OKAY (context string) + (epg-context-set-result-for context 'decryption-okay t)) (defun epg--status-NODATA (context string) (epg-context-set-result-for context 'error - (cons (list 'no-data (cons 'reason (string-to-number string))) + (cons (cons 'no-data (string-to-number string)) (epg-context-result-for context 'error)))) (defun epg--status-UNEXPECTED (context string) (epg-context-set-result-for context 'error - (cons (list 'unexpected (cons 'reason (string-to-number string))) + (cons (cons 'unexpected (string-to-number string)) (epg-context-result-for context 'error)))) (defun epg--status-KEYEXPIRED (context string) @@ -1496,8 +1498,8 @@ This function is for internal use only." (if (string-match "\\`\\([0-9]+\\)" string) (epg-context-set-result-for context 'error - (cons (list 'delete-problem - (cons 'reason (string-to-number (match-string 1 string)))) + (cons (cons 'delete-problem + (string-to-number (match-string 1 string))) (epg-context-result-for context 'error))))) (defun epg--status-SIG_CREATED (context string) @@ -1817,7 +1819,7 @@ You can then use `write-region' to write new data into the file." (epg-context-result-for epg-context 'error))))) (if (eq (process-status (epg-context-process context)) 'run) (delete-process (epg-context-process context)))) - + ;;;###autoload (defun epg-start-decrypt (context cipher) "Initiate a decrypt operation on CIPHER. @@ -1837,6 +1839,19 @@ If you are unsure, use synchronous version of this function (unless (eq (epg-context-protocol context) 'CMS) (epg-wait-for-status context '("BEGIN_DECRYPTION")))) +(defun epg--check-decrypt (context) + (if (epg-context-result-for context 'decryption-failed) + (signal 'epg-error (list "Decryption failed"))) + (if (epg-context-result-for context 'no-secret-key) + (signal 'epg-error + (list "No secret key" + (epg-context-result-for context 'no-secret-key)))) + (unless (epg-context-result-for context 'decryption-okay) + (let* ((error (epg-context-result-for context 'error))) + (if (assq 'no-data error) + (signal 'epg-error (list "No data"))) + (signal 'epg-error (list "Can't decrypt" error))))) + ;;;###autoload (defun epg-decrypt-file (context cipher plain) "Decrypt a file CIPHER and store the result to a file PLAIN. @@ -1849,9 +1864,7 @@ If PLAIN is nil, it returns the result as a string." (epg--make-temp-file "epg-output"))) (epg-start-decrypt context (epg-make-data-from-file cipher)) (epg-wait-for-completion context) - (if (epg-context-result-for context 'error) - (error "Decrypt failed: %S" - (epg-context-result-for context 'error))) + (epg--check-decrypt context) (unless plain (epg-read-output context))) (unless plain @@ -1870,9 +1883,7 @@ If PLAIN is nil, it returns the result as a string." (epg--make-temp-file "epg-output")) (epg-start-decrypt context (epg-make-data-from-file input-file)) (epg-wait-for-completion context) - (if (epg-context-result-for context 'error) - (error "Decrypt failed: %S" - (epg-context-result-for context 'error))) + (epg--check-decrypt context) (epg-read-output context)) (epg-delete-output-file context) (if (file-exists-p input-file) @@ -2319,7 +2330,7 @@ If you are unsure, use synchronous version of this function (let ((entry (assq 'delete-problem (epg-context-result-for context 'error)))) (if entry - (if (setq entry (assq (cdr (assq 'reason (cdr entry))) + (if (setq entry (assq (cdr entry) epg-delete-problem-reason-alist)) (error "Delete keys failed: %s" (cdr entry))) (error "Delete keys failed" (cdr entry))))) -- 1.7.10.4