python: Import the topmost module in tests and examples.
* examples/verifydetails.py: Only import the topmost module 'gpg' and update the code accordingly. * tests/support.py: Likewise. * tests/t-callbacks.py: Likewise. * tests/t-data.py: Likewise. * tests/t-decrypt-verify.py: Likewise. * tests/t-decrypt.py: Likewise. * tests/t-edit.py: Likewise. * tests/t-encrypt-large.py: Likewise. * tests/t-encrypt-sign.py: Likewise. * tests/t-encrypt-sym.py: Likewise. * tests/t-encrypt.py: Likewise. * tests/t-export.py: Likewise. * tests/t-file-name.py: Likewise. * tests/t-import.py: Likewise. * tests/t-keylist.py: Likewise. * tests/t-sig-notation.py: Likewise. * tests/t-sign.py: Likewise. * tests/t-signers.py: Likewise. * tests/t-trustlist.py: Likewise. * tests/t-verify.py: Likewise. * tests/t-wait.py: Likewise. * tests/t-wrapper.py: Likewise. Signed-off-by: Justus Winter <justus@g10code.com>
This commit is contained in:
parent
70b7064e5c
commit
20dc37a0e7
@ -21,24 +21,23 @@ from __future__ import absolute_import, print_function, unicode_literals
|
|||||||
del absolute_import, print_function, unicode_literals
|
del absolute_import, print_function, unicode_literals
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from gpg import core
|
import gpg
|
||||||
from gpg.constants import protocol
|
|
||||||
|
|
||||||
def print_engine_infos():
|
def print_engine_infos():
|
||||||
print("gpgme version:", core.check_version(None))
|
print("gpgme version:", gpg.core.check_version(None))
|
||||||
print("engines:")
|
print("engines:")
|
||||||
|
|
||||||
for engine in core.get_engine_info():
|
for engine in gpg.core.get_engine_info():
|
||||||
print(engine.file_name, engine.version)
|
print(engine.file_name, engine.version)
|
||||||
|
|
||||||
for proto in [protocol.OpenPGP, protocol.CMS]:
|
for proto in [gpg.constants.protocol.OpenPGP, gpg.constants.protocol.CMS]:
|
||||||
print("Have {}? {}".format(core.get_protocol_name(proto),
|
print("Have {}? {}".format(gpg.core.get_protocol_name(proto),
|
||||||
core.engine_check_version(proto)))
|
gpg.core.engine_check_version(proto)))
|
||||||
|
|
||||||
|
|
||||||
def verifyprintdetails(filename, detached_sig_filename=None):
|
def verifyprintdetails(filename, detached_sig_filename=None):
|
||||||
"""Verify a signature, print a lot of details."""
|
"""Verify a signature, print a lot of details."""
|
||||||
with core.Context() as c:
|
with gpg.Context() as c:
|
||||||
|
|
||||||
# Verify.
|
# Verify.
|
||||||
data, result = c.verify(open(filename),
|
data, result = c.verify(open(filename),
|
||||||
|
@ -20,7 +20,7 @@ del absolute_import, print_function, unicode_literals
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
from gpg import core
|
import gpg
|
||||||
|
|
||||||
# known keys
|
# known keys
|
||||||
alpha = "A0FF4590BB6122EDEF6E3C542D727CC768697734"
|
alpha = "A0FF4590BB6122EDEF6E3C542D727CC768697734"
|
||||||
@ -36,7 +36,7 @@ def in_srcdir(name):
|
|||||||
return os.path.join(os.environ['srcdir'], name)
|
return os.path.join(os.environ['srcdir'], name)
|
||||||
|
|
||||||
def init_gpgme(proto):
|
def init_gpgme(proto):
|
||||||
core.engine_check_version(proto)
|
gpg.core.engine_check_version(proto)
|
||||||
|
|
||||||
verbose = int(os.environ.get('verbose', 0)) > 1
|
verbose = int(os.environ.get('verbose', 0)) > 1
|
||||||
def print_data(data):
|
def print_data(data):
|
||||||
@ -66,5 +66,5 @@ def mark_key_trusted(ctx, key):
|
|||||||
else:
|
else:
|
||||||
result = None
|
result = None
|
||||||
return result
|
return result
|
||||||
with core.Data() as sink:
|
with gpg.Data() as sink:
|
||||||
ctx.op_edit(key, Editor().edit, sink, sink)
|
ctx.op_edit(key, Editor().edit, sink, sink)
|
||||||
|
@ -21,16 +21,16 @@ from __future__ import absolute_import, print_function, unicode_literals
|
|||||||
del absolute_import, print_function, unicode_literals
|
del absolute_import, print_function, unicode_literals
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from gpg import core, constants
|
import gpg
|
||||||
import support
|
import support
|
||||||
|
|
||||||
support.init_gpgme(constants.PROTOCOL_OpenPGP)
|
support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
|
||||||
|
|
||||||
c = core.Context()
|
c = gpg.Context()
|
||||||
c.set_pinentry_mode(constants.PINENTRY_MODE_LOOPBACK)
|
c.set_pinentry_mode(gpg.constants.PINENTRY_MODE_LOOPBACK)
|
||||||
|
|
||||||
source = core.Data("Hallo Leute\n")
|
source = gpg.Data("Hallo Leute\n")
|
||||||
sink = core.Data()
|
sink = gpg.Data()
|
||||||
|
|
||||||
# Valid passphrases, both as string and bytes.
|
# Valid passphrases, both as string and bytes.
|
||||||
for passphrase in ('foo', b'foo'):
|
for passphrase in ('foo', b'foo'):
|
||||||
@ -100,7 +100,7 @@ def progress_cb(what, typ, current, total, hook=None):
|
|||||||
"PROGRESS UPDATE: what = {}, type = {}, current = {}, total = {}"
|
"PROGRESS UPDATE: what = {}, type = {}, current = {}, total = {}"
|
||||||
.format(what, typ, current, total))
|
.format(what, typ, current, total))
|
||||||
|
|
||||||
c = core.Context()
|
c = gpg.Context()
|
||||||
c.set_progress_cb(progress_cb, messages)
|
c.set_progress_cb(progress_cb, messages)
|
||||||
c.op_genkey(parms, None, None)
|
c.op_genkey(parms, None, None)
|
||||||
assert len(messages) > 0
|
assert len(messages) > 0
|
||||||
@ -109,7 +109,7 @@ assert len(messages) > 0
|
|||||||
def progress_cb(what, typ, current, total, hook=None):
|
def progress_cb(what, typ, current, total, hook=None):
|
||||||
raise myException
|
raise myException
|
||||||
|
|
||||||
c = core.Context()
|
c = gpg.Context()
|
||||||
c.set_progress_cb(progress_cb, None)
|
c.set_progress_cb(progress_cb, None)
|
||||||
try:
|
try:
|
||||||
c.op_genkey(parms, None, None)
|
c.op_genkey(parms, None, None)
|
||||||
@ -120,10 +120,10 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
# Test the edit callback.
|
# Test the edit callback.
|
||||||
c = core.Context()
|
c = gpg.Context()
|
||||||
c.set_pinentry_mode(constants.PINENTRY_MODE_LOOPBACK)
|
c.set_pinentry_mode(gpg.constants.PINENTRY_MODE_LOOPBACK)
|
||||||
c.set_passphrase_cb(lambda *args: "abc")
|
c.set_passphrase_cb(lambda *args: "abc")
|
||||||
sink = core.Data()
|
sink = gpg.Data()
|
||||||
alpha = c.get_key("A0FF4590BB6122EDEF6E3C542D727CC768697734", False)
|
alpha = c.get_key("A0FF4590BB6122EDEF6E3C542D727CC768697734", False)
|
||||||
|
|
||||||
cookie = object()
|
cookie = object()
|
||||||
@ -137,10 +137,10 @@ c.op_edit(alpha, edit_cb, cookie, sink)
|
|||||||
assert edit_cb_called
|
assert edit_cb_called
|
||||||
|
|
||||||
# Test exceptions.
|
# Test exceptions.
|
||||||
c = core.Context()
|
c = gpg.Context()
|
||||||
c.set_pinentry_mode(constants.PINENTRY_MODE_LOOPBACK)
|
c.set_pinentry_mode(gpg.constants.PINENTRY_MODE_LOOPBACK)
|
||||||
c.set_passphrase_cb(lambda *args: "abc")
|
c.set_passphrase_cb(lambda *args: "abc")
|
||||||
sink = core.Data()
|
sink = gpg.Data()
|
||||||
|
|
||||||
def edit_cb(status, args):
|
def edit_cb(status, args):
|
||||||
raise myException
|
raise myException
|
||||||
@ -154,8 +154,8 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
# Test the status callback.
|
# Test the status callback.
|
||||||
source = core.Data("Hallo Leute\n")
|
source = gpg.Data("Hallo Leute\n")
|
||||||
sink = core.Data()
|
sink = gpg.Data()
|
||||||
|
|
||||||
status_cb_called = False
|
status_cb_called = False
|
||||||
def status_cb(keyword, args, hook=None):
|
def status_cb(keyword, args, hook=None):
|
||||||
@ -163,24 +163,24 @@ def status_cb(keyword, args, hook=None):
|
|||||||
status_cb_called = True
|
status_cb_called = True
|
||||||
assert hook == cookie
|
assert hook == cookie
|
||||||
|
|
||||||
c = core.Context()
|
c = gpg.Context()
|
||||||
c.set_status_cb(status_cb, cookie)
|
c.set_status_cb(status_cb, cookie)
|
||||||
c.set_ctx_flag("full-status", "1")
|
c.set_ctx_flag("full-status", "1")
|
||||||
c.op_encrypt([alpha], constants.ENCRYPT_ALWAYS_TRUST, source, sink)
|
c.op_encrypt([alpha], gpg.constants.ENCRYPT_ALWAYS_TRUST, source, sink)
|
||||||
assert status_cb_called
|
assert status_cb_called
|
||||||
|
|
||||||
# Test exceptions.
|
# Test exceptions.
|
||||||
source = core.Data("Hallo Leute\n")
|
source = gpg.Data("Hallo Leute\n")
|
||||||
sink = core.Data()
|
sink = gpg.Data()
|
||||||
|
|
||||||
def status_cb(keyword, args):
|
def status_cb(keyword, args):
|
||||||
raise myException
|
raise myException
|
||||||
|
|
||||||
c = core.Context()
|
c = gpg.Context()
|
||||||
c.set_status_cb(status_cb, None)
|
c.set_status_cb(status_cb, None)
|
||||||
c.set_ctx_flag("full-status", "1")
|
c.set_ctx_flag("full-status", "1")
|
||||||
try:
|
try:
|
||||||
c.op_encrypt([alpha], constants.ENCRYPT_ALWAYS_TRUST, source, sink)
|
c.op_encrypt([alpha], gpg.constants.ENCRYPT_ALWAYS_TRUST, source, sink)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
assert e == myException
|
assert e == myException
|
||||||
else:
|
else:
|
||||||
@ -194,7 +194,7 @@ def read_cb(amount, hook=None):
|
|||||||
return 0
|
return 0
|
||||||
def release_cb(hook=None):
|
def release_cb(hook=None):
|
||||||
assert hook == cookie
|
assert hook == cookie
|
||||||
data = core.Data(cbs=(read_cb, None, None, release_cb, cookie))
|
data = gpg.Data(cbs=(read_cb, None, None, release_cb, cookie))
|
||||||
try:
|
try:
|
||||||
data.read()
|
data.read()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -204,7 +204,7 @@ else:
|
|||||||
|
|
||||||
def read_cb(amount):
|
def read_cb(amount):
|
||||||
raise myException
|
raise myException
|
||||||
data = core.Data(cbs=(read_cb, None, None, lambda: None))
|
data = gpg.Data(cbs=(read_cb, None, None, lambda: None))
|
||||||
try:
|
try:
|
||||||
data.read()
|
data.read()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -216,7 +216,7 @@ else:
|
|||||||
def write_cb(what, hook=None):
|
def write_cb(what, hook=None):
|
||||||
assert hook == cookie
|
assert hook == cookie
|
||||||
return "wrong type"
|
return "wrong type"
|
||||||
data = core.Data(cbs=(None, write_cb, None, release_cb, cookie))
|
data = gpg.Data(cbs=(None, write_cb, None, release_cb, cookie))
|
||||||
try:
|
try:
|
||||||
data.write(b'stuff')
|
data.write(b'stuff')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -226,7 +226,7 @@ else:
|
|||||||
|
|
||||||
def write_cb(what):
|
def write_cb(what):
|
||||||
raise myException
|
raise myException
|
||||||
data = core.Data(cbs=(None, write_cb, None, lambda: None))
|
data = gpg.Data(cbs=(None, write_cb, None, lambda: None))
|
||||||
try:
|
try:
|
||||||
data.write(b'stuff')
|
data.write(b'stuff')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -238,7 +238,7 @@ else:
|
|||||||
def seek_cb(offset, whence, hook=None):
|
def seek_cb(offset, whence, hook=None):
|
||||||
assert hook == cookie
|
assert hook == cookie
|
||||||
return "wrong type"
|
return "wrong type"
|
||||||
data = core.Data(cbs=(None, None, seek_cb, release_cb, cookie))
|
data = gpg.Data(cbs=(None, None, seek_cb, release_cb, cookie))
|
||||||
try:
|
try:
|
||||||
data.seek(0, os.SEEK_SET)
|
data.seek(0, os.SEEK_SET)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -248,7 +248,7 @@ else:
|
|||||||
|
|
||||||
def seek_cb(offset, whence):
|
def seek_cb(offset, whence):
|
||||||
raise myException
|
raise myException
|
||||||
data = core.Data(cbs=(None, None, seek_cb, lambda: None))
|
data = gpg.Data(cbs=(None, None, seek_cb, lambda: None))
|
||||||
try:
|
try:
|
||||||
data.seek(0, os.SEEK_SET)
|
data.seek(0, os.SEEK_SET)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -23,9 +23,9 @@ del absolute_import, print_function, unicode_literals
|
|||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
from gpg import core
|
import gpg
|
||||||
|
|
||||||
data = core.Data('Hello world!')
|
data = gpg.Data('Hello world!')
|
||||||
assert data.read() == b'Hello world!'
|
assert data.read() == b'Hello world!'
|
||||||
assert data.read() == b''
|
assert data.read() == b''
|
||||||
|
|
||||||
@ -33,29 +33,29 @@ data.seek(0, os.SEEK_SET)
|
|||||||
assert data.read() == b'Hello world!'
|
assert data.read() == b'Hello world!'
|
||||||
assert data.read() == b''
|
assert data.read() == b''
|
||||||
|
|
||||||
data = core.Data(b'Hello world!')
|
data = gpg.Data(b'Hello world!')
|
||||||
assert data.read() == b'Hello world!'
|
assert data.read() == b'Hello world!'
|
||||||
|
|
||||||
data = core.Data(b'Hello world!', copy=False)
|
data = gpg.Data(b'Hello world!', copy=False)
|
||||||
assert data.read() == b'Hello world!'
|
assert data.read() == b'Hello world!'
|
||||||
|
|
||||||
data = core.Data()
|
data = gpg.Data()
|
||||||
data.write('Hello world!')
|
data.write('Hello world!')
|
||||||
data.seek(0, os.SEEK_SET)
|
data.seek(0, os.SEEK_SET)
|
||||||
assert data.read() == b'Hello world!'
|
assert data.read() == b'Hello world!'
|
||||||
|
|
||||||
data = core.Data()
|
data = gpg.Data()
|
||||||
data.write(b'Hello world!')
|
data.write(b'Hello world!')
|
||||||
data.seek(0, os.SEEK_SET)
|
data.seek(0, os.SEEK_SET)
|
||||||
assert data.read() == b'Hello world!'
|
assert data.read() == b'Hello world!'
|
||||||
|
|
||||||
binjunk = bytes(range(256))
|
binjunk = bytes(range(256))
|
||||||
data = core.Data()
|
data = gpg.Data()
|
||||||
data.write(binjunk)
|
data.write(binjunk)
|
||||||
data.seek(0, os.SEEK_SET)
|
data.seek(0, os.SEEK_SET)
|
||||||
assert data.read() == binjunk
|
assert data.read() == binjunk
|
||||||
|
|
||||||
data = core.Data()
|
data = gpg.Data()
|
||||||
data.set_file_name("foobar")
|
data.set_file_name("foobar")
|
||||||
assert data.get_file_name() == "foobar"
|
assert data.get_file_name() == "foobar"
|
||||||
|
|
||||||
@ -66,26 +66,26 @@ with tempfile.NamedTemporaryFile() as tmp:
|
|||||||
tmp.seek(0)
|
tmp.seek(0)
|
||||||
|
|
||||||
# Open using name.
|
# Open using name.
|
||||||
data = core.Data(file=tmp.name)
|
data = gpg.Data(file=tmp.name)
|
||||||
assert data.read() == binjunk
|
assert data.read() == binjunk
|
||||||
|
|
||||||
# Open using name, without copying.
|
# Open using name, without copying.
|
||||||
if False:
|
if False:
|
||||||
# delayed reads are not yet supported
|
# delayed reads are not yet supported
|
||||||
data = core.Data(file=tmp.name, copy=False)
|
data = gpg.Data(file=tmp.name, copy=False)
|
||||||
assert data.read() == binjunk
|
assert data.read() == binjunk
|
||||||
|
|
||||||
# Open using stream.
|
# Open using stream.
|
||||||
tmp.seek(0)
|
tmp.seek(0)
|
||||||
data = core.Data(file=tmp)
|
data = gpg.Data(file=tmp)
|
||||||
assert data.read() == binjunk
|
assert data.read() == binjunk
|
||||||
|
|
||||||
# Open using stream, offset, and length.
|
# Open using stream, offset, and length.
|
||||||
data = core.Data(file=tmp, offset=0, length=42)
|
data = gpg.Data(file=tmp, offset=0, length=42)
|
||||||
assert data.read() == binjunk[:42]
|
assert data.read() == binjunk[:42]
|
||||||
|
|
||||||
# Open using name, offset, and length.
|
# Open using name, offset, and length.
|
||||||
data = core.Data(file=tmp.name, offset=23, length=42)
|
data = gpg.Data(file=tmp.name, offset=23, length=42)
|
||||||
assert data.read() == binjunk[23:23+42]
|
assert data.read() == binjunk[23:23+42]
|
||||||
|
|
||||||
# Test callbacks.
|
# Test callbacks.
|
||||||
@ -112,7 +112,7 @@ class DataObject(object):
|
|||||||
|
|
||||||
do = DataObject()
|
do = DataObject()
|
||||||
cookie = object()
|
cookie = object()
|
||||||
data = core.Data(cbs=(do.read, do.write, do.seek, do.release, cookie))
|
data = gpg.Data(cbs=(do.read, do.write, do.seek, do.release, cookie))
|
||||||
data.write('Hello world!')
|
data.write('Hello world!')
|
||||||
data.seek(0, os.SEEK_SET)
|
data.seek(0, os.SEEK_SET)
|
||||||
assert data.read() == b'Hello world!'
|
assert data.read() == b'Hello world!'
|
||||||
@ -121,7 +121,7 @@ assert do.released
|
|||||||
|
|
||||||
# Again, without the cookie.
|
# Again, without the cookie.
|
||||||
do = DataObject()
|
do = DataObject()
|
||||||
data = core.Data(cbs=(do.read, do.write, do.seek, do.release))
|
data = gpg.Data(cbs=(do.read, do.write, do.seek, do.release))
|
||||||
data.write('Hello world!')
|
data.write('Hello world!')
|
||||||
data.seek(0, os.SEEK_SET)
|
data.seek(0, os.SEEK_SET)
|
||||||
assert data.read() == b'Hello world!'
|
assert data.read() == b'Hello world!'
|
||||||
|
@ -21,7 +21,6 @@ from __future__ import absolute_import, print_function, unicode_literals
|
|||||||
del absolute_import, print_function, unicode_literals
|
del absolute_import, print_function, unicode_literals
|
||||||
|
|
||||||
import gpg
|
import gpg
|
||||||
from gpg import core, constants, errors
|
|
||||||
import support
|
import support
|
||||||
|
|
||||||
def check_verify_result(result, summary, fpr, status):
|
def check_verify_result(result, summary, fpr, status):
|
||||||
@ -29,17 +28,17 @@ def check_verify_result(result, summary, fpr, status):
|
|||||||
sig = result.signatures[0]
|
sig = result.signatures[0]
|
||||||
assert sig.summary == summary, "Unexpected signature summary"
|
assert sig.summary == summary, "Unexpected signature summary"
|
||||||
assert sig.fpr == fpr
|
assert sig.fpr == fpr
|
||||||
assert errors.GPGMEError(sig.status).getcode() == status
|
assert gpg.errors.GPGMEError(sig.status).getcode() == status
|
||||||
assert len(sig.notations) == 0
|
assert len(sig.notations) == 0
|
||||||
assert not sig.wrong_key_usage
|
assert not sig.wrong_key_usage
|
||||||
assert sig.validity == constants.VALIDITY_FULL
|
assert sig.validity == gpg.constants.VALIDITY_FULL
|
||||||
assert errors.GPGMEError(sig.validity_reason).getcode() == errors.NO_ERROR
|
assert gpg.errors.GPGMEError(sig.validity_reason).getcode() == gpg.errors.NO_ERROR
|
||||||
|
|
||||||
support.init_gpgme(constants.PROTOCOL_OpenPGP)
|
support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
|
||||||
c = core.Context()
|
c = gpg.Context()
|
||||||
|
|
||||||
source = core.Data(file=support.make_filename("cipher-2.asc"))
|
source = gpg.Data(file=support.make_filename("cipher-2.asc"))
|
||||||
sink = core.Data()
|
sink = gpg.Data()
|
||||||
|
|
||||||
c.op_decrypt_verify(source, sink)
|
c.op_decrypt_verify(source, sink)
|
||||||
result = c.op_decrypt_result()
|
result = c.op_decrypt_result()
|
||||||
@ -50,9 +49,9 @@ support.print_data(sink)
|
|||||||
|
|
||||||
verify_result = c.op_verify_result()
|
verify_result = c.op_verify_result()
|
||||||
check_verify_result(verify_result,
|
check_verify_result(verify_result,
|
||||||
constants.SIGSUM_VALID | constants.SIGSUM_GREEN,
|
gpg.constants.SIGSUM_VALID | gpg.constants.SIGSUM_GREEN,
|
||||||
"A0FF4590BB6122EDEF6E3C542D727CC768697734",
|
"A0FF4590BB6122EDEF6E3C542D727CC768697734",
|
||||||
errors.NO_ERROR)
|
gpg.errors.NO_ERROR)
|
||||||
|
|
||||||
# Idiomatic interface.
|
# Idiomatic interface.
|
||||||
with gpg.Context() as c:
|
with gpg.Context() as c:
|
||||||
@ -63,14 +62,14 @@ with gpg.Context() as c:
|
|||||||
assert plaintext.find(b'Wenn Sie dies lesen k') >= 0, \
|
assert plaintext.find(b'Wenn Sie dies lesen k') >= 0, \
|
||||||
'Plaintext not found'
|
'Plaintext not found'
|
||||||
check_verify_result(verify_result,
|
check_verify_result(verify_result,
|
||||||
constants.SIGSUM_VALID | constants.SIGSUM_GREEN,
|
gpg.constants.SIGSUM_VALID | gpg.constants.SIGSUM_GREEN,
|
||||||
"A0FF4590BB6122EDEF6E3C542D727CC768697734",
|
"A0FF4590BB6122EDEF6E3C542D727CC768697734",
|
||||||
errors.NO_ERROR)
|
gpg.errors.NO_ERROR)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
c.decrypt(open(support.make_filename("cipher-2.asc")),
|
c.decrypt(open(support.make_filename("cipher-2.asc")),
|
||||||
verify=[alpha, bob])
|
verify=[alpha, bob])
|
||||||
except errors.MissingSignatures as e:
|
except gpg.errors.MissingSignatures as e:
|
||||||
assert len(e.missing) == 1
|
assert len(e.missing) == 1
|
||||||
assert e.missing[0] == bob
|
assert e.missing[0] == bob
|
||||||
else:
|
else:
|
||||||
|
@ -21,14 +21,13 @@ from __future__ import absolute_import, print_function, unicode_literals
|
|||||||
del absolute_import, print_function, unicode_literals
|
del absolute_import, print_function, unicode_literals
|
||||||
|
|
||||||
import gpg
|
import gpg
|
||||||
from gpg import core, constants
|
|
||||||
import support
|
import support
|
||||||
|
|
||||||
support.init_gpgme(constants.PROTOCOL_OpenPGP)
|
support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
|
||||||
c = core.Context()
|
c = gpg.Context()
|
||||||
|
|
||||||
source = core.Data(file=support.make_filename("cipher-1.asc"))
|
source = gpg.Data(file=support.make_filename("cipher-1.asc"))
|
||||||
sink = core.Data()
|
sink = gpg.Data()
|
||||||
|
|
||||||
c.op_decrypt(source, sink)
|
c.op_decrypt(source, sink)
|
||||||
result = c.op_decrypt_result()
|
result = c.op_decrypt_result()
|
||||||
|
@ -23,7 +23,7 @@ del absolute_import, print_function, unicode_literals
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
from gpg import core, constants
|
import gpg
|
||||||
import support
|
import support
|
||||||
|
|
||||||
class KeyEditor(object):
|
class KeyEditor(object):
|
||||||
@ -51,10 +51,10 @@ class KeyEditor(object):
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
support.init_gpgme(constants.PROTOCOL_OpenPGP)
|
support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
|
||||||
|
|
||||||
c = core.Context()
|
c = gpg.Context()
|
||||||
c.set_pinentry_mode(constants.PINENTRY_MODE_LOOPBACK)
|
c.set_pinentry_mode(gpg.constants.PINENTRY_MODE_LOOPBACK)
|
||||||
c.set_passphrase_cb(lambda *args: "abc")
|
c.set_passphrase_cb(lambda *args: "abc")
|
||||||
c.set_armor(True)
|
c.set_armor(True)
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ c.interact(c.get_key("A0FF4590BB6122EDEF6E3C542D727CC768697734", False),
|
|||||||
assert editor.done
|
assert editor.done
|
||||||
|
|
||||||
# The deprecated interface.
|
# The deprecated interface.
|
||||||
sink = core.Data()
|
sink = gpg.Data()
|
||||||
editor = KeyEditor()
|
editor = KeyEditor()
|
||||||
c.op_edit(c.get_key("A0FF4590BB6122EDEF6E3C542D727CC768697734", False),
|
c.op_edit(c.get_key("A0FF4590BB6122EDEF6E3C542D727CC768697734", False),
|
||||||
editor.edit_fnc, sink, sink)
|
editor.edit_fnc, sink, sink)
|
||||||
|
@ -22,7 +22,7 @@ del absolute_import, print_function, unicode_literals
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import random
|
import random
|
||||||
from gpg import core, constants
|
import gpg
|
||||||
import support
|
import support
|
||||||
|
|
||||||
if len(sys.argv) == 2:
|
if len(sys.argv) == 2:
|
||||||
@ -30,8 +30,8 @@ if len(sys.argv) == 2:
|
|||||||
else:
|
else:
|
||||||
nbytes = 100000
|
nbytes = 100000
|
||||||
|
|
||||||
support.init_gpgme(constants.PROTOCOL_OpenPGP)
|
support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
|
||||||
c = core.Context()
|
c = gpg.Context()
|
||||||
|
|
||||||
ntoread = nbytes
|
ntoread = nbytes
|
||||||
def read_cb(amount):
|
def read_cb(amount):
|
||||||
@ -48,14 +48,14 @@ def write_cb(data):
|
|||||||
nwritten += len(data)
|
nwritten += len(data)
|
||||||
return len(data)
|
return len(data)
|
||||||
|
|
||||||
source = core.Data(cbs=(read_cb, None, None, lambda: None))
|
source = gpg.Data(cbs=(read_cb, None, None, lambda: None))
|
||||||
sink = core.Data(cbs=(None, write_cb, None, lambda: None))
|
sink = gpg.Data(cbs=(None, write_cb, None, lambda: None))
|
||||||
|
|
||||||
keys = []
|
keys = []
|
||||||
keys.append(c.get_key("A0FF4590BB6122EDEF6E3C542D727CC768697734", False))
|
keys.append(c.get_key("A0FF4590BB6122EDEF6E3C542D727CC768697734", False))
|
||||||
keys.append(c.get_key("D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2", False))
|
keys.append(c.get_key("D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2", False))
|
||||||
|
|
||||||
c.op_encrypt(keys, constants.ENCRYPT_ALWAYS_TRUST, source, sink)
|
c.op_encrypt(keys, gpg.constants.ENCRYPT_ALWAYS_TRUST, source, sink)
|
||||||
result = c.op_encrypt_result()
|
result = c.op_encrypt_result()
|
||||||
assert not result.invalid_recipients, \
|
assert not result.invalid_recipients, \
|
||||||
"Invalid recipient encountered: {}".format(result.invalid_recipients.fpr)
|
"Invalid recipient encountered: {}".format(result.invalid_recipients.fpr)
|
||||||
|
@ -22,11 +22,10 @@ del absolute_import, print_function, unicode_literals
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import gpg
|
import gpg
|
||||||
from gpg import core, constants
|
|
||||||
import support
|
import support
|
||||||
|
|
||||||
support.init_gpgme(constants.PROTOCOL_OpenPGP)
|
support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
|
||||||
c = core.Context()
|
c = gpg.Context()
|
||||||
c.set_armor(True)
|
c.set_armor(True)
|
||||||
|
|
||||||
def check_result(r, typ):
|
def check_result(r, typ):
|
||||||
@ -40,11 +39,11 @@ def check_result(r, typ):
|
|||||||
if signature.type != typ:
|
if signature.type != typ:
|
||||||
sys.exit("Wrong type of signature created")
|
sys.exit("Wrong type of signature created")
|
||||||
|
|
||||||
if signature.pubkey_algo != constants.PK_DSA:
|
if signature.pubkey_algo != gpg.constants.PK_DSA:
|
||||||
sys.exit("Wrong pubkey algorithm reported: {}".format(
|
sys.exit("Wrong pubkey algorithm reported: {}".format(
|
||||||
signature.pubkey_algo))
|
signature.pubkey_algo))
|
||||||
|
|
||||||
if signature.hash_algo not in (constants.MD_SHA1, constants.MD_RMD160):
|
if signature.hash_algo not in (gpg.constants.MD_SHA1, gpg.constants.MD_RMD160):
|
||||||
sys.exit("Wrong hash algorithm reported: {}".format(
|
sys.exit("Wrong hash algorithm reported: {}".format(
|
||||||
signature.hash_algo))
|
signature.hash_algo))
|
||||||
|
|
||||||
@ -60,17 +59,17 @@ keys.append(c.get_key("A0FF4590BB6122EDEF6E3C542D727CC768697734", False))
|
|||||||
keys.append(c.get_key("D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2", False))
|
keys.append(c.get_key("D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2", False))
|
||||||
|
|
||||||
for recipients in (keys, []):
|
for recipients in (keys, []):
|
||||||
source = core.Data("Hallo Leute\n")
|
source = gpg.Data("Hallo Leute\n")
|
||||||
sink = core.Data()
|
sink = gpg.Data()
|
||||||
|
|
||||||
c.op_encrypt_sign(recipients, constants.ENCRYPT_ALWAYS_TRUST, source, sink)
|
c.op_encrypt_sign(recipients, gpg.constants.ENCRYPT_ALWAYS_TRUST, source, sink)
|
||||||
result = c.op_encrypt_result()
|
result = c.op_encrypt_result()
|
||||||
assert not result.invalid_recipients, \
|
assert not result.invalid_recipients, \
|
||||||
"Invalid recipient encountered: {}".format(
|
"Invalid recipient encountered: {}".format(
|
||||||
result.invalid_recipients.fpr)
|
result.invalid_recipients.fpr)
|
||||||
|
|
||||||
result = c.op_sign_result()
|
result = c.op_sign_result()
|
||||||
check_result(result, constants.SIG_MODE_NORMAL)
|
check_result(result, gpg.constants.SIG_MODE_NORMAL)
|
||||||
|
|
||||||
support.print_data(sink)
|
support.print_data(sink)
|
||||||
|
|
||||||
@ -83,7 +82,7 @@ with gpg.Context(armor=True) as c:
|
|||||||
always_trust=True)
|
always_trust=True)
|
||||||
assert len(ciphertext) > 0
|
assert len(ciphertext) > 0
|
||||||
assert ciphertext.find(b'BEGIN PGP MESSAGE') > 0, 'Marker not found'
|
assert ciphertext.find(b'BEGIN PGP MESSAGE') > 0, 'Marker not found'
|
||||||
check_result(sig_result, constants.SIG_MODE_NORMAL)
|
check_result(sig_result, gpg.constants.SIG_MODE_NORMAL)
|
||||||
|
|
||||||
c.signers = [c.get_key(support.sign_only, True)]
|
c.signers = [c.get_key(support.sign_only, True)]
|
||||||
c.encrypt(message, recipients=keys, always_trust=True)
|
c.encrypt(message, recipients=keys, always_trust=True)
|
||||||
|
@ -22,18 +22,17 @@ del absolute_import, print_function, unicode_literals
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import gpg
|
import gpg
|
||||||
from gpg import core, constants
|
|
||||||
import support
|
import support
|
||||||
|
|
||||||
support.init_gpgme(constants.PROTOCOL_OpenPGP)
|
support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
|
||||||
|
|
||||||
for passphrase in ("abc", b"abc"):
|
for passphrase in ("abc", b"abc"):
|
||||||
c = core.Context()
|
c = gpg.Context()
|
||||||
c.set_armor(True)
|
c.set_armor(True)
|
||||||
c.set_pinentry_mode(constants.PINENTRY_MODE_LOOPBACK)
|
c.set_pinentry_mode(gpg.constants.PINENTRY_MODE_LOOPBACK)
|
||||||
|
|
||||||
source = core.Data("Hallo Leute\n")
|
source = gpg.Data("Hallo Leute\n")
|
||||||
cipher = core.Data()
|
cipher = gpg.Data()
|
||||||
|
|
||||||
passphrase_cb_called = 0
|
passphrase_cb_called = 0
|
||||||
def passphrase_cb(hint, desc, prev_bad, hook=None):
|
def passphrase_cb(hint, desc, prev_bad, hook=None):
|
||||||
@ -48,11 +47,11 @@ for passphrase in ("abc", b"abc"):
|
|||||||
"Callback called {} times".format(passphrase_cb_called)
|
"Callback called {} times".format(passphrase_cb_called)
|
||||||
support.print_data(cipher)
|
support.print_data(cipher)
|
||||||
|
|
||||||
c = core.Context()
|
c = gpg.Context()
|
||||||
c.set_armor(True)
|
c.set_armor(True)
|
||||||
c.set_pinentry_mode(constants.PINENTRY_MODE_LOOPBACK)
|
c.set_pinentry_mode(gpg.constants.PINENTRY_MODE_LOOPBACK)
|
||||||
c.set_passphrase_cb(passphrase_cb, None)
|
c.set_passphrase_cb(passphrase_cb, None)
|
||||||
plain = core.Data()
|
plain = gpg.Data()
|
||||||
cipher.seek(0, os.SEEK_SET)
|
cipher.seek(0, os.SEEK_SET)
|
||||||
|
|
||||||
c.op_decrypt(cipher, plain)
|
c.op_decrypt(cipher, plain)
|
||||||
|
@ -21,21 +21,20 @@ from __future__ import absolute_import, print_function, unicode_literals
|
|||||||
del absolute_import, print_function, unicode_literals
|
del absolute_import, print_function, unicode_literals
|
||||||
|
|
||||||
import gpg
|
import gpg
|
||||||
from gpg import core, constants
|
|
||||||
import support
|
import support
|
||||||
|
|
||||||
support.init_gpgme(constants.PROTOCOL_OpenPGP)
|
support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
|
||||||
c = core.Context()
|
c = gpg.Context()
|
||||||
c.set_armor(True)
|
c.set_armor(True)
|
||||||
|
|
||||||
source = core.Data("Hallo Leute\n")
|
source = gpg.Data("Hallo Leute\n")
|
||||||
sink = core.Data()
|
sink = gpg.Data()
|
||||||
|
|
||||||
keys = []
|
keys = []
|
||||||
keys.append(c.get_key("A0FF4590BB6122EDEF6E3C542D727CC768697734", False))
|
keys.append(c.get_key("A0FF4590BB6122EDEF6E3C542D727CC768697734", False))
|
||||||
keys.append(c.get_key("D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2", False))
|
keys.append(c.get_key("D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2", False))
|
||||||
|
|
||||||
c.op_encrypt(keys, constants.ENCRYPT_ALWAYS_TRUST, source, sink)
|
c.op_encrypt(keys, gpg.constants.ENCRYPT_ALWAYS_TRUST, source, sink)
|
||||||
result = c.op_encrypt_result()
|
result = c.op_encrypt_result()
|
||||||
assert not result.invalid_recipients, \
|
assert not result.invalid_recipients, \
|
||||||
"Invalid recipients: {}".format(", ".join(r.fpr for r in result.recipients))
|
"Invalid recipients: {}".format(", ".join(r.fpr for r in result.recipients))
|
||||||
|
@ -20,14 +20,14 @@
|
|||||||
from __future__ import absolute_import, print_function, unicode_literals
|
from __future__ import absolute_import, print_function, unicode_literals
|
||||||
del absolute_import, print_function, unicode_literals
|
del absolute_import, print_function, unicode_literals
|
||||||
|
|
||||||
from gpg import core, constants
|
import gpg
|
||||||
import support
|
import support
|
||||||
|
|
||||||
support.init_gpgme(constants.PROTOCOL_OpenPGP)
|
support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
|
||||||
c = core.Context()
|
c = gpg.Context()
|
||||||
c.set_armor(True)
|
c.set_armor(True)
|
||||||
|
|
||||||
sink = core.Data()
|
sink = gpg.Data()
|
||||||
c.op_export_ext(['Alpha', 'Bob'], 0, sink)
|
c.op_export_ext(['Alpha', 'Bob'], 0, sink)
|
||||||
support.print_data(sink)
|
support.print_data(sink)
|
||||||
|
|
||||||
@ -35,6 +35,6 @@ support.print_data(sink)
|
|||||||
keys = []
|
keys = []
|
||||||
keys.append(c.get_key("0x68697734", False)) # Alpha
|
keys.append(c.get_key("0x68697734", False)) # Alpha
|
||||||
keys.append(c.get_key("0xA9E3B0B2", False)) # Bob
|
keys.append(c.get_key("0xA9E3B0B2", False)) # Bob
|
||||||
sink = core.Data()
|
sink = gpg.Data()
|
||||||
c.op_export_keys(keys, 0, sink)
|
c.op_export_keys(keys, 0, sink)
|
||||||
support.print_data(sink)
|
support.print_data(sink)
|
||||||
|
@ -21,24 +21,24 @@ from __future__ import absolute_import, print_function, unicode_literals
|
|||||||
del absolute_import, print_function, unicode_literals
|
del absolute_import, print_function, unicode_literals
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from gpg import core, constants
|
import gpg
|
||||||
import support
|
import support
|
||||||
|
|
||||||
testname = "abcde12345"
|
testname = "abcde12345"
|
||||||
|
|
||||||
support.init_gpgme(constants.PROTOCOL_OpenPGP)
|
support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
|
||||||
c = core.Context()
|
c = gpg.Context()
|
||||||
c.set_armor(True)
|
c.set_armor(True)
|
||||||
|
|
||||||
source = core.Data("Hallo Leute\n")
|
source = gpg.Data("Hallo Leute\n")
|
||||||
source.set_file_name(testname)
|
source.set_file_name(testname)
|
||||||
cipher = core.Data()
|
cipher = gpg.Data()
|
||||||
plain = core.Data()
|
plain = gpg.Data()
|
||||||
|
|
||||||
keys = []
|
keys = []
|
||||||
keys.append(c.get_key("A0FF4590BB6122EDEF6E3C542D727CC768697734", False))
|
keys.append(c.get_key("A0FF4590BB6122EDEF6E3C542D727CC768697734", False))
|
||||||
|
|
||||||
c.op_encrypt(keys, constants.ENCRYPT_ALWAYS_TRUST, source, cipher)
|
c.op_encrypt(keys, gpg.constants.ENCRYPT_ALWAYS_TRUST, source, cipher)
|
||||||
cipher.seek(0, os.SEEK_SET)
|
cipher.seek(0, os.SEEK_SET)
|
||||||
c.op_decrypt(cipher, plain)
|
c.op_decrypt(cipher, plain)
|
||||||
result = c.op_decrypt_result()
|
result = c.op_decrypt_result()
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
from __future__ import absolute_import, print_function, unicode_literals
|
from __future__ import absolute_import, print_function, unicode_literals
|
||||||
del absolute_import, print_function, unicode_literals
|
del absolute_import, print_function, unicode_literals
|
||||||
|
|
||||||
from gpg import core, constants
|
import gpg
|
||||||
import support
|
import support
|
||||||
|
|
||||||
def check_result(result, fpr, secret):
|
def check_result(result, fpr, secret):
|
||||||
@ -67,13 +67,13 @@ def check_result(result, fpr, secret):
|
|||||||
assert len(result.imports) == 1 or fpr == result.imports[1].fpr
|
assert len(result.imports) == 1 or fpr == result.imports[1].fpr
|
||||||
assert result.imports[0].result == 0
|
assert result.imports[0].result == 0
|
||||||
|
|
||||||
support.init_gpgme(constants.PROTOCOL_OpenPGP)
|
support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
|
||||||
c = core.Context()
|
c = gpg.Context()
|
||||||
|
|
||||||
c.op_import(core.Data(file=support.make_filename("pubkey-1.asc")))
|
c.op_import(gpg.Data(file=support.make_filename("pubkey-1.asc")))
|
||||||
result = c.op_import_result()
|
result = c.op_import_result()
|
||||||
check_result(result, "ADAB7FCC1F4DE2616ECFA402AF82244F9CD9FD55", False)
|
check_result(result, "ADAB7FCC1F4DE2616ECFA402AF82244F9CD9FD55", False)
|
||||||
|
|
||||||
c.op_import(core.Data(file=support.make_filename("seckey-1.asc")))
|
c.op_import(gpg.Data(file=support.make_filename("seckey-1.asc")))
|
||||||
result = c.op_import_result()
|
result = c.op_import_result()
|
||||||
check_result(result, "ADAB7FCC1F4DE2616ECFA402AF82244F9CD9FD55", True)
|
check_result(result, "ADAB7FCC1F4DE2616ECFA402AF82244F9CD9FD55", True)
|
||||||
|
@ -21,11 +21,10 @@ from __future__ import absolute_import, print_function, unicode_literals
|
|||||||
del absolute_import, print_function, unicode_literals
|
del absolute_import, print_function, unicode_literals
|
||||||
|
|
||||||
import gpg
|
import gpg
|
||||||
from gpg import core, constants
|
|
||||||
import support
|
import support
|
||||||
|
|
||||||
support.init_gpgme(constants.PROTOCOL_OpenPGP)
|
support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
|
||||||
c = core.Context()
|
c = gpg.Context()
|
||||||
|
|
||||||
# Check expration of keys. This test assumes three subkeys of which
|
# Check expration of keys. This test assumes three subkeys of which
|
||||||
# 2 are expired; it is used with the "Whisky" test key. It has
|
# 2 are expired; it is used with the "Whisky" test key. It has
|
||||||
@ -109,7 +108,7 @@ def check_global(key, uids, n_subkeys):
|
|||||||
assert key.can_sign, "Key unexpectedly unusable for signing"
|
assert key.can_sign, "Key unexpectedly unusable for signing"
|
||||||
assert key.can_certify, "Key unexpectedly unusable for certifications"
|
assert key.can_certify, "Key unexpectedly unusable for certifications"
|
||||||
assert not key.secret, "Key unexpectedly secret"
|
assert not key.secret, "Key unexpectedly secret"
|
||||||
assert not key.protocol != constants.PROTOCOL_OpenPGP, \
|
assert not key.protocol != gpg.constants.PROTOCOL_OpenPGP, \
|
||||||
"Key has unexpected protocol: {}".format(key.protocol)
|
"Key has unexpected protocol: {}".format(key.protocol)
|
||||||
assert not key.issuer_serial, \
|
assert not key.issuer_serial, \
|
||||||
"Key unexpectedly carries issuer serial: {}".format(key.issuer_serial)
|
"Key unexpectedly carries issuer serial: {}".format(key.issuer_serial)
|
||||||
@ -120,10 +119,10 @@ def check_global(key, uids, n_subkeys):
|
|||||||
|
|
||||||
# Only key Alfa is trusted
|
# Only key Alfa is trusted
|
||||||
assert key.uids[0].name == 'Alfa Test' \
|
assert key.uids[0].name == 'Alfa Test' \
|
||||||
or key.owner_trust == constants.VALIDITY_UNKNOWN, \
|
or key.owner_trust == gpg.constants.VALIDITY_UNKNOWN, \
|
||||||
"Key has unexpected owner trust: {}".format(key.owner_trust)
|
"Key has unexpected owner trust: {}".format(key.owner_trust)
|
||||||
assert key.uids[0].name != 'Alfa Test' \
|
assert key.uids[0].name != 'Alfa Test' \
|
||||||
or key.owner_trust == constants.VALIDITY_ULTIMATE, \
|
or key.owner_trust == gpg.constants.VALIDITY_ULTIMATE, \
|
||||||
"Key has unexpected owner trust: {}".format(key.owner_trust)
|
"Key has unexpected owner trust: {}".format(key.owner_trust)
|
||||||
|
|
||||||
assert len(key.subkeys) - 1 == n_subkeys, \
|
assert len(key.subkeys) - 1 == n_subkeys, \
|
||||||
@ -154,8 +153,8 @@ def check_subkey(fpr, which, subkey):
|
|||||||
assert not subkey.secret, which + " key unexpectedly secret"
|
assert not subkey.secret, which + " key unexpectedly secret"
|
||||||
assert not subkey.is_cardkey, "Public key marked as card key"
|
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.card_number, "Public key with card number set"
|
||||||
assert not subkey.pubkey_algo != (constants.PK_DSA if which == "Primary"
|
assert not subkey.pubkey_algo != (gpg.constants.PK_DSA if which == "Primary"
|
||||||
else constants.PK_ELG_E), \
|
else gpg.constants.PK_ELG_E), \
|
||||||
which + " key has unexpected public key algo: {}".\
|
which + " key has unexpected public key algo: {}".\
|
||||||
format(subkey.pubkey_algo)
|
format(subkey.pubkey_algo)
|
||||||
assert subkey.length == 1024, \
|
assert subkey.length == 1024, \
|
||||||
@ -170,10 +169,10 @@ def check_subkey(fpr, which, subkey):
|
|||||||
def check_uid(which, ref, uid):
|
def check_uid(which, ref, uid):
|
||||||
assert not uid.revoked, which + " user ID unexpectedly revoked"
|
assert not uid.revoked, which + " user ID unexpectedly revoked"
|
||||||
assert not uid.invalid, which + " user ID unexpectedly invalid"
|
assert not uid.invalid, which + " user ID unexpectedly invalid"
|
||||||
assert uid.validity == (constants.VALIDITY_UNKNOWN
|
assert uid.validity == (gpg.constants.VALIDITY_UNKNOWN
|
||||||
if uid.name.split()[0]
|
if uid.name.split()[0]
|
||||||
not in {'Alfa', 'Alpha', 'Alice'} else
|
not in {'Alfa', 'Alpha', 'Alice'} else
|
||||||
constants.VALIDITY_ULTIMATE), \
|
gpg.constants.VALIDITY_ULTIMATE), \
|
||||||
which + " user ID has unexpectedly validity: {}".format(uid.validity)
|
which + " user ID has unexpectedly validity: {}".format(uid.validity)
|
||||||
assert not uid.signatures, which + " user ID unexpectedly signed"
|
assert not uid.signatures, which + " user ID unexpectedly signed"
|
||||||
assert uid.name == ref[0], \
|
assert uid.name == ref[0], \
|
||||||
|
@ -21,19 +21,19 @@ from __future__ import absolute_import, print_function, unicode_literals
|
|||||||
del absolute_import, print_function, unicode_literals
|
del absolute_import, print_function, unicode_literals
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from gpg import core, constants
|
import gpg
|
||||||
import support
|
import support
|
||||||
|
|
||||||
expected_notations = {
|
expected_notations = {
|
||||||
"laughing@me": ("Just Squeeze Me", constants.SIG_NOTATION_HUMAN_READABLE),
|
"laughing@me": ("Just Squeeze Me", gpg.constants.SIG_NOTATION_HUMAN_READABLE),
|
||||||
"preferred-email-encoding@pgp.com": ("pgpmime",
|
"preferred-email-encoding@pgp.com": ("pgpmime",
|
||||||
constants.SIG_NOTATION_HUMAN_READABLE
|
gpg.constants.SIG_NOTATION_HUMAN_READABLE
|
||||||
| constants.SIG_NOTATION_CRITICAL),
|
| gpg.constants.SIG_NOTATION_CRITICAL),
|
||||||
None: ("http://www.gnu.org/policy/", 0),
|
None: ("http://www.gnu.org/policy/", 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
# GnuPG prior to 2.1.13 did not report the critical flag correctly.
|
# GnuPG prior to 2.1.13 did not report the critical flag correctly.
|
||||||
with core.Context() as c:
|
with gpg.Context() as c:
|
||||||
version = c.engine_info.version
|
version = c.engine_info.version
|
||||||
have_correct_sig_data = not (version.startswith("1.")
|
have_correct_sig_data = not (version.startswith("1.")
|
||||||
or version.startswith("2.0.")
|
or version.startswith("2.0.")
|
||||||
@ -55,26 +55,26 @@ def check_result(result):
|
|||||||
assert r.value == value, \
|
assert r.value == value, \
|
||||||
"Expected {!r}, got {!r}".format(value, r.value)
|
"Expected {!r}, got {!r}".format(value, r.value)
|
||||||
assert r.human_readable \
|
assert r.human_readable \
|
||||||
== bool(flags&constants.SIG_NOTATION_HUMAN_READABLE)
|
== bool(flags & gpg.constants.SIG_NOTATION_HUMAN_READABLE)
|
||||||
assert r.critical \
|
assert r.critical \
|
||||||
== (bool(flags&constants.SIG_NOTATION_CRITICAL)
|
== (bool(flags & gpg.constants.SIG_NOTATION_CRITICAL)
|
||||||
if have_correct_sig_data else False)
|
if have_correct_sig_data else False)
|
||||||
|
|
||||||
assert len(expected_notations) == 0
|
assert len(expected_notations) == 0
|
||||||
|
|
||||||
support.init_gpgme(constants.PROTOCOL_OpenPGP)
|
support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
|
||||||
|
|
||||||
source = core.Data("Hallo Leute\n")
|
source = gpg.Data("Hallo Leute\n")
|
||||||
signed = core.Data()
|
signed = gpg.Data()
|
||||||
|
|
||||||
c = core.Context()
|
c = gpg.Context()
|
||||||
for name, (value, flags) in expected_notations.items():
|
for name, (value, flags) in expected_notations.items():
|
||||||
c.sig_notation_add(name, value, flags)
|
c.sig_notation_add(name, value, flags)
|
||||||
|
|
||||||
c.op_sign(source, signed, constants.SIG_MODE_NORMAL)
|
c.op_sign(source, signed, gpg.constants.SIG_MODE_NORMAL)
|
||||||
|
|
||||||
signed.seek(0, os.SEEK_SET)
|
signed.seek(0, os.SEEK_SET)
|
||||||
sink = core.Data()
|
sink = gpg.Data()
|
||||||
c.op_verify(signed, None, sink)
|
c.op_verify(signed, None, sink)
|
||||||
result = c.op_verify_result()
|
result = c.op_verify_result()
|
||||||
check_result(result)
|
check_result(result)
|
||||||
|
@ -22,7 +22,6 @@ del absolute_import, print_function, unicode_literals
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import gpg
|
import gpg
|
||||||
from gpg import core, constants
|
|
||||||
import support
|
import support
|
||||||
|
|
||||||
def fail(msg):
|
def fail(msg):
|
||||||
@ -39,11 +38,11 @@ def check_result(r, typ):
|
|||||||
if signature.type != typ:
|
if signature.type != typ:
|
||||||
fail("Wrong type of signature created")
|
fail("Wrong type of signature created")
|
||||||
|
|
||||||
if signature.pubkey_algo != constants.PK_DSA:
|
if signature.pubkey_algo != gpg.constants.PK_DSA:
|
||||||
fail("Wrong pubkey algorithm reported: {}".format(
|
fail("Wrong pubkey algorithm reported: {}".format(
|
||||||
signature.pubkey_algo))
|
signature.pubkey_algo))
|
||||||
|
|
||||||
if signature.hash_algo != constants.MD_SHA1:
|
if signature.hash_algo != gpg.constants.MD_SHA1:
|
||||||
fail("Wrong hash algorithm reported: {}".format(
|
fail("Wrong hash algorithm reported: {}".format(
|
||||||
signature.hash_algo))
|
signature.hash_algo))
|
||||||
|
|
||||||
@ -55,38 +54,38 @@ def check_result(r, typ):
|
|||||||
fail("Wrong fingerprint reported: {}".format(signature.fpr))
|
fail("Wrong fingerprint reported: {}".format(signature.fpr))
|
||||||
|
|
||||||
|
|
||||||
support.init_gpgme(constants.PROTOCOL_OpenPGP)
|
support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
|
||||||
c = core.Context()
|
c = gpg.Context()
|
||||||
c.set_textmode(True)
|
c.set_textmode(True)
|
||||||
c.set_armor(True)
|
c.set_armor(True)
|
||||||
|
|
||||||
source = core.Data("Hallo Leute\n")
|
source = gpg.Data("Hallo Leute\n")
|
||||||
sink = core.Data()
|
sink = gpg.Data()
|
||||||
|
|
||||||
c.op_sign(source, sink, constants.SIG_MODE_NORMAL)
|
c.op_sign(source, sink, gpg.constants.SIG_MODE_NORMAL)
|
||||||
|
|
||||||
result = c.op_sign_result()
|
result = c.op_sign_result()
|
||||||
check_result(result, constants.SIG_MODE_NORMAL)
|
check_result(result, gpg.constants.SIG_MODE_NORMAL)
|
||||||
support.print_data(sink)
|
support.print_data(sink)
|
||||||
|
|
||||||
# Now a detached signature.
|
# Now a detached signature.
|
||||||
source.seek(0, os.SEEK_SET)
|
source.seek(0, os.SEEK_SET)
|
||||||
sink = core.Data()
|
sink = gpg.Data()
|
||||||
|
|
||||||
c.op_sign(source, sink, constants.SIG_MODE_DETACH)
|
c.op_sign(source, sink, gpg.constants.SIG_MODE_DETACH)
|
||||||
|
|
||||||
result = c.op_sign_result()
|
result = c.op_sign_result()
|
||||||
check_result(result, constants.SIG_MODE_DETACH)
|
check_result(result, gpg.constants.SIG_MODE_DETACH)
|
||||||
support.print_data(sink)
|
support.print_data(sink)
|
||||||
|
|
||||||
# And finally a cleartext signature. */
|
# And finally a cleartext signature. */
|
||||||
source.seek(0, os.SEEK_SET)
|
source.seek(0, os.SEEK_SET)
|
||||||
sink = core.Data()
|
sink = gpg.Data()
|
||||||
|
|
||||||
c.op_sign(source, sink, constants.SIG_MODE_CLEAR)
|
c.op_sign(source, sink, gpg.constants.SIG_MODE_CLEAR)
|
||||||
|
|
||||||
result = c.op_sign_result()
|
result = c.op_sign_result()
|
||||||
check_result(result, constants.SIG_MODE_CLEAR)
|
check_result(result, gpg.constants.SIG_MODE_CLEAR)
|
||||||
support.print_data(sink)
|
support.print_data(sink)
|
||||||
|
|
||||||
# Idiomatic interface.
|
# Idiomatic interface.
|
||||||
|
@ -21,7 +21,6 @@ from __future__ import absolute_import, print_function, unicode_literals
|
|||||||
del absolute_import, print_function, unicode_literals
|
del absolute_import, print_function, unicode_literals
|
||||||
|
|
||||||
import gpg
|
import gpg
|
||||||
from gpg import core, constants
|
|
||||||
import support
|
import support
|
||||||
|
|
||||||
def fail(msg):
|
def fail(msg):
|
||||||
@ -38,11 +37,11 @@ def check_result(r, typ):
|
|||||||
if signature.type != typ:
|
if signature.type != typ:
|
||||||
fail("Wrong type of signature created")
|
fail("Wrong type of signature created")
|
||||||
|
|
||||||
if signature.pubkey_algo != constants.PK_DSA:
|
if signature.pubkey_algo != gpg.constants.PK_DSA:
|
||||||
fail("Wrong pubkey algorithm reported: {}".format(
|
fail("Wrong pubkey algorithm reported: {}".format(
|
||||||
signature.pubkey_algo))
|
signature.pubkey_algo))
|
||||||
|
|
||||||
if signature.hash_algo != constants.MD_SHA1:
|
if signature.hash_algo != gpg.constants.MD_SHA1:
|
||||||
fail("Wrong hash algorithm reported: {}".format(
|
fail("Wrong hash algorithm reported: {}".format(
|
||||||
signature.hash_algo))
|
signature.hash_algo))
|
||||||
|
|
||||||
@ -55,8 +54,8 @@ def check_result(r, typ):
|
|||||||
fail("Wrong fingerprint reported: {}".format(signature.fpr))
|
fail("Wrong fingerprint reported: {}".format(signature.fpr))
|
||||||
|
|
||||||
|
|
||||||
support.init_gpgme(constants.PROTOCOL_OpenPGP)
|
support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
|
||||||
c = core.Context()
|
c = gpg.Context()
|
||||||
c.set_textmode(True)
|
c.set_textmode(True)
|
||||||
c.set_armor(True)
|
c.set_armor(True)
|
||||||
|
|
||||||
@ -69,10 +68,10 @@ c.op_keylist_end()
|
|||||||
c.signers_add(keys[0])
|
c.signers_add(keys[0])
|
||||||
c.signers_add(keys[1])
|
c.signers_add(keys[1])
|
||||||
|
|
||||||
for mode in (constants.SIG_MODE_NORMAL, constants.SIG_MODE_DETACH,
|
for mode in (gpg.constants.SIG_MODE_NORMAL, gpg.constants.SIG_MODE_DETACH,
|
||||||
constants.SIG_MODE_CLEAR):
|
gpg.constants.SIG_MODE_CLEAR):
|
||||||
source = core.Data("Hallo Leute\n")
|
source = gpg.Data("Hallo Leute\n")
|
||||||
sink = core.Data()
|
sink = gpg.Data()
|
||||||
|
|
||||||
c.op_sign(source, sink, mode)
|
c.op_sign(source, sink, mode)
|
||||||
|
|
||||||
@ -84,15 +83,15 @@ for mode in (constants.SIG_MODE_NORMAL, constants.SIG_MODE_DETACH,
|
|||||||
with gpg.Context(armor=True, textmode=True, signers=keys) as c:
|
with gpg.Context(armor=True, textmode=True, signers=keys) as c:
|
||||||
message = "Hallo Leute\n".encode()
|
message = "Hallo Leute\n".encode()
|
||||||
signed, result = c.sign(message)
|
signed, result = c.sign(message)
|
||||||
check_result(result, constants.SIG_MODE_NORMAL)
|
check_result(result, gpg.constants.SIG_MODE_NORMAL)
|
||||||
assert signed.find(b'BEGIN PGP MESSAGE') > 0, 'Message not found'
|
assert signed.find(b'BEGIN PGP MESSAGE') > 0, 'Message not found'
|
||||||
|
|
||||||
signed, result = c.sign(message, mode=constants.SIG_MODE_DETACH)
|
signed, result = c.sign(message, mode=gpg.constants.SIG_MODE_DETACH)
|
||||||
check_result(result, constants.SIG_MODE_DETACH)
|
check_result(result, gpg.constants.SIG_MODE_DETACH)
|
||||||
assert signed.find(b'BEGIN PGP SIGNATURE') > 0, 'Signature not found'
|
assert signed.find(b'BEGIN PGP SIGNATURE') > 0, 'Signature not found'
|
||||||
|
|
||||||
signed, result = c.sign(message, mode=constants.SIG_MODE_CLEAR)
|
signed, result = c.sign(message, mode=gpg.constants.SIG_MODE_CLEAR)
|
||||||
check_result(result, 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(b'BEGIN PGP SIGNED MESSAGE') > 0, 'Message not found'
|
||||||
assert signed.find(message) > 0, 'Message content not found'
|
assert signed.find(message) > 0, 'Message content not found'
|
||||||
assert signed.find(b'BEGIN PGP SIGNATURE') > 0, 'Signature not found'
|
assert signed.find(b'BEGIN PGP SIGNATURE') > 0, 'Signature not found'
|
||||||
|
@ -20,11 +20,11 @@
|
|||||||
from __future__ import absolute_import, print_function, unicode_literals
|
from __future__ import absolute_import, print_function, unicode_literals
|
||||||
del absolute_import, print_function, unicode_literals
|
del absolute_import, print_function, unicode_literals
|
||||||
|
|
||||||
from gpg import core, constants
|
import gpg
|
||||||
import support
|
import support
|
||||||
|
|
||||||
support.init_gpgme(constants.PROTOCOL_OpenPGP)
|
support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
|
||||||
c = core.Context()
|
c = gpg.Context()
|
||||||
|
|
||||||
def dump_item(item):
|
def dump_item(item):
|
||||||
print("l={} k={} t={} o={} v={} u={}".format(
|
print("l={} k={} t={} o={} v={} u={}".format(
|
||||||
|
@ -23,7 +23,6 @@ del absolute_import, print_function, unicode_literals
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import gpg
|
import gpg
|
||||||
from gpg import core, constants, errors
|
|
||||||
import support
|
import support
|
||||||
|
|
||||||
test_text1 = b"Just GNU it!\n"
|
test_text1 = b"Just GNU it!\n"
|
||||||
@ -67,7 +66,7 @@ def check_result(result, summary, validity, fpr, status, notation):
|
|||||||
"Unexpected signature summary: {}, want: {}".format(sig.summary,
|
"Unexpected signature summary: {}, want: {}".format(sig.summary,
|
||||||
summary)
|
summary)
|
||||||
assert sig.fpr == fpr
|
assert sig.fpr == fpr
|
||||||
assert errors.GPGMEError(sig.status).getcode() == status
|
assert gpg.errors.GPGMEError(sig.status).getcode() == status
|
||||||
|
|
||||||
if notation:
|
if notation:
|
||||||
expected_notations = {
|
expected_notations = {
|
||||||
@ -96,50 +95,50 @@ def check_result(result, summary, validity, fpr, status, notation):
|
|||||||
assert sig.validity == validity, \
|
assert sig.validity == validity, \
|
||||||
"Unexpected signature validity: {}, want: {}".format(
|
"Unexpected signature validity: {}, want: {}".format(
|
||||||
sig.validity, validity)
|
sig.validity, validity)
|
||||||
assert errors.GPGMEError(sig.validity_reason).getcode() == errors.NO_ERROR
|
assert gpg.errors.GPGMEError(sig.validity_reason).getcode() == gpg.errors.NO_ERROR
|
||||||
|
|
||||||
|
|
||||||
support.init_gpgme(constants.PROTOCOL_OpenPGP)
|
support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
|
||||||
c = core.Context()
|
c = gpg.Context()
|
||||||
c.set_armor(True)
|
c.set_armor(True)
|
||||||
|
|
||||||
# Checking a valid message.
|
# Checking a valid message.
|
||||||
text = core.Data(test_text1)
|
text = gpg.Data(test_text1)
|
||||||
sig = core.Data(test_sig1)
|
sig = gpg.Data(test_sig1)
|
||||||
c.op_verify(sig, text, None)
|
c.op_verify(sig, text, None)
|
||||||
result = c.op_verify_result()
|
result = c.op_verify_result()
|
||||||
check_result(result, constants.SIGSUM_VALID | constants.SIGSUM_GREEN,
|
check_result(result, gpg.constants.SIGSUM_VALID | gpg.constants.SIGSUM_GREEN,
|
||||||
constants.VALIDITY_FULL,
|
gpg.constants.VALIDITY_FULL,
|
||||||
"A0FF4590BB6122EDEF6E3C542D727CC768697734",
|
"A0FF4590BB6122EDEF6E3C542D727CC768697734",
|
||||||
errors.NO_ERROR, True)
|
gpg.errors.NO_ERROR, True)
|
||||||
|
|
||||||
|
|
||||||
# Checking a manipulated message.
|
# Checking a manipulated message.
|
||||||
text = core.Data(test_text1f)
|
text = gpg.Data(test_text1f)
|
||||||
sig.seek(0, os.SEEK_SET)
|
sig.seek(0, os.SEEK_SET)
|
||||||
c.op_verify(sig, text, None)
|
c.op_verify(sig, text, None)
|
||||||
result = c.op_verify_result()
|
result = c.op_verify_result()
|
||||||
check_result(result, constants.SIGSUM_RED, constants.VALIDITY_UNKNOWN,
|
check_result(result, gpg.constants.SIGSUM_RED, gpg.constants.VALIDITY_UNKNOWN,
|
||||||
"2D727CC768697734", errors.BAD_SIGNATURE, False)
|
"2D727CC768697734", gpg.errors.BAD_SIGNATURE, False)
|
||||||
|
|
||||||
# Checking a normal signature.
|
# Checking a normal signature.
|
||||||
text = core.Data()
|
text = gpg.Data()
|
||||||
sig = core.Data(test_sig2)
|
sig = gpg.Data(test_sig2)
|
||||||
c.op_verify(sig, None, text)
|
c.op_verify(sig, None, text)
|
||||||
result = c.op_verify_result()
|
result = c.op_verify_result()
|
||||||
check_result(result, constants.SIGSUM_VALID | constants.SIGSUM_GREEN,
|
check_result(result, gpg.constants.SIGSUM_VALID | gpg.constants.SIGSUM_GREEN,
|
||||||
constants.VALIDITY_FULL,
|
gpg.constants.VALIDITY_FULL,
|
||||||
"A0FF4590BB6122EDEF6E3C542D727CC768697734",
|
"A0FF4590BB6122EDEF6E3C542D727CC768697734",
|
||||||
errors.NO_ERROR, False)
|
gpg.errors.NO_ERROR, False)
|
||||||
|
|
||||||
# Checking an invalid message.
|
# Checking an invalid message.
|
||||||
text = core.Data()
|
text = gpg.Data()
|
||||||
sig = core.Data(double_plaintext_sig)
|
sig = gpg.Data(double_plaintext_sig)
|
||||||
try:
|
try:
|
||||||
c.op_verify(sig, None, text)
|
c.op_verify(sig, None, text)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
assert type(e) == errors.GPGMEError
|
assert type(e) == gpg.errors.GPGMEError
|
||||||
assert e.getcode() == errors.BAD_DATA
|
assert e.getcode() == gpg.errors.BAD_DATA
|
||||||
else:
|
else:
|
||||||
assert False, "Expected an error but got none."
|
assert False, "Expected an error but got none."
|
||||||
|
|
||||||
@ -148,35 +147,35 @@ else:
|
|||||||
with gpg.Context(armor=True) as c:
|
with gpg.Context(armor=True) as c:
|
||||||
# Checking a valid message.
|
# Checking a valid message.
|
||||||
_, result = c.verify(test_text1, test_sig1)
|
_, result = c.verify(test_text1, test_sig1)
|
||||||
check_result(result, constants.SIGSUM_VALID | constants.SIGSUM_GREEN,
|
check_result(result, gpg.constants.SIGSUM_VALID | gpg.constants.SIGSUM_GREEN,
|
||||||
constants.VALIDITY_FULL,
|
gpg.constants.VALIDITY_FULL,
|
||||||
"A0FF4590BB6122EDEF6E3C542D727CC768697734",
|
"A0FF4590BB6122EDEF6E3C542D727CC768697734",
|
||||||
errors.NO_ERROR, True)
|
gpg.errors.NO_ERROR, True)
|
||||||
|
|
||||||
# Checking a manipulated message.
|
# Checking a manipulated message.
|
||||||
try:
|
try:
|
||||||
c.verify(test_text1f, test_sig1)
|
c.verify(test_text1f, test_sig1)
|
||||||
except errors.BadSignatures as e:
|
except gpg.errors.BadSignatures as e:
|
||||||
check_result(e.result, constants.SIGSUM_RED,
|
check_result(e.result, gpg.constants.SIGSUM_RED,
|
||||||
constants.VALIDITY_UNKNOWN,
|
gpg.constants.VALIDITY_UNKNOWN,
|
||||||
"2D727CC768697734", errors.BAD_SIGNATURE, False)
|
"2D727CC768697734", gpg.errors.BAD_SIGNATURE, False)
|
||||||
else:
|
else:
|
||||||
assert False, "Expected an error but got none."
|
assert False, "Expected an error but got none."
|
||||||
|
|
||||||
# Checking a normal signature.
|
# Checking a normal signature.
|
||||||
sig = core.Data(test_sig2)
|
sig = gpg.Data(test_sig2)
|
||||||
data, result = c.verify(test_sig2)
|
data, result = c.verify(test_sig2)
|
||||||
check_result(result, constants.SIGSUM_VALID | constants.SIGSUM_GREEN,
|
check_result(result, gpg.constants.SIGSUM_VALID | gpg.constants.SIGSUM_GREEN,
|
||||||
constants.VALIDITY_FULL,
|
gpg.constants.VALIDITY_FULL,
|
||||||
"A0FF4590BB6122EDEF6E3C542D727CC768697734",
|
"A0FF4590BB6122EDEF6E3C542D727CC768697734",
|
||||||
errors.NO_ERROR, False)
|
gpg.errors.NO_ERROR, False)
|
||||||
assert data == test_text1
|
assert data == test_text1
|
||||||
|
|
||||||
# Checking an invalid message.
|
# Checking an invalid message.
|
||||||
try:
|
try:
|
||||||
c.verify(double_plaintext_sig)
|
c.verify(double_plaintext_sig)
|
||||||
except errors.GPGMEError as e:
|
except gpg.errors.GPGMEError as e:
|
||||||
assert e.getcode() == errors.BAD_DATA
|
assert e.getcode() == gpg.errors.BAD_DATA
|
||||||
else:
|
else:
|
||||||
assert False, "Expected an error but got none."
|
assert False, "Expected an error but got none."
|
||||||
|
|
||||||
@ -188,7 +187,7 @@ with gpg.Context(armor=True) as c:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
c.verify(test_text1, test_sig1, verify=[alpha, bob])
|
c.verify(test_text1, test_sig1, verify=[alpha, bob])
|
||||||
except errors.MissingSignatures as e:
|
except gpg.errors.MissingSignatures as e:
|
||||||
assert len(e.missing) == 1
|
assert len(e.missing) == 1
|
||||||
assert e.missing[0] == bob
|
assert e.missing[0] == bob
|
||||||
else:
|
else:
|
||||||
|
@ -21,16 +21,16 @@ from __future__ import absolute_import, print_function, unicode_literals
|
|||||||
del absolute_import, print_function, unicode_literals
|
del absolute_import, print_function, unicode_literals
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from gpg import core, constants, errors
|
import gpg
|
||||||
import support
|
import support
|
||||||
|
|
||||||
support.init_gpgme(constants.PROTOCOL_OpenPGP)
|
support.init_gpgme(gpg.constants.PROTOCOL_OpenPGP)
|
||||||
c = core.Context()
|
c = gpg.Context()
|
||||||
c.set_armor(True)
|
c.set_armor(True)
|
||||||
|
|
||||||
# Checking a message without a signature.
|
# Checking a message without a signature.
|
||||||
sig = core.Data("foo\n")
|
sig = gpg.Data("foo\n")
|
||||||
text = core.Data()
|
text = gpg.Data()
|
||||||
c.op_verify_start(sig, None, text)
|
c.op_verify_start(sig, None, text)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -40,6 +40,6 @@ try:
|
|||||||
break
|
break
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
assert e.getcode() == errors.NO_DATA
|
assert e.getcode() == gpg.errors.NO_DATA
|
||||||
else:
|
else:
|
||||||
assert False, "Expected an error, got none"
|
assert False, "Expected an error, got none"
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public
|
# 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/>.
|
# License along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from gpg import core
|
import gpg
|
||||||
|
|
||||||
d0 = core.Data()
|
d0 = gpg.Data()
|
||||||
d0.seek # trigger on-demand-wrapping
|
d0.seek # trigger on-demand-wrapping
|
||||||
assert d0.seek == d0.seek, "Generated wrapper functions are not cached"
|
assert d0.seek == d0.seek, "Generated wrapper functions are not cached"
|
||||||
assert hasattr(core.Data, 'seek'), "Generated wrapper functions are not shared"
|
assert hasattr(gpg.Data, 'seek'), "Generated wrapper functions are not shared"
|
||||||
|
Loading…
Reference in New Issue
Block a user