blob: 40c4ad8c2f465f0a391b09c41764bc35767ceb10 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
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)
|