Signal 'file-error if cryptographic operations fail.
authorueno <ueno>
Mon, 17 Apr 2006 08:11:10 +0000 (08:11 +0000)
committerueno <ueno>
Mon, 17 Apr 2006 08:11:10 +0000 (08:11 +0000)
epa-file.el

index 9232426..574eaed 100644 (file)
@@ -74,7 +74,7 @@
   (setq file (expand-file-name file))
   (let ((local-copy (epa-file-run-real-handler #'file-local-copy (list file)))
        (context (epg-make-context))
-       point length entry)
+       string length entry)
     (if visit
        (setq buffer-file-name file))
     (epg-context-set-passphrase-callback
        (progn
          (if replace
              (goto-char (point-min)))
-         (setq point (point))
          (condition-case error
-             (insert (epg-decrypt-file context file nil))
-           (error (signal 'file-error
-                          (cons "Opening input file"
-                                (nthcdr 2 error)))))
-         (setq length (- (point) point))
-         (if replace
-             (delete-region (point) (point-max)))
-         (decode-coding-region point (point) 'undecided)
+             (setq string (decode-coding-string
+                           (epg-decrypt-file context file nil)
+                           'undecided))
+           (error
+            (if (setq entry (assoc file epa-file-passphrase-alist))
+                (setcdr entry nil))
+            (signal 'file-error
+                    (cons "Opening input file" (nthcdr 2 error)))))
          (if (boundp 'last-coding-system-used)
              (set-buffer-file-coding-system last-coding-system-used)
            (set-buffer-file-coding-system default-buffer-file-coding-system))
-         (goto-char point))
+         (insert string)
+         (setq length (length string))
+         (if replace
+             (delete-region (point) (point-max))))
       (if (and local-copy
               (file-exists-p local-copy))
          (delete-file local-copy)))
                              (error last-coding-system-used))
                          buffer-file-coding-system))
         (context (epg-make-context))
-        (coding-system-for-write 'binary))
+        (coding-system-for-write 'binary)
+        string entry)
     (epg-context-set-passphrase-callback
      context
      (cons #'epa-file-passphrase-callback-function
           file))
+    (condition-case error
+       (setq string
+             (epg-encrypt-string
+              context
+              (encode-coding-string (buffer-string) coding-system)
+              (mapcar (lambda (key)
+                        (epg-sub-key-id (car (epg-key-sub-key-list key))))
+                      (unless (assoc file epa-file-passphrase-alist)
+                        (epa-select-keys
+                   "Select recipents for encryption.
+If no one is selected, symmetric encryption will be performed.  ")))))
+      (error
+       (if (setq entry (assoc file epa-file-passphrase-alist))
+          (setcdr entry nil))
+       (signal 'file-error (cons "Opening output file" (nthcdr 2 error)))))
     (epa-file-run-real-handler
      #'write-region
-     (list (epg-encrypt-string
-           context
-           (encode-coding-string (buffer-string) coding-system)
-           (mapcar (lambda (key)
-                     (epg-sub-key-id (car (epg-key-sub-key-list key))))
-                   (unless (assoc file epa-file-passphrase-alist)
-                     (epa-select-keys
-                      "Select recipents for encryption.
-If no one is selected, symmetric encryption will be performed.  "))))
-          nil file append visit lockname mustbenew))
+     (list string nil file append visit lockname mustbenew))
     (if (boundp 'last-coding-system-used)
        (setq last-coding-system-used coding-system))
     (if (eq visit t)