Page Menu
Home
GnuPG
Search
Configure Global Search
Log In
Files
F36623568
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Size
81 KB
Subscribers
None
View Options
diff --git a/examples/assuan.py b/examples/assuan.py
index f02cd16..dd42ad4 100644
--- a/examples/assuan.py
+++ b/examples/assuan.py
@@ -1,28 +1,28 @@
#!/usr/bin/env python
#
# Copyright (C) 2016 g10 Code GmbH
#
# 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 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 for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
"""Demonstrate the use of the Assuan protocol engine"""
from __future__ import absolute_import, print_function, unicode_literals
del absolute_import, print_function, unicode_literals
import gpg
-with gpg.Context(protocol=gpg.constants.PROTOCOL_ASSUAN) as c:
+with gpg.Context(protocol=gpg.constants.protocol.ASSUAN) as c:
# Invoke the pinentry to get a confirmation.
err = c.assuan_transact(['GET_CONFIRMATION', 'Hello there'])
print("You chose {}.".format("cancel" if err else "ok"))
diff --git a/examples/testCMSgetkey.py b/examples/testCMSgetkey.py
index 0f02cb1..d4c0884 100644
--- a/examples/testCMSgetkey.py
+++ b/examples/testCMSgetkey.py
@@ -1,35 +1,35 @@
#!/usr/bin/env python
#
# Copyright (C) 2016 g10 Code GmbH
# Copyright (C) 2008 Bernhard Reiter <bernhard@intevation.de>
#
# 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 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 for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
"""A test applicaton for the CMS protocol."""
from __future__ import absolute_import, print_function, unicode_literals
del absolute_import, print_function, unicode_literals
import sys
import gpg
if len(sys.argv) != 2:
sys.exit("fingerprint or unique key ID for gpgme_get_key()")
-with gpg.Context(protocol=gpg.constants.PROTOCOL_CMS) as c:
+with gpg.Context(protocol=gpg.constants.protocol.CMS) as c:
key = c.get_key(sys.argv[1])
print("got key: ", key.subkeys[0].fpr)
for uid in key.uids:
print(uid.uid)
diff --git a/gpg/constants/sig/__init__.py b/gpg/constants/sig/__init__.py
index 2ce0edf..39d4e6e 100644
--- a/gpg/constants/sig/__init__.py
+++ b/gpg/constants/sig/__init__.py
@@ -1,6 +1,6 @@
from __future__ import absolute_import, print_function, unicode_literals
del absolute_import, print_function, unicode_literals
-from . import mode
-__all__ = ['mode']
+from . import mode, notation
+__all__ = ['mode', 'notation']
diff --git a/tests/t-export.py b/gpg/constants/sig/notation.py
old mode 100755
new mode 100644
similarity index 51%
copy from tests/t-export.py
copy to gpg/constants/sig/notation.py
index 4f67502..9a79e01
--- a/tests/t-export.py
+++ b/gpg/constants/sig/notation.py
@@ -1,40 +1,25 @@
-#!/usr/bin/env python
-
+# Constants for signature notation data.
+#
# 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.
+# 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.
#
# 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 __future__ import absolute_import, print_function, unicode_literals
del absolute_import, print_function, unicode_literals
-import gpg
-import support
-
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
-c = gpg.Context()
-c.set_armor(True)
-
-sink = gpg.Data()
-c.op_export_ext(['Alpha', 'Bob'], 0, sink)
-support.print_data(sink)
-
-# Again. Now using a key array.
-keys = []
-keys.append(c.get_key("0x68697734", False)) # Alpha
-keys.append(c.get_key("0xA9E3B0B2", False)) # Bob
-sink = gpg.Data()
-c.op_export_keys(keys, 0, sink)
-support.print_data(sink)
+from gpg import util
+util.process_constants('GPGME_SIG_NOTATION_', globals())
+del util
diff --git a/tests/initial.py b/tests/initial.py
index a811a93..ebe7f8a 100755
--- a/tests/initial.py
+++ b/tests/initial.py
@@ -1,41 +1,41 @@
#!/usr/bin/env python
# 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 __future__ import absolute_import, print_function, unicode_literals
del absolute_import, print_function, unicode_literals
import os
import subprocess
import gpg
import support
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
subprocess.check_call([os.path.join(os.getenv('top_srcdir'),
"tests", "start-stop-agent"), "--start"])
with gpg.Context() as c:
alpha = c.get_key("A0FF4590BB6122EDEF6E3C542D727CC768697734", False)
bob = c.get_key("D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2", False)
# Mark alpha as trusted. The signature verification tests expect
# this.
support.mark_key_trusted(c, alpha)
c.op_import(open(support.in_srcdir("encrypt-only.asc")))
c.op_import(open(support.in_srcdir("sign-only.asc")))
diff --git a/tests/t-callbacks.py b/tests/t-callbacks.py
index 05eb194..eed50bc 100755
--- a/tests/t-callbacks.py
+++ b/tests/t-callbacks.py
@@ -1,257 +1,257 @@
#!/usr/bin/env python
# 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 __future__ import absolute_import, print_function, unicode_literals
del absolute_import, print_function, unicode_literals
import os
import gpg
import support
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
c = gpg.Context()
c.set_pinentry_mode(gpg.constants.PINENTRY_MODE_LOOPBACK)
source = gpg.Data("Hallo Leute\n")
sink = gpg.Data()
# Valid passphrases, both as string and bytes.
for passphrase in ('foo', b'foo'):
def passphrase_cb(hint, desc, prev_bad, hook=None):
assert hook == passphrase
return hook
c.set_passphrase_cb(passphrase_cb, passphrase)
c.op_encrypt([], 0, source, sink)
# Returning an invalid type.
def passphrase_cb(hint, desc, prev_bad, hook=None):
return 0
c.set_passphrase_cb(passphrase_cb, None)
try:
c.op_encrypt([], 0, source, sink)
except Exception as e:
assert type(e) == TypeError
assert str(e) == "expected str or bytes from passphrase callback, got int"
else:
assert False, "Expected an error, got none"
# Raising an exception inside callback.
myException = Exception()
def passphrase_cb(hint, desc, prev_bad, hook=None):
raise myException
c.set_passphrase_cb(passphrase_cb, None)
try:
c.op_encrypt([], 0, source, sink)
except Exception as e:
assert e == myException
else:
assert False, "Expected an error, got none"
# Wrong kind of callback function.
def bad_passphrase_cb():
pass
c.set_passphrase_cb(bad_passphrase_cb, None)
try:
c.op_encrypt([], 0, source, sink)
except Exception as e:
assert type(e) == TypeError
else:
assert False, "Expected an error, got none"
# Test the progress callback.
parms = """<GnupgKeyParms format="internal">
Key-Type: RSA
Key-Length: 1024
Name-Real: Joe Tester
Name-Comment: with stupid passphrase
Name-Email: joe+gpg@example.org
Passphrase: Crypt0R0cks
Expire-Date: 2020-12-31
</GnupgKeyParms>
"""
messages = []
def progress_cb(what, typ, current, total, hook=None):
assert hook == messages
messages.append(
"PROGRESS UPDATE: what = {}, type = {}, current = {}, total = {}"
.format(what, typ, current, total))
c = gpg.Context()
c.set_progress_cb(progress_cb, messages)
c.op_genkey(parms, None, None)
assert len(messages) > 0
# Test exception handling.
def progress_cb(what, typ, current, total, hook=None):
raise myException
c = gpg.Context()
c.set_progress_cb(progress_cb, None)
try:
c.op_genkey(parms, None, None)
except Exception as e:
assert e == myException
else:
assert False, "Expected an error, got none"
# Test the edit callback.
c = gpg.Context()
c.set_pinentry_mode(gpg.constants.PINENTRY_MODE_LOOPBACK)
c.set_passphrase_cb(lambda *args: "abc")
sink = gpg.Data()
alpha = c.get_key("A0FF4590BB6122EDEF6E3C542D727CC768697734", False)
cookie = object()
edit_cb_called = False
def edit_cb(status, args, hook):
global edit_cb_called
edit_cb_called = True
assert hook == cookie
return "quit" if args == "keyedit.prompt" else None
c.op_edit(alpha, edit_cb, cookie, sink)
assert edit_cb_called
# Test exceptions.
c = gpg.Context()
c.set_pinentry_mode(gpg.constants.PINENTRY_MODE_LOOPBACK)
c.set_passphrase_cb(lambda *args: "abc")
sink = gpg.Data()
def edit_cb(status, args):
raise myException
try:
c.op_edit(alpha, edit_cb, None, sink)
except Exception as e:
assert e == myException
else:
assert False, "Expected an error, got none"
# Test the status callback.
source = gpg.Data("Hallo Leute\n")
sink = gpg.Data()
status_cb_called = False
def status_cb(keyword, args, hook=None):
global status_cb_called
status_cb_called = True
assert hook == cookie
c = gpg.Context()
c.set_status_cb(status_cb, cookie)
c.set_ctx_flag("full-status", "1")
c.op_encrypt([alpha], gpg.constants.ENCRYPT_ALWAYS_TRUST, source, sink)
assert status_cb_called
# Test exceptions.
source = gpg.Data("Hallo Leute\n")
sink = gpg.Data()
def status_cb(keyword, args):
raise myException
c = gpg.Context()
c.set_status_cb(status_cb, None)
c.set_ctx_flag("full-status", "1")
try:
c.op_encrypt([alpha], gpg.constants.ENCRYPT_ALWAYS_TRUST, source, sink)
except Exception as e:
assert e == myException
else:
assert False, "Expected an error, got none"
# Test the data callbacks.
def read_cb(amount, hook=None):
assert hook == cookie
return 0
def release_cb(hook=None):
assert hook == cookie
data = gpg.Data(cbs=(read_cb, None, None, release_cb, cookie))
try:
data.read()
except Exception as e:
assert type(e) == TypeError
else:
assert False, "Expected an error, got none"
def read_cb(amount):
raise myException
data = gpg.Data(cbs=(read_cb, None, None, lambda: None))
try:
data.read()
except Exception as e:
assert e == myException
else:
assert False, "Expected an error, got none"
def write_cb(what, hook=None):
assert hook == cookie
return "wrong type"
data = gpg.Data(cbs=(None, write_cb, None, release_cb, cookie))
try:
data.write(b'stuff')
except Exception as e:
assert type(e) == TypeError
else:
assert False, "Expected an error, got none"
def write_cb(what):
raise myException
data = gpg.Data(cbs=(None, write_cb, None, lambda: None))
try:
data.write(b'stuff')
except Exception as e:
assert e == myException
else:
assert False, "Expected an error, got none"
def seek_cb(offset, whence, hook=None):
assert hook == cookie
return "wrong type"
data = gpg.Data(cbs=(None, None, seek_cb, release_cb, cookie))
try:
data.seek(0, os.SEEK_SET)
except Exception as e:
assert type(e) == TypeError
else:
assert False, "Expected an error, got none"
def seek_cb(offset, whence):
raise myException
data = gpg.Data(cbs=(None, None, seek_cb, lambda: None))
try:
data.seek(0, os.SEEK_SET)
except Exception as e:
assert e == myException
else:
assert False, "Expected an error, got none"
diff --git a/tests/t-decrypt-verify.py b/tests/t-decrypt-verify.py
index 1fa7a6f..6243167 100755
--- a/tests/t-decrypt-verify.py
+++ b/tests/t-decrypt-verify.py
@@ -1,76 +1,76 @@
#!/usr/bin/env python
# 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 __future__ import absolute_import, print_function, unicode_literals
del absolute_import, print_function, unicode_literals
import gpg
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 gpg.errors.GPGMEError(sig.status).getcode() == status
assert len(sig.notations) == 0
assert not sig.wrong_key_usage
- assert sig.validity == gpg.constants.VALIDITY_FULL
+ assert sig.validity == gpg.constants.validity.FULL
assert gpg.errors.GPGMEError(sig.validity_reason).getcode() == gpg.errors.NO_ERROR
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
c = gpg.Context()
source = gpg.Data(file=support.make_filename("cipher-2.asc"))
sink = gpg.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,
- gpg.constants.SIGSUM_VALID | gpg.constants.SIGSUM_GREEN,
+ gpg.constants.sigsum.VALID | gpg.constants.sigsum.GREEN,
"A0FF4590BB6122EDEF6E3C542D727CC768697734",
gpg.errors.NO_ERROR)
# Idiomatic interface.
with gpg.Context() as c:
alpha = c.get_key("A0FF4590BB6122EDEF6E3C542D727CC768697734", False)
bob = c.get_key("D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2", False)
plaintext, _, verify_result = \
c.decrypt(open(support.make_filename("cipher-2.asc")), verify=[alpha])
assert plaintext.find(b'Wenn Sie dies lesen k') >= 0, \
'Plaintext not found'
check_verify_result(verify_result,
- gpg.constants.SIGSUM_VALID | gpg.constants.SIGSUM_GREEN,
+ gpg.constants.sigsum.VALID | gpg.constants.sigsum.GREEN,
"A0FF4590BB6122EDEF6E3C542D727CC768697734",
gpg.errors.NO_ERROR)
try:
c.decrypt(open(support.make_filename("cipher-2.asc")),
verify=[alpha, bob])
except gpg.errors.MissingSignatures as e:
assert len(e.missing) == 1
assert e.missing[0] == bob
else:
assert False, "Expected an error, got none"
diff --git a/tests/t-decrypt.py b/tests/t-decrypt.py
index daaad3d..1af0562 100755
--- a/tests/t-decrypt.py
+++ b/tests/t-decrypt.py
@@ -1,44 +1,44 @@
#!/usr/bin/env python
# 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 __future__ import absolute_import, print_function, unicode_literals
del absolute_import, print_function, unicode_literals
import gpg
import support
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
c = gpg.Context()
source = gpg.Data(file=support.make_filename("cipher-1.asc"))
sink = gpg.Data()
c.op_decrypt(source, sink)
result = c.op_decrypt_result()
assert not result.unsupported_algorithm, \
"Unsupported algorithm: {}".format(result.unsupported_algorithm)
support.print_data(sink)
# Idiomatic interface.
with gpg.Context() as c:
plaintext, _, _ = c.decrypt(open(support.make_filename("cipher-1.asc")))
assert len(plaintext) > 0
assert plaintext.find(b'Wenn Sie dies lesen k') >= 0, \
'Plaintext not found'
diff --git a/tests/t-edit.py b/tests/t-edit.py
index 82f6401..bd70e7e 100755
--- a/tests/t-edit.py
+++ b/tests/t-edit.py
@@ -1,72 +1,72 @@
#!/usr/bin/env python
# Copyright (C) 2005 Igor Belyi <belyi@users.sourceforge.net>
# 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 __future__ import absolute_import, print_function, unicode_literals
del absolute_import, print_function, unicode_literals
import sys
import os
import gpg
import support
class KeyEditor(object):
def __init__(self):
self.steps = ["fpr", "expire", "1", "primary", "quit"]
self.step = 0
self.done = False
self.verbose = int(os.environ.get('verbose', 0)) > 1
def edit_fnc(self, status, args, out=None):
if args == "keyedit.prompt":
result = self.steps[self.step]
self.step += 1
elif args == "keyedit.save.okay":
result = "Y"
self.done = self.step == len(self.steps)
elif args == "keygen.valid":
result = "0"
else:
result = None
if self.verbose:
sys.stderr.write("Code: {}, args: {!r}, Returning: {!r}\n"
.format(status, args, result))
return result
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
c = gpg.Context()
c.set_pinentry_mode(gpg.constants.PINENTRY_MODE_LOOPBACK)
c.set_passphrase_cb(lambda *args: "abc")
c.set_armor(True)
# The deprecated interface.
editor = KeyEditor()
c.interact(c.get_key("A0FF4590BB6122EDEF6E3C542D727CC768697734", False),
editor.edit_fnc)
assert editor.done
# The deprecated interface.
sink = gpg.Data()
editor = KeyEditor()
c.op_edit(c.get_key("A0FF4590BB6122EDEF6E3C542D727CC768697734", False),
editor.edit_fnc, sink, sink)
assert editor.done
diff --git a/tests/t-encrypt-large.py b/tests/t-encrypt-large.py
index 1c3c4f6..cdb4a32 100755
--- a/tests/t-encrypt-large.py
+++ b/tests/t-encrypt-large.py
@@ -1,66 +1,66 @@
#!/usr/bin/env python
# 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 __future__ import absolute_import, print_function, unicode_literals
del absolute_import, print_function, unicode_literals
import sys
import random
import gpg
import support
if len(sys.argv) == 2:
nbytes = int(sys.argv[1])
else:
nbytes = 100000
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
c = gpg.Context()
ntoread = nbytes
def read_cb(amount):
global ntoread
chunk = ntoread if ntoread < amount else amount
ntoread -= chunk
assert ntoread >= 0
assert chunk >= 0
return bytes(bytearray(random.randrange(256) for i in range(chunk)))
nwritten = 0
def write_cb(data):
global nwritten
nwritten += len(data)
return len(data)
source = gpg.Data(cbs=(read_cb, None, None, lambda: None))
sink = gpg.Data(cbs=(None, write_cb, None, lambda: None))
keys = []
keys.append(c.get_key("A0FF4590BB6122EDEF6E3C542D727CC768697734", False))
keys.append(c.get_key("D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2", False))
c.op_encrypt(keys, gpg.constants.ENCRYPT_ALWAYS_TRUST, source, sink)
result = c.op_encrypt_result()
assert not result.invalid_recipients, \
"Invalid recipient encountered: {}".format(result.invalid_recipients.fpr)
assert ntoread == 0
if support.verbose:
sys.stderr.write(
"plaintext={} bytes, ciphertext={} bytes\n".format(nbytes, nwritten))
diff --git a/tests/t-encrypt-sign.py b/tests/t-encrypt-sign.py
index 9b06202..094a2b0 100755
--- a/tests/t-encrypt-sign.py
+++ b/tests/t-encrypt-sign.py
@@ -1,97 +1,97 @@
#!/usr/bin/env python
# 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 __future__ import absolute_import, print_function, unicode_literals
del absolute_import, print_function, unicode_literals
import sys
import gpg
import support
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
c = gpg.Context()
c.set_armor(True)
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 != gpg.constants.PK_DSA:
+ if signature.pubkey_algo != gpg.constants.pk.DSA:
sys.exit("Wrong pubkey algorithm reported: {}".format(
signature.pubkey_algo))
- if signature.hash_algo not in (gpg.constants.MD_SHA1, gpg.constants.MD_RMD160):
+ if signature.hash_algo not in (gpg.constants.md.SHA1, gpg.constants.md.RMD160):
sys.exit("Wrong hash algorithm reported: {}".format(
signature.hash_algo))
if signature.sig_class != 0:
sys.exit("Wrong signature class reported: {}".format(
signature.sig_class))
if signature.fpr != "A0FF4590BB6122EDEF6E3C542D727CC768697734":
sys.exit("Wrong fingerprint reported: {}".format(signature.fpr))
keys = []
keys.append(c.get_key("A0FF4590BB6122EDEF6E3C542D727CC768697734", False))
keys.append(c.get_key("D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2", False))
for recipients in (keys, []):
source = gpg.Data("Hallo Leute\n")
sink = gpg.Data()
c.op_encrypt_sign(recipients, gpg.constants.ENCRYPT_ALWAYS_TRUST, source, sink)
result = c.op_encrypt_result()
assert not result.invalid_recipients, \
"Invalid recipient encountered: {}".format(
result.invalid_recipients.fpr)
result = c.op_sign_result()
- check_result(result, gpg.constants.SIG_MODE_NORMAL)
+ check_result(result, gpg.constants.sig.mode.NORMAL)
support.print_data(sink)
# Idiomatic interface.
with gpg.Context(armor=True) as c:
message = "Hallo Leute\n".encode()
ciphertext, _, sig_result = c.encrypt(message,
recipients=keys,
always_trust=True)
assert len(ciphertext) > 0
assert ciphertext.find(b'BEGIN PGP MESSAGE') > 0, 'Marker not found'
- check_result(sig_result, gpg.constants.SIG_MODE_NORMAL)
+ check_result(sig_result, gpg.constants.sig.mode.NORMAL)
c.signers = [c.get_key(support.sign_only, True)]
c.encrypt(message, recipients=keys, always_trust=True)
c.signers = [c.get_key(support.encrypt_only, True)]
try:
c.encrypt(message, recipients=keys, always_trust=True)
except gpg.errors.InvalidSigners as e:
assert len(e.signers) == 1
assert support.encrypt_only.endswith(e.signers[0].fpr)
else:
assert False, "Expected an InvalidSigners error, got none"
diff --git a/tests/t-encrypt-sym.py b/tests/t-encrypt-sym.py
index 3990556..07e6b62 100755
--- a/tests/t-encrypt-sym.py
+++ b/tests/t-encrypt-sym.py
@@ -1,85 +1,85 @@
#!/usr/bin/env python
# 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 __future__ import absolute_import, print_function, unicode_literals
del absolute_import, print_function, unicode_literals
import os
import gpg
import support
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
for passphrase in ("abc", b"abc"):
c = gpg.Context()
c.set_armor(True)
c.set_pinentry_mode(gpg.constants.PINENTRY_MODE_LOOPBACK)
source = gpg.Data("Hallo Leute\n")
cipher = gpg.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 = gpg.Context()
c.set_armor(True)
c.set_pinentry_mode(gpg.constants.PINENTRY_MODE_LOOPBACK)
c.set_passphrase_cb(passphrase_cb, None)
plain = gpg.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)
# Idiomatic interface.
for passphrase in ("abc", b"abc"):
with gpg.Context(armor=True) as c:
# Check that the passphrase callback is not altered.
def f(*args):
assert False
c.set_passphrase_cb(f)
message = "Hallo Leute\n".encode()
ciphertext, _, _ = c.encrypt(message,
passphrase=passphrase,
sign=False)
assert ciphertext.find(b'BEGIN PGP MESSAGE') > 0, 'Marker not found'
plaintext, _, _ = c.decrypt(ciphertext, passphrase=passphrase)
assert plaintext == message, 'Message body not recovered'
assert c._passphrase_cb[1] == f, "Passphrase callback not restored"
diff --git a/tests/t-encrypt.py b/tests/t-encrypt.py
index eaa454f..0c0ca35 100755
--- a/tests/t-encrypt.py
+++ b/tests/t-encrypt.py
@@ -1,64 +1,64 @@
#!/usr/bin/env python
# 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 __future__ import absolute_import, print_function, unicode_literals
del absolute_import, print_function, unicode_literals
import gpg
import support
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
c = gpg.Context()
c.set_armor(True)
source = gpg.Data("Hallo Leute\n")
sink = gpg.Data()
keys = []
keys.append(c.get_key("A0FF4590BB6122EDEF6E3C542D727CC768697734", False))
keys.append(c.get_key("D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2", False))
c.op_encrypt(keys, gpg.constants.ENCRYPT_ALWAYS_TRUST, source, sink)
result = c.op_encrypt_result()
assert not result.invalid_recipients, \
"Invalid recipients: {}".format(", ".join(r.fpr for r in result.recipients))
support.print_data(sink)
# Idiomatic interface.
with gpg.Context(armor=True) as c:
ciphertext, _, _ = c.encrypt("Hallo Leute\n".encode(),
recipients=keys,
sign=False,
always_trust=True)
assert len(ciphertext) > 0
assert ciphertext.find(b'BEGIN PGP MESSAGE') > 0, 'Marker not found'
c.encrypt("Hallo Leute\n".encode(),
recipients=[c.get_key(support.encrypt_only, False)],
sign=False, always_trust=True)
try:
c.encrypt("Hallo Leute\n".encode(),
recipients=[c.get_key(support.sign_only, False)],
sign=False, always_trust=True)
except gpg.errors.InvalidRecipients as e:
assert len(e.recipients) == 1
assert support.sign_only.endswith(e.recipients[0].fpr)
else:
assert False, "Expected an InvalidRecipients error, got none"
diff --git a/tests/t-export.py b/tests/t-export.py
index 4f67502..4927beb 100755
--- a/tests/t-export.py
+++ b/tests/t-export.py
@@ -1,40 +1,40 @@
#!/usr/bin/env python
# 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 __future__ import absolute_import, print_function, unicode_literals
del absolute_import, print_function, unicode_literals
import gpg
import support
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
c = gpg.Context()
c.set_armor(True)
sink = gpg.Data()
c.op_export_ext(['Alpha', 'Bob'], 0, sink)
support.print_data(sink)
# Again. Now using a key array.
keys = []
keys.append(c.get_key("0x68697734", False)) # Alpha
keys.append(c.get_key("0xA9E3B0B2", False)) # Bob
sink = gpg.Data()
c.op_export_keys(keys, 0, sink)
support.print_data(sink)
diff --git a/tests/t-file-name.py b/tests/t-file-name.py
index 37cd261..d12afb8 100755
--- a/tests/t-file-name.py
+++ b/tests/t-file-name.py
@@ -1,45 +1,45 @@
#!/usr/bin/env python
# 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 __future__ import absolute_import, print_function, unicode_literals
del absolute_import, print_function, unicode_literals
import os
import gpg
import support
testname = "abcde12345"
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
c = gpg.Context()
c.set_armor(True)
source = gpg.Data("Hallo Leute\n")
source.set_file_name(testname)
cipher = gpg.Data()
plain = gpg.Data()
keys = []
keys.append(c.get_key("A0FF4590BB6122EDEF6E3C542D727CC768697734", False))
c.op_encrypt(keys, gpg.constants.ENCRYPT_ALWAYS_TRUST, source, cipher)
cipher.seek(0, os.SEEK_SET)
c.op_decrypt(cipher, plain)
result = c.op_decrypt_result()
assert result.file_name == testname
diff --git a/tests/t-idiomatic.py b/tests/t-idiomatic.py
index 4df8742..485f048 100755
--- a/tests/t-idiomatic.py
+++ b/tests/t-idiomatic.py
@@ -1,84 +1,84 @@
#!/usr/bin/env python
# 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 __future__ import absolute_import, print_function, unicode_literals
del absolute_import, print_function, unicode_literals
import sys
import io
import os
import tempfile
import gpg
import support
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
# Both Context and Data can be used as context manager:
with gpg.Context() as c, gpg.Data() as d:
c.get_engine_info()
d.write(b"Halloechen")
leak_c = c
leak_d = d
assert leak_c.wrapped == None
assert leak_d.wrapped == None
def sign_and_verify(source, signed, sink):
with gpg.Context() as c:
- c.op_sign(source, signed, gpg.constants.SIG_MODE_NORMAL)
+ c.op_sign(source, signed, gpg.constants.sig.mode.NORMAL)
signed.seek(0, os.SEEK_SET)
c.op_verify(signed, None, sink)
result = c.op_verify_result()
assert len(result.signatures) == 1, "Unexpected number of signatures"
sig = result.signatures[0]
- assert sig.summary == (gpg.constants.SIGSUM_VALID |
- gpg.constants.SIGSUM_GREEN)
+ assert sig.summary == (gpg.constants.sigsum.VALID |
+ gpg.constants.sigsum.GREEN)
assert gpg.errors.GPGMEError(sig.status).getcode() == gpg.errors.NO_ERROR
sink.seek(0, os.SEEK_SET)
assert sink.read() == b"Hallo Leute\n"
# Demonstrate automatic wrapping of file-like objects with 'fileno'
# method.
with tempfile.TemporaryFile() as source, \
tempfile.TemporaryFile() as signed, \
tempfile.TemporaryFile() as sink:
source.write(b"Hallo Leute\n")
source.seek(0, os.SEEK_SET)
sign_and_verify(source, signed, sink)
if sys.version_info[0] == 3:
# Python2's io.BytesIO does not implement the buffer interface,
# hence we cannot use it as sink.
# XXX: Python's io.BytesIo.truncate does not work as advertised.
# http://bugs.python.org/issue27261
bio = io.BytesIO()
bio.truncate(1)
if len(bio.getvalue()) != 1:
# This version of Python is affected, preallocate buffer.
preallocate = 128*b'\x00'
else:
preallocate = b''
# Demonstrate automatic wrapping of objects implementing the buffer
# interface, and the use of data objects with the 'with' statement.
with io.BytesIO(preallocate) as signed, gpg.Data() as sink:
sign_and_verify(b"Hallo Leute\n", signed, sink)
diff --git a/tests/t-import.py b/tests/t-import.py
index 68ad6d7..5b0576f 100755
--- a/tests/t-import.py
+++ b/tests/t-import.py
@@ -1,79 +1,79 @@
#!/usr/bin/env python
# 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 __future__ import absolute_import, print_function, unicode_literals
del absolute_import, print_function, unicode_literals
import gpg
import support
def check_result(result, fpr, secret):
assert result.considered == 1 or (secret and result.considered == 3)
assert result.no_user_id == 0
assert not ((secret and result.imported != 0)
or (not secret and (result.imported != 0
and result.imported != 1)))
assert result.imported_rsa == 0
assert not ((secret and (result.unchanged != 0 and result.unchanged != 1))
or (not secret and ((result.imported == 0
and result.unchanged != 1)
or (result.imported == 1
and result.unchanged != 0))))
assert result.new_user_ids == 0
assert result.new_sub_keys == 0
assert not ((secret
and ((result.secret_imported == 0
and result.new_signatures != 0)
or (result.secret_imported == 1
and result.new_signatures > 1)))
or (not secret and result.new_signatures != 0))
assert result.new_revocations == 0
assert not ((secret and result.secret_read != 1 and result.secret_read != 3)
or (not secret and result.secret_read != 0))
assert not ((secret and result.secret_imported != 0
and result.secret_imported != 1
and result.secret_imported != 2)
or (not secret and result.secret_imported != 0))
assert not ((secret
and ((result.secret_imported == 0
and result.secret_unchanged != 1
and result.secret_unchanged != 2)
or (result.secret_imported == 1
and result.secret_unchanged != 0)))
or (not secret and result.secret_unchanged != 0))
assert result.not_imported == 0
if secret:
assert not (len(result.imports) in (0, 3))
else:
assert not (len(result.imports) in (0, 2))
assert fpr == result.imports[0].fpr
assert len(result.imports) == 1 or fpr == result.imports[1].fpr
assert result.imports[0].result == 0
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
c = gpg.Context()
c.op_import(gpg.Data(file=support.make_filename("pubkey-1.asc")))
result = c.op_import_result()
check_result(result, "ADAB7FCC1F4DE2616ECFA402AF82244F9CD9FD55", False)
c.op_import(gpg.Data(file=support.make_filename("seckey-1.asc")))
result = c.op_import_result()
check_result(result, "ADAB7FCC1F4DE2616ECFA402AF82244F9CD9FD55", True)
diff --git a/tests/t-keylist.py b/tests/t-keylist.py
index a725941..ea2a724 100755
--- a/tests/t-keylist.py
+++ b/tests/t-keylist.py
@@ -1,268 +1,268 @@
#!/usr/bin/env python
# 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 __future__ import absolute_import, print_function, unicode_literals
del absolute_import, print_function, unicode_literals
import gpg
import support
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
c = gpg.Context()
# Check expration of keys. This test assumes three subkeys of which
# 2 are expired; it is used with the "Whisky" test key. It has
# already been checked that these 3 subkeys are available.
def check_whisky(name, key):
sub1 = key.subkeys[2]
sub2 = key.subkeys[3]
assert sub1.expired and sub2.expired, \
"Subkey of `{}' not flagged as expired".format(name)
assert sub1.expires == 1129636886 and sub2.expires == 1129636939, \
"Subkey of `{}' has wrong expiration date".format(name)
keys = [
[ "A0FF4590BB6122EDEF6E3C542D727CC768697734", "6AE6D7EE46A871F8",
[ [ "Alfa Test", "demo key", "alfa@example.net" ],
[ "Alpha Test", "demo key", "alpha@example.net" ],
[ "Alice", "demo key", "" ] ], 1 ],
[ "D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2", "5381EA4EE29BA37F",
[ [ "Bob", "demo key", "" ],
[ "Bravo Test", "demo key", "bravo@example.net" ] ], 1 ],
[ "61EE841A2A27EB983B3B3C26413F4AF31AFDAB6C", "E71E72ACBC43DA60",
[ [ "Charlie Test", "demo key", "charlie@example.net" ] ], 1 ],
[ "6560C59C43D031C54D7C588EEBA9F240EB9DC9E6", "06F22880B0C45424",
[ [ "Delta Test", "demo key", "delta@example.net" ] ], 1 ],
[ "3531152DE293E26A07F504BC318C1FAEFAEF6D1B", "B5C79E1A7272144D",
[ [ "Echelon", "demo key", "" ],
[ "Echo Test", "demo key", "echo@example.net" ],
[ "Eve", "demo key", "" ] ], 1 ],
[ "56D33268F7FE693FBB594762D4BF57F37372E243", "0A32EE79EE45198E",
[ [ "Foxtrot Test", "demo key", "foxtrot@example.net" ] ], 1 ],
[ "C9C07DCC6621B9FB8D071B1D168410A48FC282E6", "247491CC9DCAD354",
[ [ "Golf Test", "demo key", "golf@example.net" ] ], 1 ],
[ "9E91CBB11E4D4135583EF90513DB965534C6E3F1", "76E26537D622AD0A",
[ [ "Hotel Test", "demo key", "hotel@example.net" ] ], 1 ],
[ "CD538D6CC9FB3D745ECDA5201FE8FC6F04259677", "C1C8EFDE61F76C73",
[ [ "India Test", "demo key", "india@example.net" ] ], 1 ],
[ "F8F1EDC73995AB739AD54B380C820C71D2699313", "BD0B108735F8F136",
[ [ "Juliet Test", "demo key", "juliet@example.net" ] ], 1 ],
[ "3FD11083779196C2ECDD9594AD1B0FAD43C2D0C7", "86CBB34A9AF64D02",
[ [ "Kilo Test", "demo key", "kilo@example.net" ] ], 1 ],
[ "1DDD28CEF714F5B03B8C246937CAB51FB79103F8", "0363B449FE56350C",
[ [ "Lima Test", "demo key", "lima@example.net" ] ], 1 ],
[ "2686AA191A278013992C72EBBE794852BE5CF886", "5F600A834F31EAE8",
[ [ "Mallory", "demo key", "" ],
[ "Mike Test", "demo key", "mike@example.net" ] ], 1 ],
[ "5AB9D6D7BAA1C95B3BAA3D9425B00FD430CEC684", "4C1D63308B70E472",
[ [ "November Test", "demo key", "november@example.net" ] ], 1 ],
[ "43929E89F8F79381678CAE515F6356BA6D9732AC", "FF0785712681619F",
[ [ "Oscar Test", "demo key", "oscar@example.net" ] ], 1 ],
[ "6FAA9C201E5E26DCBAEC39FD5D15E01D3FF13206", "2764E18263330D9C",
[ [ "Papa test", "demo key", "papa@example.net" ] ], 1 ],
[ "A7969DA1C3297AA96D49843F1C67EC133C661C84", "6CDCFC44A029ACF4",
[ [ "Quebec Test", "demo key", "quebec@example.net" ] ], 1 ],
[ "38FBE1E4BF6A5E1242C8F6A13BDBEDB1777FBED3", "9FAB805A11D102EA",
[ [ "Romeo Test", "demo key", "romeo@example.net" ] ], 1 ],
[ "045B2334ADD69FC221076841A5E67F7FA3AE3EA1", "93B88B0F0F1B50B4",
[ [ "Sierra Test", "demo key", "sierra@example.net" ] ], 1 ],
[ "ECAC774F4EEEB0620767044A58CB9A4C85A81F38", "97B60E01101C0402",
[ [ "Tango Test", "demo key", "tango@example.net" ] ], 1 ],
[ "0DBCAD3F08843B9557C6C4D4A94C0F75653244D6", "93079B915522BDB9",
[ [ "Uniform Test", "demo key", "uniform@example.net" ] ], 1 ],
[ "E8143C489C8D41124DC40D0B47AF4B6961F04784", "04071FB807287134",
[ [ "Victor Test", "demo key", "victor@example.org" ] ], 1 ],
[ "E8D6C90B683B0982BD557A99DEF0F7B8EC67DBDE", "D7FBB421FD6E27F6",
[ [ "Whisky Test", "demo key", "whisky@example.net" ] ], 3,
check_whisky ],
[ "04C1DF62EFA0EBB00519B06A8979A6C5567FB34A", "5CC6F87F41E408BE",
[ [ "XRay Test", "demo key", "xray@example.net" ] ], 1 ],
[ "ED9B316F78644A58D042655A9EEF34CD4B11B25F", "5ADFD255F7B080AD",
[ [ "Yankee Test", "demo key", "yankee@example.net" ] ], 1 ],
[ "23FD347A419429BACCD5E72D6BC4778054ACD246", "EF9DC276A172C881",
[ [ "Zulu Test", "demo key", "zulu@example.net" ] ], 1 ],
]
def check_global(key, uids, n_subkeys):
assert not key.revoked, "Key unexpectedly revoked"
assert not key.expired, "Key unexpectedly expired"
assert not key.disabled, "Key unexpectedly disabled"
assert not key.invalid, "Key unexpectedly invalid"
assert key.can_sign, "Key unexpectedly unusable for signing"
assert key.can_certify, "Key unexpectedly unusable for certifications"
assert not key.secret, "Key unexpectedly secret"
- assert not key.protocol != gpg.constants.PROTOCOL_OpenPGP, \
+ assert not key.protocol != gpg.constants.protocol.OpenPGP, \
"Key has unexpected protocol: {}".format(key.protocol)
assert not key.issuer_serial, \
"Key unexpectedly carries issuer serial: {}".format(key.issuer_serial)
assert not key.issuer_name, \
"Key unexpectedly carries issuer name: {}".format(key.issuer_name)
assert not key.chain_id, \
"Key unexpectedly carries chain ID: {}".format(key.chain_id)
# Only key Alfa is trusted
assert key.uids[0].name == 'Alfa Test' \
- or key.owner_trust == gpg.constants.VALIDITY_UNKNOWN, \
+ or key.owner_trust == gpg.constants.validity.UNKNOWN, \
"Key has unexpected owner trust: {}".format(key.owner_trust)
assert key.uids[0].name != 'Alfa Test' \
- or key.owner_trust == gpg.constants.VALIDITY_ULTIMATE, \
+ or key.owner_trust == gpg.constants.validity.ULTIMATE, \
"Key has unexpected owner trust: {}".format(key.owner_trust)
assert len(key.subkeys) - 1 == n_subkeys, \
"Key `{}' has unexpected number of subkeys".format(uids[0][0])
def check_subkey(fpr, which, subkey):
assert not subkey.revoked, which + " key unexpectedly revoked"
assert not subkey.expired, which + " key unexpectedly expired"
assert not subkey.disabled, which + " key unexpectedly disabled"
assert not subkey.invalid, which + " key unexpectedly invalid"
if which == "Primary":
assert not subkey.can_encrypt, \
which + " key unexpectedly usable for encryption"
assert subkey.can_sign, \
which + " key unexpectedly unusable for signing"
assert subkey.can_certify, \
which + " key unexpectedly unusable for certifications"
else:
assert subkey.can_encrypt, \
which + " key unexpectedly unusable for encryption"
assert not subkey.can_sign, \
which + " key unexpectedly usable for signing"
assert not subkey.can_certify, \
which + " key unexpectedly usable for certifications"
assert not subkey.secret, which + " key unexpectedly secret"
assert not subkey.is_cardkey, "Public key marked as card key"
assert not subkey.card_number, "Public key with card number set"
- assert not subkey.pubkey_algo != (gpg.constants.PK_DSA if which == "Primary"
- else gpg.constants.PK_ELG_E), \
+ assert not subkey.pubkey_algo != (gpg.constants.pk.DSA if which == "Primary"
+ else gpg.constants.pk.ELG_E), \
which + " key has unexpected public key algo: {}".\
format(subkey.pubkey_algo)
assert subkey.length == 1024, \
which + " key has unexpected length: {}".format(subkey.length)
assert fpr.endswith(subkey.keyid), \
which + " key has unexpected key ID: {}".format(subkey.keyid)
assert which == "Secondary" or subkey.fpr == fpr, \
which + " key has unexpected fingerprint: {}".format(subkey.fpr)
assert not subkey.expires, \
which + " key unexpectedly expires: {}".format(subkey.expires)
def check_uid(which, ref, uid):
assert not uid.revoked, which + " user ID unexpectedly revoked"
assert not uid.invalid, which + " user ID unexpectedly invalid"
- assert uid.validity == (gpg.constants.VALIDITY_UNKNOWN
+ assert uid.validity == (gpg.constants.validity.UNKNOWN
if uid.name.split()[0]
not in {'Alfa', 'Alpha', 'Alice'} else
- gpg.constants.VALIDITY_ULTIMATE), \
+ gpg.constants.validity.ULTIMATE), \
which + " user ID has unexpectedly validity: {}".format(uid.validity)
assert not uid.signatures, which + " user ID unexpectedly signed"
assert uid.name == ref[0], \
"Unexpected name in {} user ID: {!r}".format(which.lower(), uid.name)
assert uid.comment == ref[1], \
"Unexpected comment in {} user ID: {!r}".format(which.lower(),
uid.comment)
assert uid.email == ref[2], \
"Unexpected email in {} user ID: {!r}".format(which.lower(), uid.email)
i = 0
c.op_keylist_start(None, False)
key = c.op_keylist_next ()
while key:
try:
if len(keys[i]) == 4:
fpr, sec_keyid, uids, n_subkeys = keys[i]
misc_check = None
else:
fpr, sec_keyid, uids, n_subkeys, misc_check = keys[i]
except IndexError:
# There are more keys. We don't check for that.
break
# Global key flags.
check_global(key, uids, n_subkeys)
check_subkey(fpr, "Primary", key.subkeys[0])
check_subkey(sec_keyid, "Secondary", key.subkeys[1])
assert len(key.uids) == len(uids)
check_uid("First", uids[0], key.uids[0])
if len(key.uids) > 1:
check_uid("Second", uids[1], key.uids[1])
if len(key.uids) > 2:
check_uid("Third", uids[2], key.uids[2])
if misc_check:
misc_check (uids[0][0], key)
key = c.op_keylist_next ()
i += 1
c.op_keylist_end()
result = c.op_keylist_result()
assert not result.truncated, "Key listing unexpectedly truncated"
for i, key in enumerate(c.keylist()):
try:
if len(keys[i]) == 4:
fpr, sec_keyid, uids, n_subkeys = keys[i]
misc_check = None
else:
fpr, sec_keyid, uids, n_subkeys, misc_check = keys[i]
except IndexError:
# There are more keys. We don't check for that.
break
# Global key flags.
check_global(key, uids, n_subkeys)
check_subkey(fpr, "Primary", key.subkeys[0])
check_subkey(sec_keyid, "Secondary", key.subkeys[1])
assert len(key.uids) == len(uids)
check_uid("First", uids[0], key.uids[0])
if len(key.uids) > 1:
check_uid("Second", uids[1], key.uids[1])
if len(key.uids) > 2:
check_uid("Third", uids[2], key.uids[2])
if misc_check:
misc_check (uids[0][0], key)
# check get_key()
with gpg.Context() as c:
c.get_key(support.alpha)
c.get_key(support.alpha, secret=True)
c.get_key(support.bob)
try:
c.get_key(support.bob, secret=True)
except KeyError:
pass
else:
assert False, "Expected KeyError"
# Legacy error
try:
c.get_key(support.no_such_key)
except gpg.errors.GPGMEError:
pass
else:
assert False, "Expected GPGMEError"
diff --git a/tests/t-protocol-assuan.py b/tests/t-protocol-assuan.py
index ad22ae3..0084a6b 100755
--- a/tests/t-protocol-assuan.py
+++ b/tests/t-protocol-assuan.py
@@ -1,69 +1,69 @@
#!/usr/bin/env python
# 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 __future__ import absolute_import, print_function, unicode_literals
del absolute_import, print_function, unicode_literals
import gpg
-with gpg.Context(protocol=gpg.constants.PROTOCOL_ASSUAN) as c:
+with gpg.Context(protocol=gpg.constants.protocol.ASSUAN) as c:
# Do nothing.
c.assuan_transact('nop')
c.assuan_transact('NOP')
c.assuan_transact(['NOP'])
err = c.assuan_transact('idontexist')
assert err.getsource() == gpg.errors.SOURCE_GPGAGENT
assert err.getcode() == gpg.errors.ASS_UNKNOWN_CMD
# Invoke the pinentry to get a confirmation.
c.assuan_transact(['GET_CONFIRMATION', 'Hello there'])
data = []
def data_cb(line):
data.append(line)
err = c.assuan_transact(['GETINFO', 'version'], data_cb=data_cb)
assert not err
assert len(data) == 1
data = []
err = c.assuan_transact(['GETINFO', 's2k_count'], data_cb=data_cb)
if not err:
assert len(data) == 1
assert int(data[0]) > 0
# XXX HELP sends status lines if we could use ASSUAN_CONVEY_COMMENTS.
status = []
def status_cb(line, args):
status.append((line, args))
alphas_grip = '76F7E2B35832976B50A27A282D9B87E44577EB66'
err = c.assuan_transact(['KEYINFO', alphas_grip], status_cb=status_cb)
if not err:
assert len(status) == 1
line, args = status[0]
assert line.startswith('KEYINFO')
assert args.startswith(alphas_grip)
# XXX: test these callbacks, e.g. using PRESET_PASSPHRASE
# XXX: once issue2428 is resolved
def inq_cb(name, args):
print("inq_cb", name, args)
diff --git a/tests/t-sig-notation.py b/tests/t-sig-notation.py
index 050ef6b..f1342b1 100755
--- a/tests/t-sig-notation.py
+++ b/tests/t-sig-notation.py
@@ -1,80 +1,80 @@
#!/usr/bin/env python
# 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 __future__ import absolute_import, print_function, unicode_literals
del absolute_import, print_function, unicode_literals
import os
import gpg
import support
expected_notations = {
- "laughing@me": ("Just Squeeze Me", gpg.constants.SIG_NOTATION_HUMAN_READABLE),
+ "laughing@me": ("Just Squeeze Me", gpg.constants.sig.notation.HUMAN_READABLE),
"preferred-email-encoding@pgp.com": ("pgpmime",
- gpg.constants.SIG_NOTATION_HUMAN_READABLE
- | gpg.constants.SIG_NOTATION_CRITICAL),
+ gpg.constants.sig.notation.HUMAN_READABLE
+ | gpg.constants.sig.notation.CRITICAL),
None: ("http://www.gnu.org/policy/", 0),
}
# GnuPG prior to 2.1.13 did not report the critical flag correctly.
with gpg.Context() as c:
version = c.engine_info.version
have_correct_sig_data = not (version.startswith("1.")
or version.startswith("2.0.")
or version == "2.1.1"
or (version.startswith("2.1.1")
and version[5] < '3'))
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 & gpg.constants.SIG_NOTATION_HUMAN_READABLE)
+ == bool(flags & gpg.constants.sig.notation.HUMAN_READABLE)
assert r.critical \
- == (bool(flags & gpg.constants.SIG_NOTATION_CRITICAL)
+ == (bool(flags & gpg.constants.sig.notation.CRITICAL)
if have_correct_sig_data else False)
assert len(expected_notations) == 0
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
source = gpg.Data("Hallo Leute\n")
signed = gpg.Data()
c = gpg.Context()
for name, (value, flags) in expected_notations.items():
c.sig_notation_add(name, value, flags)
-c.op_sign(source, signed, gpg.constants.SIG_MODE_NORMAL)
+c.op_sign(source, signed, gpg.constants.sig.mode.NORMAL)
signed.seek(0, os.SEEK_SET)
sink = gpg.Data()
c.op_verify(signed, None, sink)
result = c.op_verify_result()
check_result(result)
diff --git a/tests/t-sign.py b/tests/t-sign.py
index c15b68c..9418ed8 100755
--- a/tests/t-sign.py
+++ b/tests/t-sign.py
@@ -1,121 +1,121 @@
#!/usr/bin/env python
# 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 __future__ import absolute_import, print_function, unicode_literals
del absolute_import, print_function, unicode_literals
import os
import gpg
import support
def fail(msg):
raise RuntimeError(msg)
def check_result(r, typ):
if r.invalid_signers:
fail("Invalid signer found: {}".format(r.invalid_signers.fpr))
if len(r.signatures) != 1:
fail("Unexpected number of signatures created")
signature = r.signatures[0]
if signature.type != typ:
fail("Wrong type of signature created")
- if signature.pubkey_algo != gpg.constants.PK_DSA:
+ if signature.pubkey_algo != gpg.constants.pk.DSA:
fail("Wrong pubkey algorithm reported: {}".format(
signature.pubkey_algo))
- if signature.hash_algo != gpg.constants.MD_SHA1:
+ if signature.hash_algo != gpg.constants.md.SHA1:
fail("Wrong hash algorithm reported: {}".format(
signature.hash_algo))
if signature.sig_class != 1:
fail("Wrong signature class reported: {}".format(
signature.sig_class))
if signature.fpr != "A0FF4590BB6122EDEF6E3C542D727CC768697734":
fail("Wrong fingerprint reported: {}".format(signature.fpr))
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
c = gpg.Context()
c.set_textmode(True)
c.set_armor(True)
source = gpg.Data("Hallo Leute\n")
sink = gpg.Data()
-c.op_sign(source, sink, gpg.constants.SIG_MODE_NORMAL)
+c.op_sign(source, sink, gpg.constants.sig.mode.NORMAL)
result = c.op_sign_result()
-check_result(result, gpg.constants.SIG_MODE_NORMAL)
+check_result(result, gpg.constants.sig.mode.NORMAL)
support.print_data(sink)
# Now a detached signature.
source.seek(0, os.SEEK_SET)
sink = gpg.Data()
-c.op_sign(source, sink, gpg.constants.SIG_MODE_DETACH)
+c.op_sign(source, sink, gpg.constants.sig.mode.DETACH)
result = c.op_sign_result()
-check_result(result, gpg.constants.SIG_MODE_DETACH)
+check_result(result, gpg.constants.sig.mode.DETACH)
support.print_data(sink)
# And finally a cleartext signature. */
source.seek(0, os.SEEK_SET)
sink = gpg.Data()
-c.op_sign(source, sink, gpg.constants.SIG_MODE_CLEAR)
+c.op_sign(source, sink, gpg.constants.sig.mode.CLEAR)
result = c.op_sign_result()
-check_result(result, gpg.constants.SIG_MODE_CLEAR)
+check_result(result, gpg.constants.sig.mode.CLEAR)
support.print_data(sink)
# Idiomatic interface.
with gpg.Context(armor=True, textmode=True) as c:
message = "Hallo Leute\n".encode()
signed, _ = c.sign(message)
assert len(signed) > 0
assert signed.find(b'BEGIN PGP MESSAGE') > 0, 'Message not found'
- signed, _ = c.sign(message, mode=gpg.constants.SIG_MODE_DETACH)
+ signed, _ = c.sign(message, mode=gpg.constants.sig.mode.DETACH)
assert len(signed) > 0
assert signed.find(b'BEGIN PGP SIGNATURE') > 0, 'Signature not found'
- signed, _ = c.sign(message, mode=gpg.constants.SIG_MODE_CLEAR)
+ signed, _ = c.sign(message, mode=gpg.constants.sig.mode.CLEAR)
assert len(signed) > 0
assert signed.find(b'BEGIN PGP SIGNED MESSAGE') > 0, 'Message not found'
assert signed.find(message) > 0, 'Message content not found'
assert signed.find(b'BEGIN PGP SIGNATURE') > 0, 'Signature not found'
with gpg.Context() as c:
message = "Hallo Leute\n".encode()
c.signers = [c.get_key(support.sign_only, True)]
c.sign(message)
c.signers = [c.get_key(support.encrypt_only, True)]
try:
c.sign(message)
except gpg.errors.InvalidSigners as e:
assert len(e.signers) == 1
assert support.encrypt_only.endswith(e.signers[0].fpr)
else:
assert False, "Expected an InvalidSigners error, got none"
diff --git a/tests/t-signers.py b/tests/t-signers.py
index 13e039b..80e797c 100755
--- a/tests/t-signers.py
+++ b/tests/t-signers.py
@@ -1,97 +1,97 @@
#!/usr/bin/env python
# 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 __future__ import absolute_import, print_function, unicode_literals
del absolute_import, print_function, unicode_literals
import gpg
import support
def fail(msg):
raise RuntimeError(msg)
def check_result(r, typ):
if r.invalid_signers:
fail("Invalid signer found: {}".format(r.invalid_signers.fpr))
if len(r.signatures) != 2:
fail("Unexpected number of signatures created")
for signature in r.signatures:
if signature.type != typ:
fail("Wrong type of signature created")
- if signature.pubkey_algo != gpg.constants.PK_DSA:
+ if signature.pubkey_algo != gpg.constants.pk.DSA:
fail("Wrong pubkey algorithm reported: {}".format(
signature.pubkey_algo))
- if signature.hash_algo != gpg.constants.MD_SHA1:
+ if signature.hash_algo != gpg.constants.md.SHA1:
fail("Wrong hash algorithm reported: {}".format(
signature.hash_algo))
if signature.sig_class != 1:
fail("Wrong signature class reported: got {}, want {}".format(
signature.sig_class, 1))
if signature.fpr not in ("A0FF4590BB6122EDEF6E3C542D727CC768697734",
"23FD347A419429BACCD5E72D6BC4778054ACD246"):
fail("Wrong fingerprint reported: {}".format(signature.fpr))
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
c = gpg.Context()
c.set_textmode(True)
c.set_armor(True)
keys = []
c.op_keylist_start('', True)
keys.append(c.op_keylist_next())
keys.append(c.op_keylist_next())
c.op_keylist_end()
c.signers_add(keys[0])
c.signers_add(keys[1])
-for mode in (gpg.constants.SIG_MODE_NORMAL, gpg.constants.SIG_MODE_DETACH,
- gpg.constants.SIG_MODE_CLEAR):
+for mode in (gpg.constants.sig.mode.NORMAL, gpg.constants.sig.mode.DETACH,
+ gpg.constants.sig.mode.CLEAR):
source = gpg.Data("Hallo Leute\n")
sink = gpg.Data()
c.op_sign(source, sink, mode)
result = c.op_sign_result()
check_result(result, mode)
support.print_data(sink)
# Idiomatic interface.
with gpg.Context(armor=True, textmode=True, signers=keys) as c:
message = "Hallo Leute\n".encode()
signed, result = c.sign(message)
- check_result(result, gpg.constants.SIG_MODE_NORMAL)
+ check_result(result, gpg.constants.sig.mode.NORMAL)
assert signed.find(b'BEGIN PGP MESSAGE') > 0, 'Message not found'
- signed, result = c.sign(message, mode=gpg.constants.SIG_MODE_DETACH)
- check_result(result, gpg.constants.SIG_MODE_DETACH)
+ signed, result = c.sign(message, mode=gpg.constants.sig.mode.DETACH)
+ check_result(result, gpg.constants.sig.mode.DETACH)
assert signed.find(b'BEGIN PGP SIGNATURE') > 0, 'Signature not found'
- signed, result = c.sign(message, mode=gpg.constants.SIG_MODE_CLEAR)
- check_result(result, gpg.constants.SIG_MODE_CLEAR)
+ signed, result = c.sign(message, mode=gpg.constants.sig.mode.CLEAR)
+ check_result(result, gpg.constants.sig.mode.CLEAR)
assert signed.find(b'BEGIN PGP SIGNED MESSAGE') > 0, 'Message not found'
assert signed.find(message) > 0, 'Message content not found'
assert signed.find(b'BEGIN PGP SIGNATURE') > 0, 'Signature not found'
diff --git a/tests/t-trustlist.py b/tests/t-trustlist.py
index 5db0954..8c5e214 100755
--- a/tests/t-trustlist.py
+++ b/tests/t-trustlist.py
@@ -1,43 +1,43 @@
#!/usr/bin/env python
# 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 __future__ import absolute_import, print_function, unicode_literals
del absolute_import, print_function, unicode_literals
import gpg
import support
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
c = gpg.Context()
def dump_item(item):
print("l={} k={} t={} o={} v={} u={}".format(
item.level, item.keyid, item.type, item.owner_trust,
item.validity, item.name))
c.op_trustlist_start("alice", 0)
while True:
item = c.op_trustlist_next()
if not item:
break
dump_item(item)
c.op_trustlist_end()
for item in c.op_trustlist_all("alice", 0):
dump_item(item)
diff --git a/tests/t-verify.py b/tests/t-verify.py
index ddfa2ce..f18e1dd 100755
--- a/tests/t-verify.py
+++ b/tests/t-verify.py
@@ -1,194 +1,194 @@
#!/usr/bin/env python
# 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 __future__ import absolute_import, print_function, unicode_literals
del absolute_import, print_function, unicode_literals
import sys
import os
import gpg
import support
test_text1 = b"Just GNU it!\n"
test_text1f= b"Just GNU it?\n"
test_sig1 = b"""-----BEGIN PGP SIGNATURE-----
iN0EABECAJ0FAjoS+i9FFIAAAAAAAwA5YmFyw7bDpMO8w58gZGFzIHdhcmVuIFVt
bGF1dGUgdW5kIGpldHp0IGVpbiBwcm96ZW50JS1aZWljaGVuNRSAAAAAAAgAJGZv
b2Jhci4xdGhpcyBpcyBhIG5vdGF0aW9uIGRhdGEgd2l0aCAyIGxpbmVzGhpodHRw
Oi8vd3d3Lmd1Lm9yZy9wb2xpY3kvAAoJEC1yfMdoaXc0JBIAoIiLlUsvpMDOyGEc
dADGKXF/Hcb+AKCJWPphZCphduxSvrzH0hgzHdeQaA==
=nts1
-----END PGP SIGNATURE-----
"""
test_sig2 = b"""-----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 = b"""-----BEGIN PGP MESSAGE-----
rDRiCmZvb2Jhci50eHRF4pxNVGhpcyBpcyBteSBzbmVha3kgcGxhaW50ZXh0IG1l
c3NhZ2UKowGbwMvMwCSoW1RzPCOz3IRxTWISa6JebnG666MFD1wzSzJSixQ81XMV
UlITUxTyixRyKxXKE0uSMxQyEosVikvyCwpSU/S4FNCArq6Ce1F+aXJGvoJvYlGF
erFCTmJxiUJ5flFKMVeHGwuDIBMDGysTyA4GLk4BmO036xgWzMgzt9V85jCtfDFn
UqVooWlGXHwNw/xg/fVzt9VNbtjtJ/fhUqYo0/LyCGEA
=6+AK
-----END PGP MESSAGE-----
"""
def check_result(result, summary, validity, fpr, status, notation):
assert len(result.signatures) == 1, "Unexpected number of signatures"
sig = result.signatures[0]
assert sig.summary == summary, \
"Unexpected signature summary: {}, want: {}".format(sig.summary,
summary)
assert sig.fpr == fpr
assert gpg.errors.GPGMEError(sig.status).getcode() == status
if notation:
expected_notations = {
"bar": (b"\xc3\xb6\xc3\xa4\xc3\xbc\xc3\x9f" +
b" das waren Umlaute und jetzt ein prozent%-Zeichen"
if sys.version_info[0] < 3 else
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 == validity, \
"Unexpected signature validity: {}, want: {}".format(
sig.validity, validity)
assert gpg.errors.GPGMEError(sig.validity_reason).getcode() == gpg.errors.NO_ERROR
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
c = gpg.Context()
c.set_armor(True)
# Checking a valid message.
text = gpg.Data(test_text1)
sig = gpg.Data(test_sig1)
c.op_verify(sig, text, None)
result = c.op_verify_result()
-check_result(result, gpg.constants.SIGSUM_VALID | gpg.constants.SIGSUM_GREEN,
- gpg.constants.VALIDITY_FULL,
+check_result(result, gpg.constants.sigsum.VALID | gpg.constants.sigsum.GREEN,
+ gpg.constants.validity.FULL,
"A0FF4590BB6122EDEF6E3C542D727CC768697734",
gpg.errors.NO_ERROR, True)
# Checking a manipulated message.
text = gpg.Data(test_text1f)
sig.seek(0, os.SEEK_SET)
c.op_verify(sig, text, None)
result = c.op_verify_result()
-check_result(result, gpg.constants.SIGSUM_RED, gpg.constants.VALIDITY_UNKNOWN,
+check_result(result, gpg.constants.sigsum.RED, gpg.constants.validity.UNKNOWN,
"2D727CC768697734", gpg.errors.BAD_SIGNATURE, False)
# Checking a normal signature.
text = gpg.Data()
sig = gpg.Data(test_sig2)
c.op_verify(sig, None, text)
result = c.op_verify_result()
-check_result(result, gpg.constants.SIGSUM_VALID | gpg.constants.SIGSUM_GREEN,
- gpg.constants.VALIDITY_FULL,
+check_result(result, gpg.constants.sigsum.VALID | gpg.constants.sigsum.GREEN,
+ gpg.constants.validity.FULL,
"A0FF4590BB6122EDEF6E3C542D727CC768697734",
gpg.errors.NO_ERROR, False)
# Checking an invalid message.
text = gpg.Data()
sig = gpg.Data(double_plaintext_sig)
try:
c.op_verify(sig, None, text)
except Exception as e:
assert type(e) == gpg.errors.GPGMEError
assert e.getcode() == gpg.errors.BAD_DATA
else:
assert False, "Expected an error but got none."
# Idiomatic interface.
with gpg.Context(armor=True) as c:
# Checking a valid message.
_, result = c.verify(test_text1, test_sig1)
- check_result(result, gpg.constants.SIGSUM_VALID | gpg.constants.SIGSUM_GREEN,
- gpg.constants.VALIDITY_FULL,
+ check_result(result, gpg.constants.sigsum.VALID | gpg.constants.sigsum.GREEN,
+ gpg.constants.validity.FULL,
"A0FF4590BB6122EDEF6E3C542D727CC768697734",
gpg.errors.NO_ERROR, True)
# Checking a manipulated message.
try:
c.verify(test_text1f, test_sig1)
except gpg.errors.BadSignatures as e:
- check_result(e.result, gpg.constants.SIGSUM_RED,
- gpg.constants.VALIDITY_UNKNOWN,
+ check_result(e.result, gpg.constants.sigsum.RED,
+ gpg.constants.validity.UNKNOWN,
"2D727CC768697734", gpg.errors.BAD_SIGNATURE, False)
else:
assert False, "Expected an error but got none."
# Checking a normal signature.
sig = gpg.Data(test_sig2)
data, result = c.verify(test_sig2)
- check_result(result, gpg.constants.SIGSUM_VALID | gpg.constants.SIGSUM_GREEN,
- gpg.constants.VALIDITY_FULL,
+ check_result(result, gpg.constants.sigsum.VALID | gpg.constants.sigsum.GREEN,
+ gpg.constants.validity.FULL,
"A0FF4590BB6122EDEF6E3C542D727CC768697734",
gpg.errors.NO_ERROR, False)
assert data == test_text1
# Checking an invalid message.
try:
c.verify(double_plaintext_sig)
except gpg.errors.GPGMEError as e:
assert e.getcode() == gpg.errors.BAD_DATA
else:
assert False, "Expected an error but got none."
alpha = c.get_key("A0FF4590BB6122EDEF6E3C542D727CC768697734", False)
bob = c.get_key("D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2", False)
# Checking a valid message.
c.verify(test_text1, test_sig1, verify=[alpha])
try:
c.verify(test_text1, test_sig1, verify=[alpha, bob])
except gpg.errors.MissingSignatures as e:
assert len(e.missing) == 1
assert e.missing[0] == bob
else:
assert False, "Expected an error, got none"
diff --git a/tests/t-wait.py b/tests/t-wait.py
index d4217b5..b1f2043 100755
--- a/tests/t-wait.py
+++ b/tests/t-wait.py
@@ -1,45 +1,45 @@
#!/usr/bin/env python
# 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 __future__ import absolute_import, print_function, unicode_literals
del absolute_import, print_function, unicode_literals
import time
import gpg
import support
-support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
+support.init_gpgme(gpg.constants.protocol.OpenPGP)
c = gpg.Context()
c.set_armor(True)
# Checking a message without a signature.
sig = gpg.Data("foo\n")
text = gpg.Data()
c.op_verify_start(sig, None, text)
try:
while True:
err = c.wait(False)
if err:
break
time.sleep(0.1)
except Exception as e:
assert e.getcode() == gpg.errors.NO_DATA
else:
assert False, "Expected an error, got none"
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Feb 26, 6:55 PM (1 d, 18 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
f5/df/2fd068e9b89dad7046a77acf8c81
Attached To
rGPGMEPY Gpgme Python bindings
Event Timeline
Log In to Comment