diff options
| author | J08nY | 2023-04-18 13:59:18 +0200 |
|---|---|---|
| committer | J08nY | 2023-04-18 13:59:18 +0200 |
| commit | eaa2f2d32a176c4f0183ada8a271a200f911171e (patch) | |
| tree | e9ac3d9e9be5f5953ecb85b346086311b77e6704 /src/sec_certs/model | |
| parent | 9a43fe5488f681935353b610e2c814407e91799e (diff) | |
| download | sec-certs-eaa2f2d32a176c4f0183ada8a271a200f911171e.tar.gz sec-certs-eaa2f2d32a176c4f0183ada8a271a200f911171e.tar.zst sec-certs-eaa2f2d32a176c4f0183ada8a271a200f911171e.zip | |
Make CCSchemeDataset an actual dataset.
Diffstat (limited to 'src/sec_certs/model')
| -rw-r--r-- | src/sec_certs/model/cc_matching.py | 8 | ||||
| -rw-r--r-- | src/sec_certs/model/fips_matching.py | 7 | ||||
| -rw-r--r-- | src/sec_certs/model/matching.py | 6 |
3 files changed, 12 insertions, 9 deletions
diff --git a/src/sec_certs/model/cc_matching.py b/src/sec_certs/model/cc_matching.py index fdb16d70..3cc38a40 100644 --- a/src/sec_certs/model/cc_matching.py +++ b/src/sec_certs/model/cc_matching.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Any, Iterable, Mapping +from typing import Any, Iterable, Mapping, Sequence from sec_certs.configuration import config from sec_certs.model.matching import AbstractMatcher @@ -79,7 +79,7 @@ class CCSchemeMatcher(AbstractMatcher[CCCertificate]): @classmethod def match_all( cls, entries: list[dict[str, Any]], scheme: str, certificates: Iterable[CCCertificate] - ) -> dict[str, Mapping]: + ) -> dict[str, dict[str, Any]]: """ Match all entries of a given CC scheme to certificates from the dataset. @@ -89,5 +89,5 @@ class CCSchemeMatcher(AbstractMatcher[CCCertificate]): :return: A mapping of certificate digests to entries, without duplicates, not all entries may be present. """ certs: list[CCCertificate] = list(filter(lambda cert: cert.scheme == scheme, certificates)) - matchers = [CCSchemeMatcher(entry, scheme) for entry in entries] - return cls._match_certs(matchers, certs, config.cc_matching_threshold) + matchers: Sequence[CCSchemeMatcher] = [CCSchemeMatcher(entry, scheme) for entry in entries] + return cls._match_certs(matchers, certs, config.cc_matching_threshold) # type: ignore diff --git a/src/sec_certs/model/fips_matching.py b/src/sec_certs/model/fips_matching.py index 8cf3cb9c..53d75c61 100644 --- a/src/sec_certs/model/fips_matching.py +++ b/src/sec_certs/model/fips_matching.py @@ -1,7 +1,7 @@ from __future__ import annotations import typing -from typing import Iterable, Mapping +from typing import Iterable, Mapping, Sequence from sec_certs.configuration import config from sec_certs.model.matching import AbstractMatcher @@ -60,5 +60,6 @@ class FIPSProcessMatcher(AbstractMatcher[FIPSCertificate]): :return: A mapping of certificate digests to entries, without duplicates, not all entries may be present. """ certs: list[FIPSCertificate] = list(certificates) - matchers = [FIPSProcessMatcher(entry) for entry in snapshot] - return cls._match_certs(matchers, certs, config.fips_matching_threshold) + matchers: Sequence[FIPSProcessMatcher] = [FIPSProcessMatcher(entry) for entry in snapshot] + # mypy is ridiculous + return cls._match_certs(matchers, certs, config.fips_matching_threshold) # type: ignore diff --git a/src/sec_certs/model/matching.py b/src/sec_certs/model/matching.py index 6d49f34f..fc71b2ad 100644 --- a/src/sec_certs/model/matching.py +++ b/src/sec_certs/model/matching.py @@ -1,7 +1,7 @@ import typing from abc import ABC, abstractmethod from heapq import heappop, heappush -from typing import Generic +from typing import Any, Generic, Sequence from rapidfuzz import fuzz @@ -11,6 +11,8 @@ CertSubType = typing.TypeVar("CertSubType", bound=Certificate) class AbstractMatcher(Generic[CertSubType], ABC): + entry: Any + @abstractmethod def match(self, cert: CertSubType) -> float: raise NotImplementedError @@ -25,7 +27,7 @@ class AbstractMatcher(Generic[CertSubType], ABC): ) @staticmethod - def _match_certs(matchers, certs, threshold): + def _match_certs(matchers: Sequence["AbstractMatcher"], certs: list[CertSubType], threshold: float): scores: list[tuple[float, int, int]] = [] matched_is: set[int] = set() matched_js: set[int] = set() |
