Page MenuHome GnuPG

No OneTemporary

diff --git a/lang/python/gpgme.i b/lang/python/gpgme.i
index 5b3c193b..87fe90d2 100644
--- a/lang/python/gpgme.i
+++ b/lang/python/gpgme.i
@@ -1,288 +1,314 @@
/*
# $Id$
# Copyright (C) 2004,2008 Igor Belyi <belyi@users.sourceforge.net>
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
#
# This library 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 library 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 library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
%module pygpgme
%include "cpointer.i"
%include "cstring.i"
// Generate doc strings for all methods.
%feature("autodoc", "0");
/* Allow use of Unicode objects, bytes, and None for strings. */
%typemap(in) const char * {
if ($input == Py_None)
$1 = NULL;
else if (PyUnicode_Check($input))
$1 = PyUnicode_AsUTF8($input);
else if (PyBytes_Check($input))
$1 = PyBytes_AsString($input);
else {
PyErr_Format(PyExc_TypeError,
"arg %d: expected str, bytes, or None, got %s",
$argnum, $input->ob_type->tp_name);
return NULL;
}
}
%typemap(freearg) const char * "";
/* Likewise for a list of strings. */
%typemap(in) const char *[] {
/* Check if is a list */
if (PyList_Check($input)) {
size_t i, size = PyList_Size($input);
$1 = (char **) malloc((size+1) * sizeof(char *));
for (i = 0; i < size; i++) {
PyObject *o = PyList_GetItem($input,i);
if (PyUnicode_Check(o))
$1[i] = PyUnicode_AsUTF8(o);
else if (PyString_Check(o))
$1[i] = PyString_AsString(o);
else {
PyErr_Format(PyExc_TypeError,
"arg %d: list must contain only str or bytes, got %s "
"at position %d",
$argnum, o->ob_type->tp_name, i);
free($1);
return NULL;
}
}
$1[i] = NULL;
} else {
PyErr_Format(PyExc_TypeError,
"arg %d: expected a list of str or bytes, got %s",
$argnum, $input->ob_type->tp_name);
return NULL;
}
}
%typemap(freearg) const char *[] {
free((char *) $1);
}
// Release returned buffers as necessary.
%typemap(newfree) char * "free($1);";
%newobject gpgme_data_release_and_get_mem;
%{
/* Convert object to a pointer to gpgme type */
PyObject* object_to_gpgme_t(PyObject* input, const char* objtype, int argnum) {
PyObject *pyname = NULL, *pypointer = NULL;
pyname = PyObject_CallMethod(input, "_getctype", NULL);
if (pyname && PyUnicode_Check(pyname))
{
if (strcmp(PyUnicode_AsUTF8(pyname), objtype) != 0)
{
PyErr_Format(PyExc_TypeError,
"arg %d: Expected value of type %s, but got %s",
argnum, objtype, PyUnicode_AsUTF8(pyname));
Py_DECREF(pyname);
return NULL;
}
}
else
{
PyErr_Format(PyExc_TypeError,
"Protocol violation: Expected an instance of type str "
"from _getctype, but got %s",
pyname == NULL ? "NULL"
: (pyname == Py_None ? "None" : pyname->ob_type->tp_name));
return NULL;
}
Py_DECREF(pyname);
pypointer = PyObject_GetAttrString(input, "wrapped");
if (pypointer == NULL) {
PyErr_Format(PyExc_TypeError,
"arg %d: Use of uninitialized Python object %s",
argnum, objtype);
return NULL;
}
return pypointer;
}
%}
%typemap(arginit) gpgme_key_t [] {
$1 = NULL;
}
%typemap(in) gpgme_key_t [] {
int i, numb = 0;
if (!PySequence_Check($input)) {
PyErr_Format(PyExc_ValueError, "arg %d: Expected a list of gpgme_key_t",
$argnum);
return NULL;
}
if((numb = PySequence_Length($input)) != 0) {
$1 = (gpgme_key_t*)malloc((numb+1)*sizeof(gpgme_key_t));
for(i=0; i<numb; i++) {
PyObject *pypointer = PySequence_GetItem($input, i);
/* input = $input, 1 = $1, 1_descriptor = $1_descriptor */
/* &1_descriptor = $&1_descriptor *1_descriptor = $*1_descriptor */
// Following code is from swig's python.swg
if ((SWIG_ConvertPtr(pypointer,(void **) &$1[i], $*1_descriptor,SWIG_POINTER_EXCEPTION | $disown )) == -1) {
Py_DECREF(pypointer);
return NULL;
}
Py_DECREF(pypointer);
}
$1[numb] = NULL;
}
}
%typemap(freearg) gpgme_key_t [] {
if ($1) free($1);
}
// Special handling for references to our objects.
%typemap(in) gpgme_data_t DATAIN {
if ($input == Py_None)
$1 = NULL;
else {
PyObject *pypointer = NULL;
if((pypointer=object_to_gpgme_t($input, "$1_ltype", $argnum)) == NULL)
return NULL;
/* input = $input, 1 = $1, 1_descriptor = $1_descriptor */
// Following code is from swig's python.swg
if ((SWIG_ConvertPtr(pypointer,(void **) &$1, $1_descriptor,
SWIG_POINTER_EXCEPTION | $disown )) == -1) {
Py_DECREF(pypointer);
return NULL;
}
Py_DECREF(pypointer);
}
}
%apply gpgme_data_t DATAIN {gpgme_data_t plain, gpgme_data_t cipher,
gpgme_data_t sig, gpgme_data_t signed_text,
gpgme_data_t plaintext, gpgme_data_t keydata,
gpgme_data_t pubkey, gpgme_data_t seckey,
gpgme_data_t out};
/* SWIG has problems interpreting ssize_t, off_t or gpgme_error_t in
gpgme.h. */
/* XXX: This is wrong at least for off_t if compiled with LFS. */
%typemap(out) ssize_t, off_t, gpgme_error_t, gpgme_err_code_t, gpgme_err_source_t, gpg_error_t {
$result = PyLong_FromLong($1);
}
/* XXX: This is wrong at least for off_t if compiled with LFS. */
%typemap(in) ssize_t, off_t, gpgme_error_t, gpgme_err_code_t, gpgme_err_source_t, gpg_error_t {
$1 = PyLong_AsLong($input);
}
// Those are for gpgme_data_read() and gpgme_strerror_r()
%typemap(in) (void *buffer, size_t size), (char *buf, size_t buflen) {
$2 = PyLong_AsLong($input);
if ($2 < 0) {
PyErr_SetString(PyExc_ValueError, "Positive integer expected");
return NULL;
}
$1 = ($1_ltype) malloc($2+1);
}
%typemap(argout) (void *buffer, size_t size), (char *buf, size_t buflen) {
Py_XDECREF($result); /* Blow away any previous result */
if (result < 0) { /* Check for I/O error */
free($1);
return PyErr_SetFromErrno(PyExc_RuntimeError);
}
$result = PyBytes_FromStringAndSize($1,result);
free($1);
}
/* For gpgme_data_write, but should be universal. */
%typemap(in) (const void *buffer, size_t size) {
if ($input == Py_None)
$1 = NULL, $2 = 0;
else if (PyUnicode_Check($input))
$1 = PyUnicode_AsUTF8AndSize($input, (size_t *) &$2);
else if (PyBytes_Check($input))
PyBytes_AsStringAndSize($input, (char **) &$1, (size_t *) &$2);
else {
PyErr_Format(PyExc_TypeError,
"arg %d: expected str, bytes, or None, got %s",
$argnum, $input->ob_type->tp_name);
return NULL;
}
}
%typemap(freearg) (const void *buffer, size_t size) "";
// Make types containing 'next' field to be lists
%ignore next;
%typemap(out) gpgme_sig_notation_t, gpgme_engine_info_t, gpgme_subkey_t, gpgme_key_sig_t,
gpgme_user_id_t, gpgme_invalid_key_t, gpgme_recipient_t, gpgme_new_signature_t,
gpgme_signature_t, gpgme_import_status_t, gpgme_conf_arg_t, gpgme_conf_opt_t,
gpgme_conf_comp_t {
int i;
int size = 0;
$1_ltype curr;
for (curr = $1; curr != NULL; curr = curr->next) {
size++;
}
$result = PyList_New(size);
for (i=0,curr=$1; i<size; i++,curr=curr->next) {
PyObject *o = SWIG_NewPointerObj(SWIG_as_voidptr(curr), $1_descriptor, %newpointer_flags);
PyList_SetItem($result, i, o);
}
}
// Include mapper for edit callbacks
%typemap(in) (gpgme_edit_cb_t fnc, void *fnc_value) {
$1 = (gpgme_edit_cb_t) pyEditCb;
if ($input == Py_None)
$2 = NULL;
else
$2 = $input;
}
-// Include the header file both for cc (first) and for swig (second)
-// Include for swig locally since we need to fix 'class' usage there.
-%{
-#include <gpgme.h>
-%}
+/* Include the unmodified <gpgme.h> for cc, and the cleaned-up local
+ version for SWIG. We do, however, want to hide certain fields on
+ some structs, which we provide prior to including the version for
+ SWIG. */
+ %{ #include <gpgme.h> %}
+
+/* This is for notations, where we want to hide the length fields, and
+ the unused bit field block. */
+struct _gpgme_sig_notation
+{
+ struct _gpgme_sig_notation *next;
+
+ /* If NAME is a null pointer, then VALUE contains a policy URL
+ rather than a notation. */
+ char *name;
+
+ /* The value of the notation data. */
+ char *value;
+
+ /* The accumulated flags. */
+ gpgme_sig_notation_flags_t flags;
+
+ /* Notation data is human-readable. */
+ unsigned int human_readable : 1;
+
+ /* Notation data is critical. */
+ unsigned int critical : 1;
+};
+
+/* Now include our local modified version. Any structs defined above
+ are ignored. */
%include "gpgme.h"
%include "errors.i"
// Generating and handling pointers-to-pointers.
%pointer_functions(gpgme_ctx_t, gpgme_ctx_t_p);
%pointer_functions(gpgme_data_t, gpgme_data_t_p);
%pointer_functions(gpgme_key_t, gpgme_key_t_p);
%pointer_functions(gpgme_error_t, gpgme_error_t_p);
%pointer_functions(gpgme_trust_item_t, gpgme_trust_item_t_p);
%pointer_functions(gpgme_engine_info_t, gpgme_engine_info_t_p);
%pointer_functions(PyObject *, PyObject_p_p);
%pointer_functions(void *, void_p_p);
// Helper functions.
%{
#include <stdio.h>
%}
FILE *fdopen(int fildes, const char *mode);
%{
#include "helpers.h"
%}
%include "helpers.h"
diff --git a/lang/python/tests/Makefile.am b/lang/python/tests/Makefile.am
index 0bc8c7f8..b85e82e3 100644
--- a/lang/python/tests/Makefile.am
+++ b/lang/python/tests/Makefile.am
@@ -1,94 +1,97 @@
# Makefile.am for the tests of the Python bindings.
# 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/>.
GPG = gpg
GPG_AGENT = gpg-agent
export GNUPGHOME := $(abs_builddir)
export GPG_AGENT_INFO :=
test_srcdir = $(top_srcdir)/tests/gpg
TESTS_ENVIRONMENT = GNUPGHOME=$(abs_builddir) \
LC_ALL=C GPG_AGENT_INFO= \
top_srcdir=$(top_srcdir) \
LD_LIBRARY_PATH="../../../src/.libs" \
PYTHONPATH=`echo $(abs_builddir)/../build/lib.*`
py_tests = t-wrapper.py \
t-callbacks.py \
t-data.py \
t-encrypt.py \
t-encrypt-sym.py \
t-encrypt-sign.py \
t-sign.py \
t-signers.py \
t-decrypt.py \
+ t-verify.py \
+ t-decrypt-verify.py \
+ t-sig-notation.py \
t-export.py \
t-trustlist.py \
t-edit.py \
t-wait.py \
t-encrypt-large.py \
t-file-name.py
TESTS = $(top_srcdir)/tests/gpg/initial.test \
$(py_tests) \
$(top_srcdir)/tests/gpg/final.test
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 pubring-stamp
private_keys = \
$(test_srcdir)/13CD0F3BDF24BE53FE192D62F18737256FF6E4FD \
$(test_srcdir)/76F7E2B35832976B50A27A282D9B87E44577EB66 \
$(test_srcdir)/A0747D5F9425E6664F4FFBEED20FBCA79FDED2BD \
$(test_srcdir)/13CBE3758AFE42B5E5E2AE4CED27AFA455E3F87F \
$(test_srcdir)/7A030357C0F253A5BBCD282FFC4E521B37558F5C
clean-local:
-$(top_srcdir)/tests/start-stop-agent --stop
-rm -fR -- private-keys-v1.d openpgp-revocs.d S.gpg-agent sshcontrol
check-local: ./gpg.conf ./gpg-agent.conf ./pubring-stamp \
./private-keys-v1.d/gpg-sample.stamp
# To guarantee that check-local is run before any tests we
# add this dependency:
$(top_srcdir)/tests/gpg/initial.test: check-local
./private-keys-v1.d/gpg-sample.stamp: $(private_keys)
test -d ./private-keys-v1.d || mkdir ./private-keys-v1.d
for k in $(private_keys); do \
cp $$k private-keys-v1.d/`basename $$k`.key; \
done
echo x > ./private-keys-v1.d/gpg-sample.stamp
./pubring-stamp: $(test_srcdir)/pubdemo.asc
$(GPG) --no-permission-warning \
--import $(test_srcdir)/pubdemo.asc
-$(GPG) --no-permission-warning \
--import $(test_srcdir)/secdemo.asc
touch ./pubring-stamp
./gpg.conf:
# This is required for t-sig-notations.
echo no-force-v3-sigs > ./gpg.conf
./gpg-agent.conf:
# This is required for gpg2, which does not support command fd.
echo pinentry-program $(abs_top_srcdir)/tests/gpg/pinentry > ./gpg-agent.conf
diff --git a/lang/python/tests/t-decrypt-verify.py b/lang/python/tests/t-decrypt-verify.py
new file mode 100755
index 00000000..433e0a1e
--- /dev/null
+++ b/lang/python/tests/t-decrypt-verify.py
@@ -0,0 +1,50 @@
+#!/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/>.
+
+from pyme import core, constants, errors
+import support
+
+def check_verify_result(result, summary, fpr, status):
+ assert len(result.signatures) == 1, "Unexpected number of signatures"
+ sig = result.signatures[0]
+ assert sig.summary == summary, "Unexpected signature summary"
+ assert sig.fpr == fpr
+ assert errors.GPGMEError(sig.status).getcode() == status
+ assert len(sig.notations) == 0
+ assert not sig.wrong_key_usage
+ assert sig.validity == constants.VALIDITY_UNKNOWN
+ assert errors.GPGMEError(sig.validity_reason).getcode() == errors.NO_ERROR
+
+support.init_gpgme(constants.PROTOCOL_OpenPGP)
+c = core.Context()
+
+source = core.Data(file=support.make_filename("cipher-2.asc"))
+sink = core.Data()
+
+c.op_decrypt_verify(source, sink)
+result = c.op_decrypt_result()
+assert not result.unsupported_algorithm, \
+ "Unsupported algorithm: {}".format(result.unsupported_algorithm)
+
+support.print_data(sink)
+
+verify_result = c.op_verify_result()
+check_verify_result(verify_result, 0,
+ "A0FF4590BB6122EDEF6E3C542D727CC768697734",
+ errors.NO_ERROR)
diff --git a/lang/python/tests/t-sig-notation.py b/lang/python/tests/t-sig-notation.py
new file mode 100755
index 00000000..2d832ef2
--- /dev/null
+++ b/lang/python/tests/t-sig-notation.py
@@ -0,0 +1,68 @@
+#!/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, errors
+import support
+
+expected_notations = {
+ "laughing@me": ("Just Squeeze Me", constants.SIG_NOTATION_HUMAN_READABLE),
+ "preferred-email-encoding@pgp.com": ("pgpmime",
+ constants.SIG_NOTATION_HUMAN_READABLE
+ | constants.SIG_NOTATION_CRITICAL),
+ None: ("http://www.gnu.org/policy/", 0),
+}
+
+def check_result(result):
+ assert len(result.signatures) == 1, "Unexpected number of signatures"
+ sig = result.signatures[0]
+ assert len(sig.notations) == len(expected_notations)
+
+ for r in sig.notations:
+ assert not 'name_len' in dir(r)
+ assert not 'value_len' in dir(r)
+ assert r.name in expected_notations
+ value, flags = expected_notations.pop(r.name)
+
+ assert r.value == value, \
+ "Expected {!r}, got {!r}".format(value, r.value)
+ assert r.human_readable \
+ == bool(flags&constants.SIG_NOTATION_HUMAN_READABLE)
+ # xxx notyet
+ #assert r.human_readable \
+ # == bool(flags&constants.SIG_NOTATION_CRITICAL)
+
+ assert len(expected_notations) == 0
+
+support.init_gpgme(constants.PROTOCOL_OpenPGP)
+
+source = core.Data("Hallo Leute\n")
+signed = core.Data()
+
+c = core.Context()
+for name, (value, flags) in expected_notations.items():
+ c.sig_notation_add(name, value, flags)
+
+c.op_sign(source, signed, constants.SIG_MODE_NORMAL)
+
+signed.seek(0, os.SEEK_SET)
+sink = core.Data()
+c.op_verify(signed, None, sink)
+result = c.op_verify_result()
+check_result(result)
diff --git a/lang/python/tests/t-verify.py b/lang/python/tests/t-verify.py
new file mode 100755
index 00000000..333ee4e8
--- /dev/null
+++ b/lang/python/tests/t-verify.py
@@ -0,0 +1,128 @@
+#!/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, errors
+import support
+
+test_text1 = "Just GNU it!\n"
+test_text1f= "Just GNU it?\n"
+test_sig1 = """-----BEGIN PGP SIGNATURE-----
+
+iN0EABECAJ0FAjoS+i9FFIAAAAAAAwA5YmFyw7bDpMO8w58gZGFzIHdhcmVuIFVt
+bGF1dGUgdW5kIGpldHp0IGVpbiBwcm96ZW50JS1aZWljaGVuNRSAAAAAAAgAJGZv
+b2Jhci4xdGhpcyBpcyBhIG5vdGF0aW9uIGRhdGEgd2l0aCAyIGxpbmVzGhpodHRw
+Oi8vd3d3Lmd1Lm9yZy9wb2xpY3kvAAoJEC1yfMdoaXc0JBIAoIiLlUsvpMDOyGEc
+dADGKXF/Hcb+AKCJWPphZCphduxSvrzH0hgzHdeQaA==
+=nts1
+-----END PGP SIGNATURE-----
+"""
+
+test_sig2 = """-----BEGIN PGP MESSAGE-----
+
+owGbwMvMwCSoW1RzPCOz3IRxjXQSR0lqcYleSUWJTZOvjVdpcYmCu1+oQmaJIleH
+GwuDIBMDGysTSIqBi1MApi+nlGGuwDeHao53HBr+FoVGP3xX+kvuu9fCMJvl6IOf
+y1kvP4y+8D5a11ang0udywsA
+=Crq6
+-----END PGP MESSAGE-----
+"""
+
+# A message with a prepended but unsigned plaintext packet.
+double_plaintext_sig = """-----BEGIN PGP MESSAGE-----
+
+rDRiCmZvb2Jhci50eHRF4pxNVGhpcyBpcyBteSBzbmVha3kgcGxhaW50ZXh0IG1l
+c3NhZ2UKowGbwMvMwCSoW1RzPCOz3IRxTWISa6JebnG666MFD1wzSzJSixQ81XMV
+UlITUxTyixRyKxXKE0uSMxQyEosVikvyCwpSU/S4FNCArq6Ce1F+aXJGvoJvYlGF
+erFCTmJxiUJ5flFKMVeHGwuDIBMDGysTyA4GLk4BmO036xgWzMgzt9V85jCtfDFn
+UqVooWlGXHwNw/xg/fVzt9VNbtjtJ/fhUqYo0/LyCGEA
+=6+AK
+-----END PGP MESSAGE-----
+"""
+
+def check_result(result, summary, fpr, status, notation):
+ assert len(result.signatures) == 1, "Unexpected number of signatures"
+ sig = result.signatures[0]
+ assert sig.summary == summary, "Unexpected signature summary"
+ assert sig.fpr == fpr
+ assert errors.GPGMEError(sig.status).getcode() == status
+
+ if notation:
+ expected_notations = {
+ "bar": b"\xc3\xb6\xc3\xa4\xc3\xbc\xc3\x9f".decode() +
+ " das waren Umlaute und jetzt ein prozent%-Zeichen",
+ "foobar.1": "this is a notation data with 2 lines",
+ None: "http://www.gu.org/policy/",
+ }
+ assert len(sig.notations) == len(expected_notations)
+
+ for r in sig.notations:
+ assert not 'name_len' in dir(r)
+ assert not 'value_len' in dir(r)
+ assert r.name in expected_notations
+ assert r.value == expected_notations[r.name], \
+ "Expected {!r}, got {!r}".format(expected_notations[r.name],
+ r.value)
+ expected_notations.pop(r.name)
+
+ assert len(expected_notations) == 0
+
+ assert not sig.wrong_key_usage
+ assert sig.validity == constants.VALIDITY_UNKNOWN
+ assert errors.GPGMEError(sig.validity_reason).getcode() == errors.NO_ERROR
+
+
+support.init_gpgme(constants.PROTOCOL_OpenPGP)
+c = core.Context()
+c.set_armor(True)
+
+# Checking a valid message.
+text = core.Data(test_text1)
+sig = core.Data(test_sig1)
+c.op_verify(sig, text, None)
+result = c.op_verify_result()
+check_result(result, 0, "A0FF4590BB6122EDEF6E3C542D727CC768697734",
+ errors.NO_ERROR, True)
+
+
+# Checking a manipulated message.
+text = core.Data(test_text1f)
+sig.seek(0, os.SEEK_SET)
+c.op_verify(sig, text, None)
+result = c.op_verify_result()
+check_result(result, constants.SIGSUM_RED, "2D727CC768697734",
+ errors.BAD_SIGNATURE, False)
+
+# Checking a normal signature.
+text = core.Data()
+sig = core.Data(test_sig2)
+c.op_verify(sig, None, text)
+result = c.op_verify_result()
+check_result(result, 0, "A0FF4590BB6122EDEF6E3C542D727CC768697734",
+ errors.NO_ERROR, False)
+
+# Checking an invalid message.
+text = core.Data()
+sig = core.Data(double_plaintext_sig)
+try:
+ c.op_verify(sig, None, text)
+except Exception as e:
+ assert type(e) == errors.GPGMEError
+ assert e.getcode() == errors.BAD_DATA
+else:
+ assert False, "Expected an error but got none."

File Metadata

Mime Type
text/x-diff
Expires
Sun, Dec 14, 9:55 AM (23 h, 26 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
c9/f1/84afa89efb8fca47f362033a70c0

Event Timeline