(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)))
(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)
(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)
(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.
(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.
(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
(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)
(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)))))