Subject: bug#71500: 28.2; Can't create/open .gpg file name contains non-ascii encoding in windows

From: Kazuhiro Ito <[email-masked]>
Date: Fri, 28 Jun 2024 20:30:08 +0900

> Ping!  Did you have a chance to try Emacs 30 (now on the emacs-30
> branch of the Emacs Git repository)?

Unfortunately, the issue is not resolved.

As Tatsuya wrote, epg--start function calls gpg2 program with setting
:coding property to raw-text, thus each argument should be encoded in
proper coding system by a caller.  The problem would occur on any OS
whose file name coding system was not utf-8.

For example, in case of epg-decrypt-file, following change is required
if we need to set :coding property to raw-text for ENCODING.

diff --git a/lisp/epg.el b/lisp/epg.el
index 7bec91f616d..59870761565 100644
--- a/lisp/epg.el
+++ b/lisp/epg.el
@@ -1468,7 +1468,10 @@ epg-decrypt-file
       (progn
 	(setf (epg-context-output-file context)
               (or plain (make-temp-file "epg-output")))
-	(epg-start-decrypt context (epg-make-data-from-file cipher))
+	(epg-start-decrypt context
+                           (epg-make-data-from-file
+                            (encode-coding-string
+                             cipher file-name-coding-system)))
 	(epg-wait-for-completion context)
 	(epg--check-error-for-decrypt context)
 	(unless plain

-- 
Kazuhiro Ito

> > Cc: [email-masked]
> > Date: Wed, 12 Jun 2024 10:52:23 +0300
> > From: Eli Zaretskii <[email-masked]>
> > 
> > > From: Tatsuya Kumazawa <[email-masked]>
> > > Date: Tue, 11 Jun 2024 22:35:23 +0900
> > > 
> > > When I save .gpg file contains non-ASCII(eg: e:/あ.gpg).
> > > 
> > > I got message below
> > > (It happens anytime when user name contains non-ASCII
> > > (it must to change epg-gpg-home-directory to ASCII only path))
> > > 
> > > ----
> > > Error while encrypting with "e:/msys2/usr/bin/gpg.exe":
> > > 
> > > gpg: can't create 'c:/Users/(my name with CP932 encoded by
> > > UTF-8)/AppData/Local/Temp/epg-output9UGAFQ': No such file or directory
> > > gpg: symmetric encryption of '[stdin]' failed: No such file or directory
> > > ----
> > > 
> > > 
> > > When I open e:/あ.gpg, I got
> > > 
> > > ----
> > > Error while decrypting with "e:/msys2/usr/bin/gpg.exe":
> > > 
> > > gpg: can't open 'e:/邵ｺ繝ｻgpg': No such file or directory
> > > gpg: decrypt_message failed: No such file or directory
> > > ----
> > > 
> > > It seems UTF-8 encode by CP932 binary sequence.
> > > 
> > > share\emacs\28.2\lisp\epg.el
> > > 
> > > 673:                                                     :coding 'raw-text
> > > 
> > > to
> > > 
> > > 673:                                                     :coding
> > > '(raw-text . cp932)
> > > 
> > > (CP932 is japanese charactor code of windows)
> > > seemsly worked in my environment.
> > > 
> > > 
> > > 
> > > It might be good from cp932 to system process encoding for multilanguage?
> > 
> > There were some encoding problems in epg that were fixed recently in
> > the development sources.  Can try Emacs 30 from the master branch of
> > the Emacs Git repository and see if the problem still exists there?