diff options
Diffstat (limited to 'ffi/lang/python/tests')
-rw-r--r-- | ffi/lang/python/tests/test_armor.py | 69 | ||||
-rw-r--r-- | ffi/lang/python/tests/test_cert.py | 67 | ||||
-rw-r--r-- | ffi/lang/python/tests/test_fingerprint.py | 45 | ||||
-rw-r--r-- | ffi/lang/python/tests/test_keyid.py | 63 | ||||
-rw-r--r-- | ffi/lang/python/tests/test_keyserver.py | 10 | ||||
-rw-r--r-- | ffi/lang/python/tests/test_packet_parser.py | 52 |
6 files changed, 0 insertions, 306 deletions
diff --git a/ffi/lang/python/tests/test_armor.py b/ffi/lang/python/tests/test_armor.py deleted file mode 100644 index 2d1815f6..00000000 --- a/ffi/lang/python/tests/test_armor.py +++ /dev/null @@ -1,69 +0,0 @@ -import os -from os.path import join -from tempfile import TemporaryDirectory - -from sequoia.core import Context, Reader, Writer -from sequoia.openpgp import ArmorReader, ArmorWriter, Kind - -TEST_VECTORS = [0, 1, 2, 3, 47, 48, 49, 50, 51] - -ctx = Context(ephemeral=True) - -def fn_bin(t): - return "../../../openpgp/tests/data/armor/test-{}.bin".format(t) - -def fn_asc(t): - return "../../../openpgp/tests/data/armor/test-{}.asc".format(t) - -def test_dearmor_file(): - for t in TEST_VECTORS: - bin = open(fn_bin(t), "rb").read() - ar = ArmorReader.new(ctx, Reader.open(ctx, fn_asc(t))) - assert(bin == ar.read()) - -def test_dearmor_fd(): - for t in TEST_VECTORS: - bin = open(fn_bin(t), "rb").read() - fd = os.open(fn_asc(t), os.O_RDONLY) - ar = ArmorReader.new(ctx, Reader.from_fd(ctx, fd)) - assert(bin == ar.read()) - -def test_dearmor_bytes(): - for t in TEST_VECTORS: - bin = open(fn_bin(t), "rb").read() - asc = open(fn_asc(t), "rb").read() - ar = ArmorReader.new(ctx, Reader.from_bytes(ctx, asc)) - assert(bin == ar.read()) - -def test_enarmor_file(): - for t in TEST_VECTORS: - with TemporaryDirectory() as tmp: - bin = open(fn_bin(t), "rb").read() - sink = join(tmp, "a") - ar = ArmorWriter.new(ctx, Writer.open(ctx, sink), Kind.File) - ar.write(bin) - ar.close() - - assert(open(fn_asc(t)).read() == open(sink).read()) - -def test_enarmor_fd(): - for t in TEST_VECTORS: - with TemporaryDirectory() as tmp: - bin = open(fn_bin(t), "rb").read() - sink = join(tmp, "a") - fd = os.open(sink, os.O_WRONLY|os.O_CREAT) - ar = ArmorWriter.new(ctx, Writer.from_fd(ctx, fd), Kind.File) - ar.write(bin) - ar.close() - - assert(open(fn_asc(t)).read() == open(sink).read()) - -def test_enarmor_bytes(): - for t in TEST_VECTORS: - bin = open(fn_bin(t), "rb").read() - sink = bytearray(141) - ar = ArmorWriter.new(ctx, Writer.from_bytes(ctx, sink), Kind.File) - ar.write(bin) - ar.close() - - assert(sink.startswith(open(fn_asc(t), "rb").read())) diff --git a/ffi/lang/python/tests/test_cert.py b/ffi/lang/python/tests/test_cert.py deleted file mode 100644 index 98222529..00000000 --- a/ffi/lang/python/tests/test_cert.py +++ /dev/null @@ -1,67 +0,0 @@ -from os.path import join -from tempfile import TemporaryDirectory - -from sequoia.core import Context, Reader, Writer -from sequoia.openpgp import ArmorReader, Fingerprint, Cert, PacketPile - -pgp = "../../../openpgp/tests/data/keys/testy.pgp" -asc = "../../../openpgp/tests/data/keys/testy.asc" -fp = Fingerprint.from_hex("3E8877C877274692975189F5D03F6F865226FE8B") - -def test_from_reader(): - ctx = Context(ephemeral=True) - r = Reader.open(ctx, pgp) - t = Cert.from_reader(ctx, r) - assert t.fingerprint() == fp - -def test_from_armor_reader(): - ctx = Context(ephemeral=True) - k = open(asc, "rb").read() - r = Reader.from_bytes(ctx, k) - r = ArmorReader.new(ctx, r) - t = Cert.from_reader(ctx, r) - assert t.fingerprint() == fp - -def test_from_file(): - ctx = Context(ephemeral=True) - t = Cert.open(ctx, pgp) - assert t.fingerprint() == fp - -def test_from_packet_pile(): - ctx = Context(ephemeral=True) - r = PacketPile.open(ctx, pgp) - t = Cert.from_packet_pile(ctx, r) - assert t.fingerprint() == fp - -def test_from_bytes(): - ctx = Context(ephemeral=True) - t = Cert.from_bytes(ctx, open(pgp, "rb").read()) - assert t.fingerprint() == fp - -def test_from_serialize(): - ctx = Context(ephemeral=True) - with TemporaryDirectory() as tmp: - sink = join(tmp, "a") - - t = Cert.open(ctx, pgp) - with Writer.open(ctx, sink) as s: - t.serialize(s) - - t = Cert.open(ctx, sink) - assert t.fingerprint() == fp - -def test_equals(): - ctx = Context(ephemeral=True) - b = open(pgp, "rb").read() - t = Cert.from_bytes(ctx, b) - u = Cert.from_bytes(ctx, b) - assert t == u - -def test_clone(): - ctx = Context(ephemeral=True) - a = Cert.open(ctx, pgp) - b = a.copy() - del a - c = b.copy() - del b - assert c.fingerprint() == fp diff --git a/ffi/lang/python/tests/test_fingerprint.py b/ffi/lang/python/tests/test_fingerprint.py deleted file mode 100644 index 85a505d0..00000000 --- a/ffi/lang/python/tests/test_fingerprint.py +++ /dev/null @@ -1,45 +0,0 @@ -from sequoia.openpgp import Fingerprint - -binary = b"\x7D\xCA\x58\xB5\x4E\xB1\x43\x16\x9D\xDE\xE1\x5F\x24\x7F\x6D\xAB\xC8\x49\x14\xFE" -hexy = "7DCA58B54EB143169DDEE15F247F6DABC84914FE" -pretty = "7DCA 58B5 4EB1 4316 9DDE E15F 247F 6DAB C849 14FE" - -def test_from_bytes(): - f = Fingerprint.from_bytes(binary) - assert str(f) == hexy - assert f.hex() == hexy - -def test_from_hex(): - f = Fingerprint.from_hex(hexy) - assert str(f) == hexy - assert f.hex() == hexy - -def test_to_keyid(): - f = Fingerprint.from_hex(hexy) - assert f.keyid().hex() == "247F6DABC84914FE" - -def test_bad_hex(): - try: - f = Fingerprint.from_hex("bad hex") - except: - pass - else: - raise "Expected exception" - -def test_equals(): - a = Fingerprint.from_hex(hexy) - b = Fingerprint.from_hex(hexy) - assert a == b - -def test_clone(): - a = Fingerprint.from_hex(hexy) - b = a.copy() - del a - c = b.copy() - del b - assert c.hex() == hexy - -def test_hash(): - a = Fingerprint.from_hex(hexy) - b = Fingerprint.from_hex(hexy) - assert hash(a) == hash(b) diff --git a/ffi/lang/python/tests/test_keyid.py b/ffi/lang/python/tests/test_keyid.py deleted file mode 100644 index 40c4ad8c..00000000 --- a/ffi/lang/python/tests/test_keyid.py +++ /dev/null @@ -1,63 +0,0 @@ -from sequoia.openpgp import KeyID - -binary = b"\x24\x7F\x6D\xAB\xC8\x49\x14\xFE" -hexy = "247F6DABC84914FE" -pretty = "247F 6DAB C849 14FE" - -def test_from_bytes(): - k = KeyID.from_bytes(binary) - assert str(k) == hexy - assert k.hex() == hexy - -def test_from_hex(): - k = KeyID.from_hex(hexy) - assert str(k) == hexy - assert k.hex() == hexy - -fp_hexy = "7DCA58B54EB143169DDEE15F247F6DABC84914FE" -fp_pretty = "7DCA 58B5 4EB1 4316 9DDE E15F 247F 6DAB C849 14FE" -def test_from_hexy_fp(): - k = KeyID.from_bytes(binary) - assert k == KeyID.from_hex(fp_hexy) - assert k == KeyID.from_hex(fp_pretty) - -def test_malformed(): - try: - KeyID.from_bytes(b"too few") - except: - pass - else: - raise "Expected exception" - - try: - KeyID.from_bytes(b"way too many") - except: - pass - else: - raise "Expected exception" - - try: - KeyID.from_hex(b"not hex chars") - except: - pass - else: - raise "Expected exception" - -def test_equals(): - a = KeyID.from_hex(hexy) - b = KeyID.from_hex(hexy) - assert a == b - -def test_clone(): - a = KeyID.from_hex(hexy) - b = a.copy() - del a - c = b.copy() - del b - assert c.hex() == hexy - -def test_hash(): - a = KeyID.from_hex(hexy) - b = KeyID.from_hex(hexy) - assert hash(a) == hash(b) - diff --git a/ffi/lang/python/tests/test_keyserver.py b/ffi/lang/python/tests/test_keyserver.py deleted file mode 100644 index 30d237fa..00000000 --- a/ffi/lang/python/tests/test_keyserver.py +++ /dev/null @@ -1,10 +0,0 @@ -from sequoia.prelude import Context -from sequoia.net import KeyServer - -def test_keys_openpgp_org(): - c = Context(ephemeral=True) - KeyServer.keys_openpgp_org(c) - -def test_new(): - c = Context(ephemeral=True) - KeyServer.new(c, "hkps://keys.domain.example") diff --git a/ffi/lang/python/tests/test_packet_parser.py b/ffi/lang/python/tests/test_packet_parser.py deleted file mode 100644 index abb0ab24..00000000 --- a/ffi/lang/python/tests/test_packet_parser.py +++ /dev/null @@ -1,52 +0,0 @@ -from enum import Enum -from sequoia.core import Context -from sequoia.openpgp import Tag, PacketParser - -pgp = "../../../openpgp/tests/data/messages/encrypted-aes128-password-123456789.gpg" -plain = "../../../openpgp/tests/data/messages/a-cypherpunks-manifesto.txt" - -def test_decryption(): - ctx = Context(ephemeral=True) - - class State(Enum): - # XXX: In Python 3.6, we can use enum.auto() to assign values. - # But we want to support Debian 9, which uses Python 3.5, as - # long as it is Debian stable. - Start = 1 - Decrypted = 2 - Deciphered = 3 - Done = 4 - - state = State.Start - algo, key = None, None - ppr = PacketParser.open(ctx, pgp) - while True: - pp = ppr.packet_parser() - if not pp: - break - - packet = pp.packet - tag = packet.tag - print(state, pp.recursion_depth, packet) - - if state == State.Start: - assert pp.recursion_depth == 0 - if tag == Tag.SKESK: - algo, key = packet.match().decrypt(b"123456789") - state = State.Decrypted - elif state == State.Decrypted: - assert pp.recursion_depth == 0 - if tag == Tag.SEIP: - pp.decrypt(algo, key) - state = State.Deciphered - elif state == State.Deciphered: - assert pp.recursion_depth == 1 - if tag == Tag.Literal: - body = pp.buffer_unread_content() - assert body[:].decode() == open(plain).read() - state = State.Done - - _, ppr = pp.recurse() - - assert ppr.eof().is_message() - assert state == State.Done |