* epg.el (epg-sign-file): Signal an error only when a signature is not
[elisp/epg.git] / epg.el
diff --git a/epg.el b/epg.el
index 2a8c2f3..b32d57a 100644 (file)
--- a/epg.el
+++ b/epg.el
@@ -485,7 +485,7 @@ This function is for internal use only."
                       args)))
       (set-default-file-modes orig-mode))
     (set-process-filter process #'epg-process-filter)
-    (set-process-filter process #'epg-process-sentinel)
+    (set-process-sentinel process #'epg-process-sentinel)
     (epg-context-set-process context process)))
 
 (defun epg-process-filter (process input)
@@ -523,13 +523,13 @@ This function is for internal use only."
       (save-excursion
        (set-buffer (process-buffer process))
        ;; gpg process exited abnormally, but we have not received an
-       ;; error response from it.
+       ;; error response from it.  Set it here.
        (unless (epg-context-result-for epg-context 'error)
          (if (string-match "\\`exited abnormally with code \\(.*\\)\n" status)
-             (epg-context-result-for
+             (epg-context-set-result-for
               epg-context 'error
               (list (cons 'exit (string-to-number (match-string 1 status)))))
-           (epg-context-result-for epg-context 'error
+           (epg-context-set-result-for epg-context 'error
                                    (list (cons 'signal status))))))))
 
 (defun epg-read-output (context)
@@ -1235,9 +1235,9 @@ Otherwise, it makes a normal signature."
                                       (epg-make-temp-file "epg-output")))
        (epg-start-sign context (epg-make-data-from-file plain) mode)
        (epg-wait-for-completion context)
-       (if (epg-context-result-for context 'error)
-           (error "Sign failed: %S"
-                  (epg-context-result-for context 'error)))
+       (unless (epg-context-result-for context 'sign)
+         (error "Sign failed: %S"
+                (epg-context-result-for context 'error)))
        (unless signature
          (epg-read-output context)))
     (unless signature
@@ -1257,9 +1257,9 @@ Otherwise, it makes a normal signature."
        (epg-start-sign context (epg-make-data-from-string plain) mode)
        (epg-flush context)
        (epg-wait-for-completion context)
-       (if (epg-context-result-for context 'error)
-           (error "Sign failed: %S"
-                  (epg-context-result-for context 'error)))
+       (unless (epg-context-result-for context 'sign)
+         (error "Sign failed: %S"
+                (epg-context-result-for context 'error)))
        (epg-read-output context))
     (epg-delete-output-file context)
     (epg-reset context)))
@@ -1320,6 +1320,10 @@ If RECIPIENTS is nil, it performs symmetric encryption."
        (epg-start-encrypt context (epg-make-data-from-file plain)
                           recipients sign always-trust)
        (epg-wait-for-completion context)
+       (if (and sign
+                (not (epg-context-result-for context 'sign)))
+           (error "Sign encrypt failed: %S"
+                  (epg-context-result-for context 'error)))
        (if (epg-context-result-for context 'error)
            (error "Encrypt failed: %S"
                   (epg-context-result-for context 'error)))
@@ -1342,6 +1346,10 @@ If RECIPIENTS is nil, it performs symmetric encryption."
                           recipients sign always-trust)
        (epg-flush context)
        (epg-wait-for-completion context)
+       (if (and sign
+                (not (epg-context-result-for context 'sign)))
+           (error "Sign encrypt failed: %S"
+                  (epg-context-result-for context 'error)))
        (if (epg-context-result-for context 'error)
            (error "Encrypt failed: %S"
                   (epg-context-result-for context 'error)))