chore(keyringctl): add missing type annotations for tests
This commit is contained in:
@ -32,6 +32,7 @@ from .types import Fingerprint
|
||||
from .types import Trust
|
||||
from .types import Uid
|
||||
from .types import Username
|
||||
from .util import filter_fingerprints_by_trust
|
||||
from .util import get_cert_paths
|
||||
from .util import system
|
||||
from .util import transform_fd_to_tmpfile
|
||||
@ -605,12 +606,7 @@ def export_ownertrust(certs: List[Path], output: Path) -> List[Fingerprint]:
|
||||
"""
|
||||
|
||||
main_trusts = certificate_trust_from_paths(sources=certs, main_keys=get_fingerprints_from_paths(sources=certs))
|
||||
trusted_certs: List[Fingerprint] = list(
|
||||
map(
|
||||
lambda item: item[0],
|
||||
filter(lambda item: Trust.full == item[1], main_trusts.items()),
|
||||
)
|
||||
)
|
||||
trusted_certs: List[Fingerprint] = filter_fingerprints_by_trust(main_trusts, Trust.full)
|
||||
|
||||
with open(file=output, mode="w") as trusted_certs_file:
|
||||
for cert in sorted(set(trusted_certs)):
|
||||
@ -636,12 +632,7 @@ def export_revoked(certs: List[Path], main_keys: Set[Fingerprint], output: Path)
|
||||
"""
|
||||
|
||||
certificate_trusts = certificate_trust_from_paths(sources=certs, main_keys=main_keys)
|
||||
revoked_certs: List[Fingerprint] = list(
|
||||
map(
|
||||
lambda item: item[0],
|
||||
filter(lambda item: Trust.revoked == item[1], certificate_trusts.items()),
|
||||
)
|
||||
)
|
||||
revoked_certs: List[Fingerprint] = filter_fingerprints_by_trust(certificate_trusts, Trust.revoked)
|
||||
|
||||
with open(file=output, mode="w") as revoked_certs_file:
|
||||
for cert in sorted(set(revoked_certs)):
|
||||
|
@ -16,12 +16,14 @@ from tempfile import mkstemp
|
||||
from traceback import print_stack
|
||||
from typing import IO
|
||||
from typing import AnyStr
|
||||
from typing import Dict
|
||||
from typing import List
|
||||
from typing import Optional
|
||||
from typing import Set
|
||||
from typing import Union
|
||||
|
||||
from libkeyringctl.types import Fingerprint
|
||||
from libkeyringctl.types import Trust
|
||||
|
||||
|
||||
@contextmanager
|
||||
@ -198,4 +200,37 @@ def get_parent_cert_paths(paths: Iterable[Path]) -> Set[Path]:
|
||||
|
||||
|
||||
def contains_fingerprint(fingerprints: Iterable[Fingerprint], fingerprint: Fingerprint) -> bool:
|
||||
"""Returns weather an iterable structure of fingerprints contains a specific fingerprint
|
||||
|
||||
Parameters
|
||||
----------
|
||||
fingerprints: Iteratable structure of fingerprints that should be searched
|
||||
fingerprint: Fingerprint to search for
|
||||
|
||||
Returns
|
||||
-------
|
||||
Weather an iterable structure of fingerprints contains a specific fingerprint
|
||||
"""
|
||||
|
||||
return any(filter(lambda e: str(e).endswith(fingerprint), fingerprints))
|
||||
|
||||
|
||||
def filter_fingerprints_by_trust(trusts: Dict[Fingerprint, Trust], trust: Trust) -> List[Fingerprint]:
|
||||
"""Filters a dict of Fingerprint to Trust by a passed Trust parameter and returns the matching fingerprints.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
trusts: Dict of Fingerprint to Trust that should be filtered based on the trust parameter
|
||||
trust: Trust that should be used to filter the trusts dict
|
||||
|
||||
Returns
|
||||
-------
|
||||
The matching fingerprints of the dict filtered by trust
|
||||
"""
|
||||
|
||||
return list(
|
||||
map(
|
||||
lambda item: item[0],
|
||||
filter(lambda item: trust == item[1], trusts.items()),
|
||||
)
|
||||
)
|
||||
|
Reference in New Issue
Block a user