1from sequoia.openpgp import Fingerprint
2
3binary = b"\x7D\xCA\x58\xB5\x4E\xB1\x43\x16\x9D\xDE\xE1\x5F\x24\x7F\x6D\xAB\xC8\x49\x14\xFE"
4hexy   = "7DCA58B54EB143169DDEE15F247F6DABC84914FE"
5pretty = "7DCA 58B5 4EB1 4316 9DDE  E15F 247F 6DAB C849 14FE"
6
7def test_from_bytes():
8    f = Fingerprint.from_bytes(binary)
9    assert str(f) == pretty
10    assert f.hex() == hexy
11
12def test_from_hex():
13    f = Fingerprint.from_hex(hexy)
14    assert str(f) == pretty
15    assert f.hex() == hexy
16
17def test_to_keyid():
18    f = Fingerprint.from_hex(hexy)
19    assert f.keyid().hex() == "247F6DABC84914FE"
20
21def test_bad_hex():
22    try:
23        f = Fingerprint.from_hex("bad hex")
24    except:
25        pass
26    else:
27        raise "Expected exception"
28
29def test_equals():
30    a = Fingerprint.from_hex(hexy)
31    b = Fingerprint.from_hex(hexy)
32    assert a == b
33
34def test_clone():
35    a = Fingerprint.from_hex(hexy)
36    b = a.copy()
37    del a
38    c = b.copy()
39    del b
40    assert c.hex() == hexy
41
42def test_hash():
43    a = Fingerprint.from_hex(hexy)
44    b = Fingerprint.from_hex(hexy)
45    assert hash(a) == hash(b)
46