3 # Copyright (C) 2016 g10 Code GmbH
5 # This file is part of GPGME.
7 # GPGME is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # GPGME is distributed in the hope that it will be useful, but WITHOUT
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
15 # Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this program; if not, see <http://www.gnu.org/licenses/>.
20 from __future__ import absolute_import, print_function, unicode_literals
21 del absolute_import, print_function, unicode_literals
27 expected_notations = {
28 "laughing@me": ("Just Squeeze Me", gpg.constants.sig.notation.HUMAN_READABLE),
29 "preferred-email-encoding@pgp.com": ("pgpmime",
30 gpg.constants.sig.notation.HUMAN_READABLE
31 | gpg.constants.sig.notation.CRITICAL),
32 None: ("http://www.gnu.org/policy/", 0),
35 # GnuPG prior to 2.1.13 did not report the critical flag correctly.
36 with gpg.Context() as c:
37 version = c.engine_info.version
38 have_correct_sig_data = not (version.startswith("1.")
39 or version.startswith("2.0.")
41 or (version.startswith("2.1.1")
42 and version[5] < '3'))
44 def check_result(result):
45 assert len(result.signatures) == 1, "Unexpected number of signatures"
46 sig = result.signatures[0]
47 assert len(sig.notations) == len(expected_notations)
49 for r in sig.notations:
50 assert not 'name_len' in dir(r)
51 assert not 'value_len' in dir(r)
52 assert r.name in expected_notations
53 value, flags = expected_notations.pop(r.name)
55 assert r.value == value, \
56 "Expected {!r}, got {!r}".format(value, r.value)
57 assert r.human_readable \
58 == bool(flags & gpg.constants.sig.notation.HUMAN_READABLE)
60 == (bool(flags & gpg.constants.sig.notation.CRITICAL)
61 if have_correct_sig_data else False)
63 assert len(expected_notations) == 0
65 support.init_gpgme(gpg.constants.protocol.OpenPGP)
67 source = gpg.Data("Hallo Leute\n")
71 for name, (value, flags) in expected_notations.items():
72 c.sig_notation_add(name, value, flags)
74 c.op_sign(source, signed, gpg.constants.sig.mode.NORMAL)
76 signed.seek(0, os.SEEK_SET)
78 c.op_verify(signed, None, sink)
79 result = c.op_verify_result()