summaryrefslogtreecommitdiff
path: root/lang/python
diff options
context:
space:
mode:
authorJinWang An <jinwang.an@samsung.com>2021-12-01 16:54:37 +0900
committerJinWang An <jinwang.an@samsung.com>2021-12-01 16:54:37 +0900
commitfd4d11c14daa6a54c81202dffc02cc419fa67568 (patch)
treee14910ad034ec7b4d10552a13e219174ccd4946d /lang/python
parent442a1386c9708114c2b721afea60d5593e36c423 (diff)
downloadgpgme-fd4d11c14daa6a54c81202dffc02cc419fa67568.tar.gz
gpgme-fd4d11c14daa6a54c81202dffc02cc419fa67568.tar.bz2
gpgme-fd4d11c14daa6a54c81202dffc02cc419fa67568.zip
Imported Upstream version 1.11.0upstream/1.11.0
Diffstat (limited to 'lang/python')
-rw-r--r--lang/python/README94
-rw-r--r--lang/python/examples/howto/README.org58
-rwxr-xr-xlang/python/examples/howto/add-userid.py62
-rwxr-xr-xlang/python/examples/howto/clear-sign-file.py56
-rwxr-xr-xlang/python/examples/howto/create-key.py95
-rwxr-xr-xlang/python/examples/howto/decrypt-file.py44
-rwxr-xr-xlang/python/examples/howto/detach-sign-file.py64
-rwxr-xr-xlang/python/examples/howto/encrypt-file.py71
-rwxr-xr-xlang/python/examples/howto/encrypt-sign-file.py70
-rw-r--r--lang/python/examples/howto/groups.py50
-rwxr-xr-xlang/python/examples/howto/keycount.py42
-rwxr-xr-xlang/python/examples/howto/revoke-userid.py62
-rwxr-xr-xlang/python/examples/howto/sign-file.py64
-rwxr-xr-xlang/python/examples/howto/sign-key.py63
-rwxr-xr-xlang/python/examples/howto/temp-homedir-config.py126
-rwxr-xr-xlang/python/examples/howto/verify-signatures.py64
-rwxr-xr-xlang/python/examples/howto/verify-signed-file.py61
-rwxr-xr-xlang/python/examples/low_level-encrypt_to_all.py (renamed from lang/python/examples/encrypt-to-all.py)0
-rwxr-xr-xlang/python/setup.py.in19
-rw-r--r--lang/python/tests/Makefile.am21
-rw-r--r--lang/python/tests/Makefile.in21
21 files changed, 1126 insertions, 81 deletions
diff --git a/lang/python/README b/lang/python/README
index 6a2e8b8..99da4dd 100644
--- a/lang/python/README
+++ b/lang/python/README
@@ -1,61 +1,77 @@
-gpg - GPGME bindings for Python -*- org -*-
-=======================
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
+ GPG - GPGME BINDINGS FOR PYTHON
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
+
+
+Table of Contents
+─────────────────
+
+1 Mailing List
+2 Bugs
+3 Authors
+4 History
+
The "gpg" module is a python interface to the GPGME library:
-https://www.gnupg.org/related_software/gpgme/
+[https://www.gnupg.org/software/gpgme/]
-"gpg" offers two interfaces, one is a high-level, curated, and
-idiomatic interface that is implemented as a shim on top of the
-low-level interface automatically created using SWIG.
+"gpg" offers two interfaces, one is a high-level, curated, and idiomatic
+interface that is implemented as a shim on top of the low-level
+interface automatically created using SWIG.
This way we make simple things easy, while still providing the entire
functionality of the underlying library.
-* Mailing List
-For general discussion and help see the gnupg-users mailing list:
-https://lists.gnupg.org/mailman/listinfo/gnupg-users
+1 Mailing List
+══════════════
+
+ For general discussion and help see the gnupg-users mailing list:
+ [https://lists.gnupg.org/mailman/listinfo/gnupg-users]
+
+ For development see the gnupg-devel mailing list:
+ [https://lists.gnupg.org/mailman/listinfo/gnupg-devel]
+
+
+2 Bugs
+══════
-For development see the gnupg-devel mailing list:
-https://lists.gnupg.org/mailman/listinfo/gnupg-devel
+ Please report bugs using our bug tracker [https://bugs.gnupg.org] with
+ tag (aka project) 'gpgme'.
-* Bugs
-Please report bugs using our bug tracker using the category 'gpgme',
-and topic 'python':
-https://bugs.gnupg.org/gnupg/
+3 Authors
+═════════
-* Authors
+ PyME was created by John Goerzen, and maintained, developed, and
+ cherished by Igor Belyi, Martin Albrecht, Ben McGinnes, and everyone
+ who contributed to it in any way.
-PyME was created by John Goerzen, and maintained, developed, and
-cherished by Igor Belyi, Martin Albrecht, Ben McGinnes, and everyone
-who contributed to it in any way.
+ In 2016 we merged a port of PyME to into the GPGME repository, and
+ development will continue there. Please see the VCS history for the
+ list of contributors, and if you do find bugs, or want to contribute,
+ please get in touch and help maintain the python gpg bindings.
-In 2016 we merged a port of PyME to into the GPGME repository, and
-development will continue there. Please see the VCS history for the
-list of contributors, and if you do find bugs, or want to contribute,
-please get in touch and help maintain the python gpg bindings.
+ Please see the section 'History' further down this document for
+ references to previous versions.
-Please see the section 'History' further down this document for
-references to previous versions.
-* History
+4 History
+═════════
- - The python bindings were renamed from PyME to "gpg" in 2016.
+ • The python bindings were renamed from PyME to "gpg" in 2016.
- - The bindings have been merged into the GPGME repository in 2016.
+ • The bindings have been merged into the GPGME repository in 2016.
- - The latest version of PyME for Python 3.2 and above (as of
- May, 2015) is v0.9.1.
- https://git.gnupg.org/gpgme.git/lang/py3-pyme
+ • The latest version of PyME for Python 3.2 and above (as of May,
+ 2015) is v0.9.1. [https://git.gnupg.org/gpgme.git/lang/py3-pyme]
- - The latest version of PyME for Python 2.6 and 2.7 (as of this
- writing) is v0.9.0. https://bitbucket.org/malb/pyme
+ • The latest version of PyME for Python 2.6 and 2.7 (as of this
+ writing) is v0.9.0. [https://bitbucket.org/malb/pyme]
- - A previous version of PyME v0.8.0 can be found on sourceforge:
- http://pyme.sourceforge.net/
+ • A previous version of PyME v0.8.0 can be found on sourceforge:
+ [http://pyme.sourceforge.net/]
- - A previous version of PyME v0.5.1 which works with GPGME v0.3.15
- can be found on John Goerzen's PyME page:
- http://quux.org/devel/pyme/
- http://www.complete.org/JohnGoerzen
+ • A previous version of PyME v0.5.1 which works with GPGME v0.3.15 can
+ be found on John Goerzen's PyME page: [http://quux.org/devel/pyme/]
+ [http://www.complete.org/JohnGoerzen]
diff --git a/lang/python/examples/howto/README.org b/lang/python/examples/howto/README.org
new file mode 100644
index 0000000..b74ae7e
--- /dev/null
+++ b/lang/python/examples/howto/README.org
@@ -0,0 +1,58 @@
+#+TITLE: GPGME Python Bindings HOWTO Examples
+#+LATEX_COMPILER: xelatex
+#+LATEX_CLASS: article
+#+LATEX_CLASS_OPTIONS: [12pt]
+#+LATEX_HEADER: \usepackage{xltxtra}
+#+LATEX_HEADER: \usepackage[margin=1in]{geometry}
+#+LATEX_HEADER: \setmainfont[Ligatures={Common}]{Times New Roman}
+#+LATEX_HEADER: \author{Ben McGinnes <ben@gnupg.org>}
+
+
+* Examples
+ :PROPERTIES:
+ :CUSTOM_ID: gpgme-python3-examples
+ :END:
+
+ The contents of this directory are the examples included in the /GNU
+ Privacy Guard (GnuPG) Made Easy Python Bindings HOWTO/ file. Each
+ script is explicitly for Python 3 and specifically for Python 3.4 or
+ later.
+
+ Some of these scripts may work with Python 2.7, but there are no
+ guarantees. They will include the relevant imports from the
+ =__future__= module to facilitate that if possible.
+
+
+* Copyright and Licensing
+ :PROPERTIES:
+ :CUSTOM_ID: copyright-and-license
+ :END:
+
+ Unless otherwise stated, all the examples in this directory are
+ released under the same terms as GPGME itself; that is they are dual
+ licensed under the terms of both the GNU General Public License
+ version 2.0 (or any later version) *and* the GNU Lesser General
+ Public License version 2.1 (or any later version).
+
+
+** Copyright (C) The GnuPG Project, 2018
+ :PROPERTIES:
+ :CUSTOM_ID: copyright
+ :END:
+
+ Copyright © The GnuPG Project, 2018.
+
+
+** License GPL compatible
+ :PROPERTIES:
+ :CUSTOM_ID: license
+ :END:
+
+ This file is free software; as a special exception the author gives
+ unlimited permission to copy and/or distribute it, with or without
+ modifications, as long as this notice is preserved.
+
+ This file is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, to the extent permitted by law; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE.
diff --git a/lang/python/examples/howto/add-userid.py b/lang/python/examples/howto/add-userid.py
new file mode 100755
index 0000000..b868979
--- /dev/null
+++ b/lang/python/examples/howto/add-userid.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import, division, unicode_literals
+
+# Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License and the GNU
+# Lesser General Public Licensefor more details.
+#
+# You should have received a copy of the GNU General Public License and the GNU
+# Lesser General Public along with this program; if not, see
+# <http://www.gnu.org/licenses/>.
+
+import gpg
+import os.path
+
+print("""
+This script adds a new user ID to an existing key.
+
+The gpg-agent and pinentry are invoked to enter the passphrase.
+""")
+
+c = gpg.Context()
+
+homedir = input("Enter the GPG configuration directory path (optional): ")
+fpr0 = input("Enter the fingerprint of the key to modify: ")
+uid_name = input("Enter the name of the user ID: ")
+uid_email = input("Enter the email address of the user ID: ")
+uid_cmnt = input("Enter a comment to include (optional): ")
+
+if homedir.startswith("~"):
+ if os.path.exists(os.path.expanduser(homedir)) is True:
+ c.home_dir = os.path.expanduser(homedir)
+ else:
+ pass
+elif os.path.exists(homedir) is True:
+ c.home_dir = homedir
+else:
+ pass
+
+fpr = "".join(fpr0.split())
+
+if len(uid_cmnt) > 0:
+ userid = "{0} ({1}) <{2}>".format(uid_name, uid_cmnt, uid_email)
+else:
+ userid = "{0} <{2}>".format(uid_name, uid_email)
+
+key = c.get_key(fpr, secret=True)
+c.key_add_uid(key, userid)
diff --git a/lang/python/examples/howto/clear-sign-file.py b/lang/python/examples/howto/clear-sign-file.py
new file mode 100755
index 0000000..597bbc5
--- /dev/null
+++ b/lang/python/examples/howto/clear-sign-file.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import, division, unicode_literals
+
+# Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License and the GNU
+# Lesser General Public Licensefor more details.
+#
+# You should have received a copy of the GNU General Public License and the GNU
+# Lesser General Public along with this program; if not, see
+# <http://www.gnu.org/licenses/>.
+
+import gpg
+import sys
+
+"""
+Clear-signs a file with a specified key. If entering both the key and the
+filename on the command line, the key must be entered first.
+"""
+
+if len(sys.argv) > 3:
+ logrus = sys.argv[1]
+ filename = " ".join(sys.argv[2:])
+elif len(sys.argv) == 3:
+ logrus = sys.argv[1]
+ filename = sys.argv[2]
+elif len(sys.argv) == 2:
+ logrus = sys.argv[1]
+ filename = input("Enter the path and filename to sign: ")
+else:
+ logrus = input("Enter the fingerprint or key ID to sign with: ")
+ filename = input("Enter the path and filename to sign: ")
+
+with open(filename, "rb") as f:
+ text = f.read()
+
+key = list(gpg.Context().keylist(pattern=logrus))
+
+with gpg.Context(armor=True, signers=key) as c:
+ signed_data, result = c.sign(text, mode=gpg.constants.sig.mode.CLEAR)
+ with open("{0}.asc".format(filename), "wb") as f:
+ f.write(signed_data)
diff --git a/lang/python/examples/howto/create-key.py b/lang/python/examples/howto/create-key.py
new file mode 100755
index 0000000..429ab1f
--- /dev/null
+++ b/lang/python/examples/howto/create-key.py
@@ -0,0 +1,95 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import, division, unicode_literals
+
+# Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License and the GNU
+# Lesser General Public Licensefor more details.
+#
+# You should have received a copy of the GNU General Public License and the GNU
+# Lesser General Public along with this program; if not, see
+# <http://www.gnu.org/licenses/>.
+
+import gpg
+import os.path
+
+print("""
+This script generates a new key which does not expire.
+
+The gpg-agent and pinentry are invoked to set the passphrase.
+""")
+
+c = gpg.Context()
+
+homedir = input("Enter the GPG configuration directory path (optional): ")
+uid_name = input("Enter the name of the user ID: ")
+uid_email = input("Enter the email address of the user ID: ")
+uid_cmnt = input("Enter a comment to include (optional): ")
+key_algo = input("Enter the key algorithm, RSA or DSA (default is RSA): ")
+key_size = input("Enter the key size (2048-4096, default is 2048): ")
+
+if homedir.startswith("~"):
+ if os.path.exists(os.path.expanduser(homedir)) is True:
+ c.home_dir = os.path.expanduser(homedir)
+ else:
+ pass
+elif os.path.exists(homedir) is True:
+ c.home_dir = homedir
+else:
+ pass
+
+if len(uid_cmnt) > 0:
+ userid = "{0} ({1}) <{2}>".format(uid_name, uid_cmnt, uid_email)
+else:
+ userid = "{0} <{2}>".format(uid_name, uid_email)
+
+if key_algo.lower() == "dsa":
+ ka = "dsa"
+else:
+ ka = "rsa"
+
+if len(key_size) == 4:
+ try:
+ ks0 = int(key_size)
+ except ValueError:
+ ks0 = None
+ if ks0 is None:
+ ks = "2048"
+ else:
+ if ks0 < 2048:
+ ks = "2048"
+ elif ka == "dsa" and ks0 > 3072:
+ ks = "3072"
+ elif ka == "rsa" and ks0 > 4096:
+ ks = "4096"
+ else:
+ ks = key_size
+else:
+ ks = "2048"
+
+keyalgo = "{0}{1}".format(ka, ks)
+
+newkey = c.create_key(userid, algorithm=keyalgo, expires=False,
+ passphrase=True, certify=True)
+key = c.get_key(newkey.fpr, secret=True)
+
+if ka == "rsa":
+ newsub = c.create_subkey(key, algorithm=keyalgo, expires=False,
+ passphrase=True, encrypt=True)
+else:
+ newsub = c.create_subkey(key, expires=False, passphrase=True,
+ encrypt=True)
diff --git a/lang/python/examples/howto/decrypt-file.py b/lang/python/examples/howto/decrypt-file.py
new file mode 100755
index 0000000..60a050b
--- /dev/null
+++ b/lang/python/examples/howto/decrypt-file.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import, division, unicode_literals
+
+# Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License and the GNU
+# Lesser General Public Licensefor more details.
+#
+# You should have received a copy of the GNU General Public License and the GNU
+# Lesser General Public along with this program; if not, see
+# <http://www.gnu.org/licenses/>.
+
+import gpg
+import sys
+
+if len(sys.argv) == 3:
+ ciphertext = sys.argv[1]
+ newfile = sys.argv[2]
+elif len(sys.argv) == 2:
+ ciphertext = sys.argv[1]
+ newfile = input("Enter path and filename of file to save decrypted data to: ")
+else:
+ ciphertext = input("Enter path and filename of encrypted file: ")
+ newfile = input("Enter path and filename of file to save decrypted data to: ")
+
+with open(ciphertext, "rb") as cfile:
+ plaintext, result, verify_result = gpg.Context().decrypt(cfile)
+
+with open(newfile, "wb") as nfile:
+ nfile.write(plaintext)
diff --git a/lang/python/examples/howto/detach-sign-file.py b/lang/python/examples/howto/detach-sign-file.py
new file mode 100755
index 0000000..99fbe65
--- /dev/null
+++ b/lang/python/examples/howto/detach-sign-file.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import, division, unicode_literals
+
+# Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License and the GNU
+# Lesser General Public Licensefor more details.
+#
+# You should have received a copy of the GNU General Public License and the GNU
+# Lesser General Public along with this program; if not, see
+# <http://www.gnu.org/licenses/>.
+
+import gpg
+import sys
+
+"""
+Signs a file with a specified key. If entering both the key and the filename
+on the command line, the key must be entered first.
+
+Will produce both an ASCII armoured and GPG binary format copy of the detached
+signature file.
+"""
+
+if len(sys.argv) > 3:
+ logrus = sys.argv[1]
+ filename = " ".join(sys.argv[2:])
+elif len(sys.argv) == 3:
+ logrus = sys.argv[1]
+ filename = sys.argv[2]
+elif len(sys.argv) == 2:
+ logrus = sys.argv[1]
+ filename = input("Enter the path and filename to sign: ")
+else:
+ logrus = input("Enter the fingerprint or key ID to sign with: ")
+ filename = input("Enter the path and filename to sign: ")
+
+with open(filename, "rb") as f:
+ text = f.read()
+
+key = list(gpg.Context().keylist(pattern=logrus))
+
+with gpg.Context(armor=True, signers=key) as ca:
+ signed_data, result = ca.sign(text, mode=gpg.constants.sig.mode.DETACH)
+ with open("{0}.asc".format(filename), "wb") as fa:
+ fa.write(signed_data)
+
+with gpg.Context(signers=key) as cb:
+ signed_data, result = cb.sign(text, mode=gpg.constants.sig.mode.DETACH)
+ with open("{0}.sig".format(filename), "wb") as fb:
+ fb.write(signed_data)
diff --git a/lang/python/examples/howto/encrypt-file.py b/lang/python/examples/howto/encrypt-file.py
new file mode 100755
index 0000000..ad4e1ce
--- /dev/null
+++ b/lang/python/examples/howto/encrypt-file.py
@@ -0,0 +1,71 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import, division, unicode_literals
+
+# Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License and the GNU
+# Lesser General Public Licensefor more details.
+#
+# You should have received a copy of the GNU General Public License and the GNU
+# Lesser General Public along with this program; if not, see
+# <http://www.gnu.org/licenses/>.
+
+import gpg
+import sys
+
+"""
+Encrypts a file to a specified key. If entering both the key and the filename
+on the command line, the key must be entered first.
+
+Will produce both an ASCII armoured and GPG binary format copy of the encrypted
+file.
+"""
+
+if len(sys.argv) > 3:
+ a_key = sys.argv[1]
+ filename = " ".join(sys.argv[2:])
+elif len(sys.argv) == 3:
+ a_key = sys.argv[1]
+ filename = sys.argv[2]
+elif len(sys.argv) == 2:
+ a_key = sys.argv[1]
+ filename = input("Enter the path and filename to encrypt: ")
+else:
+ a_key = input("Enter the fingerprint or key ID to encrypt to: ")
+ filename = input("Enter the path and filename to encrypt: ")
+
+rkey = list(gpg.Context().keylist(pattern=a_key, secret=False))
+with open(filename, "rb") as f:
+ text = f.read()
+
+with gpg.Context(armor=True) as ca:
+ try:
+ ciphertext, result, sign_result = ca.encrypt(text, recipients=rkey,
+ sign=False)
+ with open("{0}.asc".format(filename), "wb") as fa:
+ fa.write(ciphertext)
+ except gpg.errors.InvalidRecipients as e:
+ print(e)
+
+with gpg.Context() as cg:
+ try:
+ ciphertext, result, sign_result = cg.encrypt(text, recipients=rkey,
+ sign=False)
+ with open("{0}.gpg".format(filename), "wb") as fg:
+ fg.write(ciphertext)
+ except gpg.errors.InvalidRecipients as e:
+ print(e)
diff --git a/lang/python/examples/howto/encrypt-sign-file.py b/lang/python/examples/howto/encrypt-sign-file.py
new file mode 100755
index 0000000..41aaac8
--- /dev/null
+++ b/lang/python/examples/howto/encrypt-sign-file.py
@@ -0,0 +1,70 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import, division, unicode_literals
+
+# Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License and the GNU
+# Lesser General Public Licensefor more details.
+#
+# You should have received a copy of the GNU General Public License and the GNU
+# Lesser General Public along with this program; if not, see
+# <http://www.gnu.org/licenses/>.
+
+import gpg
+import sys
+
+"""
+Signs and encrypts a file to a specified key. If entering both the key and the
+filename on the command line, the key must be entered first.
+
+Signs with and also encrypts to the default key of the user invoking the
+script. Will treat all recipients as trusted to permit encryption.
+
+Will produce both an ASCII armoured and GPG binary format copy of the signed
+and encrypted file.
+"""
+
+if len(sys.argv) > 3:
+ a_key = sys.argv[1]
+ filename = " ".join(sys.argv[2:])
+elif len(sys.argv) == 3:
+ a_key = sys.argv[1]
+ filename = sys.argv[2]
+elif len(sys.argv) == 2:
+ a_key = sys.argv[1]
+ filename = input("Enter the path and filename to encrypt: ")
+else:
+ a_key = input("Enter the fingerprint or key ID to encrypt to: ")
+ filename = input("Enter the path and filename to encrypt: ")
+
+rkey = list(gpg.Context().keylist(pattern=a_key, secret=False))
+with open(filename, "rb") as f:
+ text = f.read()
+
+with gpg.Context(armor=True) as ca:
+ ciphertext, result, sign_result = ca.encrypt(text, recipients=rkey,
+ always_trust=True,
+ add_encrypt_to=True)
+ with open("{0}.asc".format(filename), "wb") as fa:
+ fa.write(ciphertext)
+
+with gpg.Context() as cg:
+ ciphertext, result, sign_result = cg.encrypt(text, recipients=rkey,
+ always_trust=True,
+ add_encrypt_to=True)
+ with open("{0}.gpg".format(filename), "wb") as fg:
+ fg.write(ciphertext)
diff --git a/lang/python/examples/howto/groups.py b/lang/python/examples/howto/groups.py
new file mode 100644
index 0000000..5e7fdf6
--- /dev/null
+++ b/lang/python/examples/howto/groups.py
@@ -0,0 +1,50 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import, division, unicode_literals
+
+# Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License and the GNU
+# Lesser General Public Licensefor more details.
+#
+# You should have received a copy of the GNU General Public License and the GNU
+# Lesser General Public along with this program; if not, see
+# <http://www.gnu.org/licenses/>.
+
+import subprocess
+
+"""
+Intended for use with other scripts.
+
+Usage: from groups import group_lists
+"""
+
+lines = subprocess.getoutput("gpgconf --list-options gpg").splitlines()
+
+for i in range(len(lines)):
+ if lines[i].startswith("group") is True:
+ line = lines[i]
+ else:
+ pass
+
+groups = line.split(":")[-1].replace('"', '').split(',')
+
+group_lines = groups
+for i in range(len(group_lines)):
+ group_lines[i] = group_lines[i].split("=")
+
+group_lists = group_lines
+for i in range(len(group_lists)):
+ group_lists[i][1] = group_lists[i][1].split()
diff --git a/lang/python/examples/howto/keycount.py b/lang/python/examples/howto/keycount.py
new file mode 100755
index 0000000..8e25454
--- /dev/null
+++ b/lang/python/examples/howto/keycount.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import, division, unicode_literals
+
+# Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License and the GNU
+# Lesser General Public Licensefor more details.
+#
+# You should have received a copy of the GNU General Public License and the GNU
+# Lesser General Public along with this program; if not, see
+# <http://www.gnu.org/licenses/>.
+
+import gpg
+
+c = gpg.Context()
+seckeys = c.keylist(pattern=None, secret=True)
+pubkeys = c.keylist(pattern=None, secret=False)
+
+seclist = list(seckeys)
+secnum = len(seclist)
+
+publist = list(pubkeys)
+pubnum = len(publist)
+
+print("""
+Number of secret keys: {0}
+Number of public keys: {1}
+""".format(secnum, pubnum))
diff --git a/lang/python/examples/howto/revoke-userid.py b/lang/python/examples/howto/revoke-userid.py
new file mode 100755
index 0000000..7a3d190
--- /dev/null
+++ b/lang/python/examples/howto/revoke-userid.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import, division, unicode_literals
+
+# Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License and the GNU
+# Lesser General Public Licensefor more details.
+#
+# You should have received a copy of the GNU General Public License and the GNU
+# Lesser General Public along with this program; if not, see
+# <http://www.gnu.org/licenses/>.
+
+import gpg
+import os.path
+
+print("""
+This script revokes a user ID on an existing key.
+
+The gpg-agent and pinentry are invoked to enter the passphrase.
+""")
+
+c = gpg.Context()
+
+homedir = input("Enter the GPG configuration directory path (optional): ")
+fpr0 = input("Enter the fingerprint of the key to modify: ")
+uid_name = input("Enter the name of the user ID: ")
+uid_email = input("Enter the email address of the user ID: ")
+uid_cmnt = input("Enter a comment to include (optional): ")
+
+if homedir.startswith("~"):
+ if os.path.exists(os.path.expanduser(homedir)) is True:
+ c.home_dir = os.path.expanduser(homedir)
+ else:
+ pass
+elif os.path.exists(homedir) is True:
+ c.home_dir = homedir
+else:
+ pass
+
+fpr = "".join(fpr0.split())
+
+if len(uid_cmnt) > 0:
+ userid = "{0} ({1}) <{2}>".format(uid_name, uid_cmnt, uid_email)
+else:
+ userid = "{0} <{2}>".format(uid_name, uid_email)
+
+key = c.get_key(fpr, secret=True)
+c.key_revoke_uid(key, userid)
diff --git a/lang/python/examples/howto/sign-file.py b/lang/python/examples/howto/sign-file.py
new file mode 100755
index 0000000..01006df
--- /dev/null
+++ b/lang/python/examples/howto/sign-file.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import, division, unicode_literals
+
+# Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License and the GNU
+# Lesser General Public Licensefor more details.
+#
+# You should have received a copy of the GNU General Public License and the GNU
+# Lesser General Public along with this program; if not, see
+# <http://www.gnu.org/licenses/>.
+
+import gpg
+import sys
+
+"""
+Signs a file with a specified key. If entering both the key and the filename
+on the command line, the key must be entered first.
+
+Will produce both an ASCII armoured and GPG binary format copy of the signed
+file.
+"""
+
+if len(sys.argv) > 3:
+ logrus = sys.argv[1]
+ filename = " ".join(sys.argv[2:])
+elif len(sys.argv) == 3:
+ logrus = sys.argv[1]
+ filename = sys.argv[2]
+elif len(sys.argv) == 2:
+ logrus = sys.argv[1]
+ filename = input("Enter the path and filename to sign: ")
+else:
+ logrus = input("Enter the fingerprint or key ID to sign with: ")
+ filename = input("Enter the path and filename to sign: ")
+
+with open(filename, "rb") as f:
+ text = f.read()
+
+key = list(gpg.Context().keylist(pattern=logrus))
+
+with gpg.Context(armor=True, signers=key) as ca:
+ signed_data, result = ca.sign(text, mode=gpg.constants.sig.mode.NORMAL)
+ with open("{0}.asc".format(filename), "wb") as fa:
+ fa.write(signed_data)
+
+with gpg.Context(signers=key) as cg:
+ signed_data, result = cg.sign(text, mode=gpg.constants.sig.mode.NORMAL)
+ with open("{0}.gpg".format(filename), "wb") as fg:
+ fg.write(signed_data)
diff --git a/lang/python/examples/howto/sign-key.py b/lang/python/examples/howto/sign-key.py
new file mode 100755
index 0000000..b1afe13
--- /dev/null
+++ b/lang/python/examples/howto/sign-key.py
@@ -0,0 +1,63 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import, division, unicode_literals
+
+# Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License and the GNU
+# Lesser General Public Licensefor more details.
+#
+# You should have received a copy of the GNU General Public License and the GNU
+# Lesser General Public along with this program; if not, see
+# <http://www.gnu.org/licenses/>.
+
+import gpg
+import os.path
+
+print("""
+This script signs or certifies a key.
+
+The gpg-agent and pinentry are invoked to enter the passphrase.
+""")
+
+c = gpg.Context()
+
+homedir = input("Enter the GPG configuration directory path (optional): ")
+fpr0 = input("Enter the fingerprint of the key to sign: ")
+userid = input("Enter the UID to sign (case sensitive, optional): ")
+sig_type = input("Enter the certification type (local or normal): ")
+
+if homedir.startswith("~"):
+ if os.path.exists(os.path.expanduser(homedir)) is True:
+ c.home_dir = os.path.expanduser(homedir)
+ else:
+ pass
+elif os.path.exists(homedir) is True:
+ c.home_dir = homedir
+else:
+ pass
+
+fpr = "".join(fpr0.split())
+key = c.get_key(fpr, secret=False)
+
+if len(userid) > 0 and sig_type.lower() == "local":
+ c.key_sign(key, uids=userid, local=True)
+elif len(userid) > 0 and sig_type.lower() != "local":
+ c.key_sign(key, uids=userid)
+elif len(userid) == 0 and sig_type.lower() == "local":
+ c.key_sign(key, local=True)
+else:
+ c.key_sign(key)
diff --git a/lang/python/examples/howto/temp-homedir-config.py b/lang/python/examples/howto/temp-homedir-config.py
new file mode 100755
index 0000000..ddd7932
--- /dev/null
+++ b/lang/python/examples/howto/temp-homedir-config.py
@@ -0,0 +1,126 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import, division, unicode_literals
+
+# Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License and the GNU
+# Lesser General Public Licensefor more details.
+#
+# You should have received a copy of the GNU General Public License and the GNU
+# Lesser General Public along with this program; if not, see
+# <http://www.gnu.org/licenses/>.
+
+import os
+import os.path
+import sys
+
+intro = """
+This script creates a temporary directory to use as a homedir for
+testing key generation tasks with the correct permissions, along
+with a gpg.conf file containing the same configuration options
+listed in the HOWTO.
+
+You may wish to change the order of the cipher preferences or
+remove those not relevant to your installation. These
+configuration parameters assume that all ciphers and digests are
+installed and available rather than limiting to the default
+ciphers and digests.
+
+The script prompts for a directory name to be installed as a hidden
+directory in the user's home directory on POSIX systems. So if you
+enter "gnupg-temp" on a Linux, BSD or OS X system, it will create
+"~/.gnupg-temp" (you do not need to enter the leading dot).
+
+This script has not been tested on Windows systems and may have
+unpredictable results. That said, it will not delete or copy over
+existing data.
+
+If the directory already exists, the script will terminate with a
+message telling you to specify a new directory name. There is no
+default directory name.
+"""
+
+gpgconf = """# gpg.conf settings for key generation:
+expert
+allow-freeform-uid
+allow-secret-key-import
+trust-model tofu+pgp
+tofu-default-policy unknown
+enable-large-rsa
+enable-dsa2
+cert-digest-algo SHA512
+default-preference-list TWOFISH CAMELLIA256 AES256 CAMELLIA192 AES192 CAMELLIA128 AES BLOWFISH IDEA CAST5 3DES SHA512 SHA384 SHA256 SHA224 RIPEMD160 SHA1 ZLIB BZIP2 ZIP Uncompressed
+personal-cipher-preferences TWOFISH CAMELLIA256 AES256 CAMELLIA192 AES192 CAMELLIA128 AES BLOWFISH IDEA CAST5 3DES
+personal-digest-preferences SHA512 SHA384 SHA256 SHA224 RIPEMD160 SHA1
+personal-compress-preferences ZLIB BZIP2 ZIP Uncompressed
+"""
+
+agentconf = """# gpg-agent.conf settings for key generation:
+default-cache-ttl 300
+"""
+
+if len(sys.argv) == 1:
+ print(intro)
+ new_homedir = input("Enter the temporary gnupg homedir name: ")
+elif len(sys.argv) == 2:
+ new_homedir = sys.argv[1]
+else:
+ new_homedir = " ".join(sys.argv[1:])
+
+userdir = os.path.expanduser("~")
+
+if new_homedir.startswith("~"):
+ new_homdir.replace("~", "")
+else:
+ pass
+
+if new_homedir.startswith("/"):
+ new_homdir.replace("/", "")
+else:
+ pass
+
+if new_homedir.startswith("."):
+ new_homdir.replace(".", "_")
+else:
+ pass
+
+if new_homedir.count(" ") > 0:
+ new_homedir.replace(" ", "_")
+else:
+ pass
+
+nh = "{0}/.{1}".format(userdir, new_homedir)
+
+if os.path.exists(nh) is True:
+ print("The {0} directory already exists.".format(nh))
+else:
+ print("Creating the {0} directory.".format(nh))
+ os.mkdir(nh)
+ os.chmod(nh, 0o700)
+ with open("{0}/{1}".format(nh, "gpg.conf"), "w") as f1:
+ f1.write(gpgconf)
+ os.chmod("{0}/{1}".format(nh, "gpg.conf"), 0o600)
+ with open("{0}/{1}".format(nh, "gpg-agent.conf"), "w") as f2:
+ f2.write(gpgconf)
+ os.chmod("{0}/{1}".format(nh, "gpg-agent.conf"), 0o600)
+ print("""You may now use the {0} directory as an alternative GPG homedir:
+
+gpg --homedir {0}
+gpg --homedir --full-gen-key
+
+Or with GPGME scripts, including the GPGME Python bindings.
+""")
diff --git a/lang/python/examples/howto/verify-signatures.py b/lang/python/examples/howto/verify-signatures.py
new file mode 100755
index 0000000..8aafc3b
--- /dev/null
+++ b/lang/python/examples/howto/verify-signatures.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import, division, unicode_literals
+
+# Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License and the GNU
+# Lesser General Public Licensefor more details.
+#
+# You should have received a copy of the GNU General Public License and the GNU
+# Lesser General Public along with this program; if not, see
+# <http://www.gnu.org/licenses/>.
+
+import gpg
+import sys
+import time
+
+"""
+Verifies a signed file which has been signed with a detached signature.
+"""
+
+if len(sys.argv) > 2:
+ filename = sys.argv[1]
+ sig_file = sys.argv[2]
+elif len(sys.argv) == 2:
+ filename = sys.argv[1]
+ sig_file = input("Enter the path and filename of the detached signature: ")
+else:
+ filename = input("Enter the path and filename to verify: ")
+ sig_file = input("Enter the path and filename of the detached signature: ")
+
+c = gpg.Context()
+
+try:
+ data, result = c.verify(open(filename), open(sig_file))
+ verified = True
+except gpg.errors.BadSignatures as e:
+ verified = False
+ print(e)
+
+if verified is True:
+ for i in range(len(result.signatures)):
+ sign = result.signatures[i]
+ print("""Good signature from:
+{0}
+with key {1}
+made at {2}
+""".format(c.get_key(sign.fpr).uids[0].uid, sign.fpr,
+ time.ctime(sign.timestamp)))
+else:
+ pass
diff --git a/lang/python/examples/howto/verify-signed-file.py b/lang/python/examples/howto/verify-signed-file.py
new file mode 100755
index 0000000..9f8702f
--- /dev/null
+++ b/lang/python/examples/howto/verify-signed-file.py
@@ -0,0 +1,61 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from __future__ import absolute_import, division, unicode_literals
+
+# Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License and the GNU
+# Lesser General Public Licensefor more details.
+#
+# You should have received a copy of the GNU General Public License and the GNU
+# Lesser General Public along with this program; if not, see
+# <http://www.gnu.org/licenses/>.
+
+import gpg
+import sys
+import time
+
+"""
+Verifies a signed file which has been signed with either NORMAL or CLEAR modes.
+"""
+
+if len(sys.argv) > 2:
+ filename = " ".join(sys.argv[1:])
+elif len(sys.argv) == 2:
+ filename = sys.argv[1]
+else:
+ filename = input("Enter the path and filename to sign: ")
+
+c = gpg.Context()
+
+try:
+ data, result = c.verify(open(filename))
+ verified = True
+except gpg.errors.BadSignatures as e:
+ verified = False
+ print(e)
+
+if verified is True:
+ for i in range(len(result.signatures)):
+ sign = result.signatures[i]
+ print("""Good signature from:
+{0}
+with key {1}
+made at {2}
+""".format(c.get_key(sign.fpr).uids[0].uid, sign.fpr,
+ time.ctime(sign.timestamp)))
+else:
+ pass
diff --git a/lang/python/examples/encrypt-to-all.py b/lang/python/examples/low_level-encrypt_to_all.py
index bad4220..bad4220 100755
--- a/lang/python/examples/encrypt-to-all.py
+++ b/lang/python/examples/low_level-encrypt_to_all.py
diff --git a/lang/python/setup.py.in b/lang/python/setup.py.in
index f9dda20..2595073 100755
--- a/lang/python/setup.py.in
+++ b/lang/python/setup.py.in
@@ -152,25 +152,8 @@ class BuildExtFirstHack(build):
sink.write(content)
def _generate_gpgme_h(self, source_name, sink_name):
- if up_to_date(source_name, sink_name):
- return
-
print("Using gpgme.h from {}".format(source_name))
-
- deprec_func = re.compile(r'^(.*typedef.*|.*\(.*\)|[^#]+\s+.+)'
- + r'\s*_GPGME_DEPRECATED(_OUTSIDE_GPGME)?\(.*\);\s*',
- re.S)
- line_break = re.compile(';|\\$|\\x0c|^\s*#|{')
-
- with open(sink_name, "w") as sink, open(source_name) as source:
- text = ''
- for line in source:
- text += re.sub(' class ', ' _py_obsolete_class ', line)
- if line_break.search(line):
- if not deprec_func.search(text):
- sink.write(text)
- text = ''
- sink.write(text)
+ shutil.copy2(source_name, sink_name)
def _generate_errors_i(self):
diff --git a/lang/python/tests/Makefile.am b/lang/python/tests/Makefile.am
index 25b15f2..3864f8b 100644
--- a/lang/python/tests/Makefile.am
+++ b/lang/python/tests/Makefile.am
@@ -18,8 +18,6 @@
GPG = gpg
GPG_AGENT = gpg-agent
-export GNUPGHOME := $(abs_builddir)
-export GPG_AGENT_INFO :=
test_srcdir = $(top_srcdir)/tests/gpg
@@ -79,7 +77,7 @@ xcheck: all
CLEANFILES = secring.gpg pubring.gpg pubring.kbx trustdb.gpg dirmngr.conf \
gpg-agent.conf pubring.kbx~ gpg.conf pubring.gpg~ \
random_seed .gpg-v21-migrated tofu.db \
- pubring-stamp private-keys-v1.d/gpg-sample.stamp
+ pubring-stamp gpg-sample.stamp
private_keys = \
$(test_srcdir)/13CD0F3BDF24BE53FE192D62F18737256FF6E4FD \
@@ -89,26 +87,25 @@ private_keys = \
$(test_srcdir)/7A030357C0F253A5BBCD282FFC4E521B37558F5C
clean-local:
- -$(top_srcdir)/tests/start-stop-agent --stop
+ -$(TESTS_ENVIRONMENT) $(top_srcdir)/tests/start-stop-agent --stop
-rm -fR -- private-keys-v1.d openpgp-revocs.d S.gpg-agent sshcontrol
BUILT_SOURCES = gpg.conf gpg-agent.conf pubring-stamp \
- private-keys-v1.d/gpg-sample.stamp
+ gpg-sample.stamp
-private-keys-v1.d/gpg-sample.stamp: $(private_keys)
- -gpgconf --kill all
+gpg-sample.stamp: $(private_keys)
+ -$(TESTS_ENVIRONMENT) gpgconf --kill all
$(MKDIR_P) ./private-keys-v1.d
for k in $(private_keys); do \
cp $$k private-keys-v1.d/$${k#$(test_srcdir)/}.key; \
done
- echo x > ./private-keys-v1.d/gpg-sample.stamp
+ echo x > ./gpg-sample.stamp
-pubring-stamp: $(test_srcdir)/pubdemo.asc \
- ./private-keys-v1.d/gpg-sample.stamp
- $(GPG) --batch --no-permission-warning \
+pubring-stamp: $(test_srcdir)/pubdemo.asc gpg-sample.stamp
+ $(TESTS_ENVIRONMENT) $(GPG) --batch --no-permission-warning \
--import $(test_srcdir)/pubdemo.asc
- -$(GPG) --batch --no-permission-warning \
+ -$(TESTS_ENVIRONMENT) $(GPG) --batch --no-permission-warning \
--import $(test_srcdir)/secdemo.asc
echo x > ./pubring-stamp
diff --git a/lang/python/tests/Makefile.in b/lang/python/tests/Makefile.in
index 89fcee2..c7512dd 100644
--- a/lang/python/tests/Makefile.in
+++ b/lang/python/tests/Makefile.in
@@ -375,7 +375,7 @@ EXTRA_DIST = support.py $(XTESTS) encrypt-only.asc sign-only.asc \
CLEANFILES = secring.gpg pubring.gpg pubring.kbx trustdb.gpg dirmngr.conf \
gpg-agent.conf pubring.kbx~ gpg.conf pubring.gpg~ \
random_seed .gpg-v21-migrated tofu.db \
- pubring-stamp private-keys-v1.d/gpg-sample.stamp
+ pubring-stamp gpg-sample.stamp
private_keys = \
$(test_srcdir)/13CD0F3BDF24BE53FE192D62F18737256FF6E4FD \
@@ -385,7 +385,7 @@ private_keys = \
$(test_srcdir)/7A030357C0F253A5BBCD282FFC4E521B37558F5C
BUILT_SOURCES = gpg.conf gpg-agent.conf pubring-stamp \
- private-keys-v1.d/gpg-sample.stamp
+ gpg-sample.stamp
all: $(BUILT_SOURCES)
$(MAKE) $(AM_MAKEFLAGS) all-am
@@ -582,8 +582,6 @@ uninstall-am:
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
tags-am uninstall uninstall-am
-export GNUPGHOME := $(abs_builddir)
-export GPG_AGENT_INFO :=
# XXX: Currently, one cannot override automake's 'check' target. As a
# workaround, we avoid defining 'TESTS', thus automake will not emit
@@ -601,22 +599,21 @@ xcheck: all
$(XTESTS)
clean-local:
- -$(top_srcdir)/tests/start-stop-agent --stop
+ -$(TESTS_ENVIRONMENT) $(top_srcdir)/tests/start-stop-agent --stop
-rm -fR -- private-keys-v1.d openpgp-revocs.d S.gpg-agent sshcontrol
-private-keys-v1.d/gpg-sample.stamp: $(private_keys)
- -gpgconf --kill all
+gpg-sample.stamp: $(private_keys)
+ -$(TESTS_ENVIRONMENT) gpgconf --kill all
$(MKDIR_P) ./private-keys-v1.d
for k in $(private_keys); do \
cp $$k private-keys-v1.d/$${k#$(test_srcdir)/}.key; \
done
- echo x > ./private-keys-v1.d/gpg-sample.stamp
+ echo x > ./gpg-sample.stamp
-pubring-stamp: $(test_srcdir)/pubdemo.asc \
- ./private-keys-v1.d/gpg-sample.stamp
- $(GPG) --batch --no-permission-warning \
+pubring-stamp: $(test_srcdir)/pubdemo.asc gpg-sample.stamp
+ $(TESTS_ENVIRONMENT) $(GPG) --batch --no-permission-warning \
--import $(test_srcdir)/pubdemo.asc
- -$(GPG) --batch --no-permission-warning \
+ -$(TESTS_ENVIRONMENT) $(GPG) --batch --no-permission-warning \
--import $(test_srcdir)/secdemo.asc
echo x > ./pubring-stamp