1from sequoia.openpgp import KeyID 2 3binary = b"\x24\x7F\x6D\xAB\xC8\x49\x14\xFE" 4hexy = "247F6DABC84914FE" 5pretty = "247F 6DAB C849 14FE" 6 7def test_from_bytes(): 8 k = KeyID.from_bytes(binary) 9 assert str(k) == pretty 10 assert k.hex() == hexy 11 12def test_from_hex(): 13 k = KeyID.from_hex(hexy) 14 assert str(k) == pretty 15 assert k.hex() == hexy 16 17fp_hexy = "7DCA58B54EB143169DDEE15F247F6DABC84914FE" 18fp_pretty = "7DCA 58B5 4EB1 4316 9DDE E15F 247F 6DAB C849 14FE" 19def test_from_hexy_fp(): 20 k = KeyID.from_bytes(binary) 21 assert k == KeyID.from_hex(fp_hexy) 22 assert k == KeyID.from_hex(fp_pretty) 23 24def test_malformed(): 25 try: 26 KeyID.from_bytes(b"too few") 27 except: 28 pass 29 else: 30 raise "Expected exception" 31 32 try: 33 KeyID.from_bytes(b"way too many") 34 except: 35 pass 36 else: 37 raise "Expected exception" 38 39 try: 40 KeyID.from_hex(b"not hex chars") 41 except: 42 pass 43 else: 44 raise "Expected exception" 45 46def test_equals(): 47 a = KeyID.from_hex(hexy) 48 b = KeyID.from_hex(hexy) 49 assert a == b 50 51def test_clone(): 52 a = KeyID.from_hex(hexy) 53 b = a.copy() 54 del a 55 c = b.copy() 56 del b 57 assert c.hex() == hexy 58 59def test_hash(): 60 a = KeyID.from_hex(hexy) 61 b = KeyID.from_hex(hexy) 62 assert hash(a) == hash(b) 63 64