mirror of
https://github.com/romanz/amodem.git
synced 2026-02-07 09:28:02 +08:00
gpg: remove complex pubkey parsing code
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
"""Decoders for GPG v2 data structures."""
|
||||
import base64
|
||||
import copy
|
||||
import functools
|
||||
import hashlib
|
||||
import io
|
||||
@@ -287,28 +286,6 @@ def digest_packets(packets, hasher):
|
||||
return hasher.digest()
|
||||
|
||||
|
||||
def collect_packets(packets, types_to_collect):
|
||||
"""Collect specified packet types into their leading packet."""
|
||||
packet = None
|
||||
result = []
|
||||
for p in packets:
|
||||
if p['type'] in types_to_collect:
|
||||
packet.setdefault(p['type'], []).append(p)
|
||||
else:
|
||||
packet = copy.deepcopy(p)
|
||||
result.append(packet)
|
||||
return result
|
||||
|
||||
|
||||
def parse_public_keys(stream):
|
||||
"""Parse GPG public key into hierarchy of packets."""
|
||||
packets = list(parse_packets(stream))
|
||||
packets = collect_packets(packets, {'signature'})
|
||||
packets = collect_packets(packets, {'user_id', 'user_attribute'})
|
||||
packets = collect_packets(packets, {'subkey'})
|
||||
return packets
|
||||
|
||||
|
||||
HASH_ALGORITHMS = {
|
||||
1: 'md5',
|
||||
2: 'sha1',
|
||||
|
||||
@@ -120,5 +120,5 @@ def public_key_path(request):
|
||||
|
||||
def test_gpg_files(public_key_path): # pylint: disable=redefined-outer-name
|
||||
with open(public_key_path, 'rb') as f:
|
||||
keys = decode.parse_public_keys(f)
|
||||
assert len(keys) > 0
|
||||
packets = list(decode.parse_packets(f))
|
||||
assert len(packets) > 0
|
||||
|
||||
Reference in New Issue
Block a user