aboutsummaryrefslogtreecommitdiffstats
path: root/lang/python/doc/src/gpgme-python-howto.org
diff options
context:
space:
mode:
Diffstat (limited to 'lang/python/doc/src/gpgme-python-howto.org')
-rw-r--r--lang/python/doc/src/gpgme-python-howto.org12
1 files changed, 9 insertions, 3 deletions
diff --git a/lang/python/doc/src/gpgme-python-howto.org b/lang/python/doc/src/gpgme-python-howto.org
index 2121fe65..b4367872 100644
--- a/lang/python/doc/src/gpgme-python-howto.org
+++ b/lang/python/doc/src/gpgme-python-howto.org
@@ -1612,6 +1612,7 @@ of the entire public keybox.
#+BEGIN_SRC python -i
import gpg
+import os
import os.path
import sys
@@ -1619,6 +1620,9 @@ print("""
This script exports one or more public keys in minimised form.
""")
+def open_0o600(path, flags):
+ return os.open(path, flags, mode=0o600)
+
c = gpg.Context(armor=True)
if len(sys.argv) >= 4:
@@ -1654,7 +1658,7 @@ except:
result = c.key_export_minimal(pattern=None)
if result is not None:
- with open(keyfile, "wb") as f:
+ with open(keyfile, "wb", opener=open_0o600) as f:
f.write(result)
else:
pass
@@ -1686,6 +1690,9 @@ This script exports one or more secret keys.
The gpg-agent and pinentry are invoked to authorise the export.
""")
+def open_0o600(path, flags):
+ return os.open(path, flags, mode=0o600)
+
c = gpg.Context(armor=True)
if len(sys.argv) >= 4:
@@ -1735,9 +1742,8 @@ except:
result = c.key_export_secret(pattern=None)
if result is not None:
- with open(keyfile, "wb") as f:
+ with open(keyfile, "wb", opener=open_0o600)) as f:
f.write(result)
- os.chmod(keyfile, 0o600)
else:
pass
#+END_SRC