[git] GPGME - branch, master, updated. gpgme-1.6.0-114-g464d404
by Justus Winter
cvs at cvs.gnupg.org
Thu May 19 11:14:20 CEST 2016
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GnuPG Made Easy".
The branch, master has been updated
via 464d404c8816fc93baf945816c93e86bdeb0ea39 (commit)
via c1c893e3384a07ff864507902fbac4a7fee4d6f1 (commit)
via 07f71cd17706093ca6b1507c41609356d479ae9f (commit)
from 375523ead3a749d77d286c56f10d403c07f2b014 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 464d404c8816fc93baf945816c93e86bdeb0ea39
Author: Justus Winter <justus at gnupg.org>
Date: Wed May 18 15:33:36 2016 +0200
python: Add more tests.
* lang/python/tests/Makefile.am (py_tests): Add new tests.
* lang/python/tests/support.py (print_data): New function.
* lang/python/tests/t-decrypt.py: Use new function.
* lang/python/tests/t-encrypt.py: Likewise.
* lang/python/tests/t-sign.py: New file.
* lang/python/tests/t-encrypt-sym.py: Likewise.
Signed-off-by: Justus Winter <justus at gnupg.org>
diff --git a/lang/python/tests/Makefile.am b/lang/python/tests/Makefile.am
index 87fb8d1..c4fc602 100644
--- a/lang/python/tests/Makefile.am
+++ b/lang/python/tests/Makefile.am
@@ -31,6 +31,8 @@ TESTS_ENVIRONMENT = GNUPGHOME=$(abs_builddir) \
py_tests = t-wrapper.py \
t-data.py \
t-encrypt.py \
+ t-encrypt-sym.py \
+ t-sign.py \
t-decrypt.py
TESTS = $(top_srcdir)/tests/gpg/initial.test \
diff --git a/lang/python/tests/support.py b/lang/python/tests/support.py
index 36b3c88..a57d581 100644
--- a/lang/python/tests/support.py
+++ b/lang/python/tests/support.py
@@ -15,6 +15,7 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, see <http://www.gnu.org/licenses/>.
+import sys
import os
from pyme import core
@@ -24,3 +25,8 @@ def make_filename(name):
def init_gpgme(proto):
core.check_version()
core.engine_check_version(proto)
+
+def print_data(data):
+ if int(os.environ.get('verbose', 0)) > 1:
+ data.seek(0, os.SEEK_SET)
+ sys.stdout.buffer.write(data.read())
diff --git a/lang/python/tests/t-decrypt.py b/lang/python/tests/t-decrypt.py
index da62ba4..bd7b59f 100755
--- a/lang/python/tests/t-decrypt.py
+++ b/lang/python/tests/t-decrypt.py
@@ -17,8 +17,6 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, see <http://www.gnu.org/licenses/>.
-import sys
-import os
from pyme import core, constants
import support
@@ -33,5 +31,4 @@ result = c.op_decrypt_result()
assert not result.unsupported_algorithm, \
"Unsupported algorithm: {}".format(result.unsupported_algorithm)
-sink.seek(0, os.SEEK_SET)
-sys.stdout.buffer.write(sink.read())
+support.print_data(sink)
diff --git a/lang/python/tests/t-encrypt-sym.py b/lang/python/tests/t-encrypt-sym.py
new file mode 100755
index 0000000..0b24fd5
--- /dev/null
+++ b/lang/python/tests/t-encrypt-sym.py
@@ -0,0 +1,63 @@
+#!/usr/bin/env python3
+
+# Copyright (C) 2016 g10 Code GmbH
+#
+# This file is part of GPGME.
+#
+# GPGME 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.
+#
+# GPGME 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 Lesser General
+# Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, see <http://www.gnu.org/licenses/>.
+
+import os
+from pyme import core, constants
+import support
+
+support.init_gpgme(constants.PROTOCOL_OpenPGP)
+
+for passphrase in ("abc", b"abc"):
+ c = core.Context()
+ c.set_armor(True)
+ c.set_pinentry_mode(constants.PINENTRY_MODE_LOOPBACK)
+
+ source = core.Data("Hallo Leute\n")
+ cipher = core.Data()
+
+ passphrase_cb_called = 0
+ def passphrase_cb(hint, desc, prev_bad, hook=None):
+ global passphrase_cb_called
+ passphrase_cb_called += 1
+ return passphrase
+
+ c.set_passphrase_cb(passphrase_cb, None)
+
+ c.op_encrypt([], 0, source, cipher)
+ assert passphrase_cb_called == 1, \
+ "Callback called {} times".format(passphrase_cb_called)
+ support.print_data(cipher)
+
+ c = core.Context()
+ c.set_armor(True)
+ c.set_pinentry_mode(constants.PINENTRY_MODE_LOOPBACK)
+ c.set_passphrase_cb(passphrase_cb, None)
+ plain = core.Data()
+ cipher.seek(0, os.SEEK_SET)
+
+ c.op_decrypt(cipher, plain)
+ # Seems like the passphrase is cached.
+ #assert passphrase_cb_called == 2, \
+ # "Callback called {} times".format(passphrase_cb_called)
+ support.print_data(plain)
+
+ plain.seek(0, os.SEEK_SET)
+ plaintext = plain.read()
+ assert plaintext == b"Hallo Leute\n", \
+ "Wrong plaintext {!r}".format(plaintext)
diff --git a/lang/python/tests/t-encrypt.py b/lang/python/tests/t-encrypt.py
index 3bed752..24869fc 100755
--- a/lang/python/tests/t-encrypt.py
+++ b/lang/python/tests/t-encrypt.py
@@ -17,8 +17,6 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, see <http://www.gnu.org/licenses/>.
-import sys
-import os
from pyme import core, constants
import support
@@ -38,5 +36,4 @@ result = c.op_encrypt_result()
assert not result.invalid_recipients, \
"Invalid recipient encountered: {}".format(result.invalid_recipients.fpr)
-sink.seek(0, os.SEEK_SET)
-sys.stdout.buffer.write(sink.read())
+support.print_data(sink)
diff --git a/lang/python/tests/t-sign.py b/lang/python/tests/t-sign.py
new file mode 100755
index 0000000..a721f03
--- /dev/null
+++ b/lang/python/tests/t-sign.py
@@ -0,0 +1,84 @@
+#!/usr/bin/env python3
+
+# Copyright (C) 2016 g10 Code GmbH
+#
+# This file is part of GPGME.
+#
+# GPGME 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.
+#
+# GPGME 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 Lesser General
+# Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, see <http://www.gnu.org/licenses/>.
+
+import sys
+import os
+from pyme import core, constants
+import support
+
+def check_result(r, typ):
+ if r.invalid_signers:
+ sys.exit("Invalid signer found: {}".format(r.invalid_signers.fpr))
+
+ if len(r.signatures) != 1:
+ sys.exit("Unexpected number of signatures created")
+
+ signature = r.signatures[0]
+ if signature.type != typ:
+ sys.exit("Wrong type of signature created")
+
+ if signature.pubkey_algo != constants.PK_DSA:
+ sys.exit("Wrong pubkey algorithm reported: {}".format(
+ signature.pubkey_algo))
+
+ if signature.hash_algo != constants.MD_SHA1:
+ sys.exit("Wrong hash algorithm reported: {}".format(
+ signature.hash_algo))
+
+ if signature.sig_class != 1:
+ sys.exit("Wrong signature class reported: {}".format(
+ signature.sig_class))
+
+ if signature.fpr != "A0FF4590BB6122EDEF6E3C542D727CC768697734":
+ sys.exit("Wrong fingerprint reported: {}".format(signature.fpr))
+
+
+support.init_gpgme(constants.PROTOCOL_OpenPGP)
+c = core.Context()
+c.set_textmode(True)
+c.set_armor(True)
+
+source = core.Data("Hallo Leute\n")
+sink = core.Data()
+
+c.op_sign(source, sink, constants.SIG_MODE_NORMAL)
+
+result = c.op_sign_result()
+check_result(result, constants.SIG_MODE_NORMAL)
+support.print_data(sink)
+
+# Now a detached signature.
+source.seek(0, os.SEEK_SET)
+sink = core.Data()
+
+c.op_sign(source, sink, constants.SIG_MODE_DETACH)
+
+result = c.op_sign_result()
+check_result(result, constants.SIG_MODE_DETACH)
+support.print_data(sink)
+
+# And finally a cleartext signature. */
+source.seek(0, os.SEEK_SET)
+sink = core.Data()
+
+c.op_sign(source, sink, constants.SIG_MODE_CLEAR)
+
+result = c.op_sign_result()
+check_result(result, constants.SIG_MODE_CLEAR)
+support.print_data(sink)
commit c1c893e3384a07ff864507902fbac4a7fee4d6f1
Author: Justus Winter <justus at gnupg.org>
Date: Thu May 19 10:55:34 2016 +0200
python: More type conversion fixes.
* lang/python/helpers.c (pyPassphraseCb): Cope with 'uid_hint' being
NULL, convert it to an Unicode object, and cope with the callback
returning both Unicode and bytes objects.
Signed-off-by: Justus Winter <justus at gnupg.org>
diff --git a/lang/python/helpers.c b/lang/python/helpers.c
index 285b1da..447a29f 100644
--- a/lang/python/helpers.c
+++ b/lang/python/helpers.c
@@ -82,7 +82,15 @@ static gpgme_error_t pyPassphraseCb(void *hook,
args = PyTuple_New(3);
}
- PyTuple_SetItem(args, 0, PyBytes_FromString(uid_hint));
+ if (uid_hint == NULL)
+ {
+ Py_INCREF(Py_None);
+ PyTuple_SetItem(args, 0, Py_None);
+ }
+ else
+ PyTuple_SetItem(args, 0, PyUnicode_DecodeUTF8(uid_hint, strlen (uid_hint),
+ "strict"));
+
PyTuple_SetItem(args, 1, PyBytes_FromString(passphrase_info));
PyTuple_SetItem(args, 2, PyBool_FromLong((long)prev_was_bad));
if (dataarg) {
@@ -98,7 +106,21 @@ static gpgme_error_t pyPassphraseCb(void *hook,
if (!retval) {
write(fd, "\n", 1);
} else {
- write(fd, PyBytes_AsString(retval), PyBytes_Size(retval));
+ char *buf;
+ size_t len;
+ if (PyBytes_Check(retval))
+ buf = PyBytes_AsString(retval), len = PyBytes_Size(retval);
+ else if (PyUnicode_Check(retval))
+ buf = PyUnicode_AsUTF8AndSize(retval, &len);
+ else
+ {
+ PyErr_Format(PyExc_TypeError,
+ "expected str or bytes from passphrase callback, got %s",
+ retval->ob_type->tp_name);
+ return gpg_error(GPG_ERR_GENERAL);
+ }
+
+ write(fd, buf, len);
write(fd, "\n", 1);
Py_DECREF(retval);
}
commit 07f71cd17706093ca6b1507c41609356d479ae9f
Author: Justus Winter <justus at gnupg.org>
Date: Thu May 19 10:49:43 2016 +0200
python: Fix import.
* lang/python/helpers.c (pygpgme_exception_init): Make module import
relative.
Signed-off-by: Justus Winter <justus at gnupg.org>
diff --git a/lang/python/helpers.c b/lang/python/helpers.c
index 96c844f..285b1da 100644
--- a/lang/python/helpers.c
+++ b/lang/python/helpers.c
@@ -29,7 +29,10 @@ static PyObject *GPGMEError = NULL;
void pygpgme_exception_init(void) {
if (GPGMEError == NULL) {
PyObject *errors;
- errors = PyImport_ImportModule("errors");
+ PyObject *from_list = PyList_New(0);
+ errors = PyImport_ImportModuleLevel("errors", PyEval_GetGlobals(),
+ PyEval_GetLocals(), from_list, 1);
+ Py_XDECREF(from_list);
if (errors) {
GPGMEError=PyDict_GetItemString(PyModule_GetDict(errors), "GPGMEError");
Py_XINCREF(GPGMEError);
-----------------------------------------------------------------------
Summary of changes:
lang/python/helpers.c | 31 ++++++++++++--
lang/python/tests/Makefile.am | 2 +
lang/python/tests/support.py | 6 +++
lang/python/tests/t-decrypt.py | 5 +--
lang/python/tests/t-encrypt-sym.py | 63 ++++++++++++++++++++++++++++
lang/python/tests/t-encrypt.py | 5 +--
lang/python/tests/t-sign.py | 84 ++++++++++++++++++++++++++++++++++++++
7 files changed, 185 insertions(+), 11 deletions(-)
create mode 100755 lang/python/tests/t-encrypt-sym.py
create mode 100755 lang/python/tests/t-sign.py
hooks/post-receive
--
GnuPG Made Easy
http://git.gnupg.org
More information about the Gnupg-commits
mailing list