From: ueno Date: Mon, 17 Apr 2006 08:11:10 +0000 (+0000) Subject: Signal 'file-error if cryptographic operations fail. X-Git-Tag: epgsm-branchpoint~47 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5d6935c92aff822b34c3a2b457cac0d1be14164a;p=elisp%2Fepg.git Signal 'file-error if cryptographic operations fail. --- diff --git a/epa-file.el b/epa-file.el index 9232426..574eaed 100644 --- a/epa-file.el +++ b/epa-file.el @@ -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 @@ -85,20 +85,22 @@ (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))) @@ -116,23 +118,30 @@ (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)