* src/fns.c (Fcompare_strings): Use FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE.
[bpt/emacs.git] / lisp / epa-file.el
index 6041234..20d34f8 100644 (file)
@@ -1,5 +1,5 @@
 ;;; epa-file.el --- the EasyPG Assistant, transparent file encryption -*- lexical-binding: t -*-
-;; Copyright (C) 2006-2013 Free Software Foundation, Inc.
+;; Copyright (C) 2006-2014 Free Software Foundation, Inc.
 
 ;; Author: Daiki Ueno <ueno@unixuser.org>
 ;; Keywords: PGP, GnuPG
@@ -211,7 +211,8 @@ encryption is used."
         (recipients
          (cond
           ((listp epa-file-encrypt-to) epa-file-encrypt-to)
-          ((stringp epa-file-encrypt-to) (list epa-file-encrypt-to)))))
+          ((stringp epa-file-encrypt-to) (list epa-file-encrypt-to))))
+        buffer)
     (epg-context-set-passphrase-callback
      context
      (cons #'epa-file-passphrase-callback-function
@@ -230,8 +231,18 @@ encryption is used."
                 (unless start
                   (setq start (point-min)
                         end (point-max)))
-                (epa-file--encode-coding-string (buffer-substring start end)
-                                                coding-system))
+                (setq buffer (current-buffer))
+                (with-temp-buffer
+                  (insert-buffer-substring buffer start end)
+                  ;; Translate the region according to
+                  ;; `buffer-file-format', as `write-region' would.
+                  ;; We can't simply do `write-region' (into a
+                  ;; temporary file) here, since it writes out
+                  ;; decrypted contents.
+                  (format-encode-buffer (with-current-buffer buffer
+                                          buffer-file-format))
+                  (epa-file--encode-coding-string (buffer-string)
+                                                  coding-system)))
               (if (or (eq epa-file-select-keys t)
                       (and (null epa-file-select-keys)
                            (not (local-variable-p 'epa-file-encrypt-to