feature(keyringctl): verify file structure integrity and packets

This moves all verify code to an own module and adds support to check
all packet files in the structure for integrity. This is done by parsing
assumptions like packet kind, type, issuer and location etc.
This commit is contained in:
Levente Polyak
2021-11-07 21:54:34 +01:00
parent d9e9453d84
commit e55042e45b
6 changed files with 328 additions and 54 deletions

View File

@ -11,6 +11,7 @@ from typing import List
from typing import Optional
from .types import Fingerprint
from .types import PacketKind
from .types import Uid
from .types import Username
from .util import cwd
@ -208,6 +209,26 @@ def packet_signature_creation_time(packet: Path) -> datetime:
return datetime.strptime(packet_dump_field(packet, "Signature creation time"), "%Y-%m-%d %H:%M:%S %Z")
def packet_kinds(packet: Path) -> List[PacketKind]:
"""Retrieve the PGP packet types of a packet path
Parameters
----------
packet: The path to the PGP packet to retrieve the kind of
Returns
-------
The kind of PGP packet
"""
dump = packet_dump(packet)
lines = [line for line in dump.splitlines()]
lines = list(
filter(lambda line: not line.startswith(" ") and not line.startswith("WARNING") and line.strip(), lines)
)
return [PacketKind(line.split()[0]) for line in lines]
def latest_certification(certifications: Iterable[Path]) -> Path:
"""Returns the latest certification based on the signature creation time from a list of packets.