diff options
| author | J08nY | 2023-04-17 14:10:27 +0200 |
|---|---|---|
| committer | J08nY | 2023-04-17 14:10:27 +0200 |
| commit | fa24c2c0ce6e2d29828ca4204e40507fc2db1e89 (patch) | |
| tree | af535bc35d081ce75572e73b38a6b172da3eb3f9 /src/sec_certs/model | |
| parent | 79f49a431fbd03f5352424d9c7455066548e8b71 (diff) | |
| download | sec-certs-fa24c2c0ce6e2d29828ca4204e40507fc2db1e89.tar.gz sec-certs-fa24c2c0ce6e2d29828ca4204e40507fc2db1e89.tar.zst sec-certs-fa24c2c0ce6e2d29828ca4204e40507fc2db1e89.zip | |
Change matcher API to not ref dataset.
Diffstat (limited to 'src/sec_certs/model')
| -rw-r--r-- | src/sec_certs/model/cc_matching.py | 15 | ||||
| -rw-r--r-- | src/sec_certs/model/fips_matching.py | 12 | ||||
| -rw-r--r-- | src/sec_certs/model/matching.py | 6 |
3 files changed, 15 insertions, 18 deletions
diff --git a/src/sec_certs/model/cc_matching.py b/src/sec_certs/model/cc_matching.py index a4c9c2d5..3fa5fe34 100644 --- a/src/sec_certs/model/cc_matching.py +++ b/src/sec_certs/model/cc_matching.py @@ -1,18 +1,17 @@ from __future__ import annotations -from typing import Any, Mapping +from typing import Any, Iterable, Mapping from rapidfuzz import fuzz from sec_certs.configuration import config -from sec_certs.dataset.cc import CCDataset from sec_certs.model.matching import AbstractMatcher from sec_certs.sample.cc import CCCertificate from sec_certs.sample.cc_certificate_id import CertificateId from sec_certs.utils.strings import fully_sanitize_string -class CCSchemeMatcher(AbstractMatcher[CCCertificate, CCDataset]): +class CCSchemeMatcher(AbstractMatcher[CCCertificate]): """ A heuristic matcher between entries on CC scheme websites (see CCSchemeDataset) and CC certificates from the Common Criteria portal (as in CCDataset). @@ -82,15 +81,17 @@ class CCSchemeMatcher(AbstractMatcher[CCCertificate, CCDataset]): return max((0, max(product_ratings) * 0.5 + max(vendor_ratings) * 0.5 - 2)) @classmethod - def match_all(cls, entries: list[dict[str, Any]], scheme: str, dset: CCDataset) -> dict[str, Mapping]: + def match_all( + cls, entries: list[dict[str, Any]], scheme: str, certificates: Iterable[CCCertificate] + ) -> dict[str, Mapping]: """ Match all entries of a given CC scheme to certificates from the dataset. :param entries: The entries from the scheme, obtained from CCSchemeDataset. :param scheme: The scheme, e.g. "DE". - :param dset: The dataset to match against. + :param certificates: The certificates to match against. :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, dset)) + certs: list[CCCertificate] = list(filter(lambda cert: cert.scheme == scheme, certificates)) matchers = [CCSchemeMatcher(entry, scheme) for entry in entries] - return cls._match_all(matchers, certs, config.cc_matching_threshold) + return cls._match_certs(matchers, certs, config.cc_matching_threshold) diff --git a/src/sec_certs/model/fips_matching.py b/src/sec_certs/model/fips_matching.py index e4f9fbc5..f108a192 100644 --- a/src/sec_certs/model/fips_matching.py +++ b/src/sec_certs/model/fips_matching.py @@ -1,12 +1,11 @@ from __future__ import annotations import typing -from typing import Mapping +from typing import Iterable, Mapping from rapidfuzz import fuzz from sec_certs.configuration import config -from sec_certs.dataset.fips import FIPSDataset from sec_certs.model.matching import AbstractMatcher from sec_certs.sample.fips import FIPSCertificate from sec_certs.utils.strings import fully_sanitize_string @@ -16,7 +15,7 @@ if typing.TYPE_CHECKING: from sec_certs.sample.fips_mip import MIPEntry, MIPSnapshot -class FIPSProcessMatcher(AbstractMatcher[FIPSCertificate, FIPSDataset]): +class FIPSProcessMatcher(AbstractMatcher[FIPSCertificate]): """ A heuristic matcher between entries on the FIPS IUT/MIP lists and the FIPS certificates. @@ -59,15 +58,14 @@ class FIPSProcessMatcher(AbstractMatcher[FIPSCertificate, FIPSDataset]): @classmethod def match_snapshot( - cls, snapshot: IUTSnapshot | MIPSnapshot, dset: FIPSDataset + cls, snapshot: IUTSnapshot | MIPSnapshot, certificates: Iterable[FIPSCertificate] ) -> Mapping[IUTEntry | MIPEntry, FIPSCertificate | None]: """ Match a whole snapshot of IUT/MIP entries to a FIPS certificate dataset. :param snapshot: The snapshot to match the entries of. - :param dset: The dataset to match to. + :param certificates: The certificates to match against. :return: A mapping of certificate digests to entries, without duplicates, not all entries may be present. """ - certs: list[FIPSCertificate] = list(dset) matchers = [FIPSProcessMatcher(entry) for entry in snapshot] - return cls._match_all(matchers, certs, config.fips_matching_threshold) + return cls._match_certs(matchers, certificates, config.fips_matching_threshold) diff --git a/src/sec_certs/model/matching.py b/src/sec_certs/model/matching.py index 687a5888..f2139340 100644 --- a/src/sec_certs/model/matching.py +++ b/src/sec_certs/model/matching.py @@ -3,20 +3,18 @@ from abc import ABC, abstractmethod from heapq import heappop, heappush from typing import Generic -from sec_certs.dataset.dataset import Dataset from sec_certs.sample.certificate import Certificate CertSubType = typing.TypeVar("CertSubType", bound=Certificate) -DatasetSubType = typing.TypeVar("DatasetSubType", bound=Dataset) -class AbstractMatcher(Generic[CertSubType, DatasetSubType], ABC): +class AbstractMatcher(Generic[CertSubType], ABC): @abstractmethod def match(self, cert: CertSubType) -> float: raise NotImplementedError @staticmethod - def _match_all(matchers, certs, threshold): + def _match_certs(matchers, certs, threshold): scores: list[tuple[float, int, int]] = [] matched_is: set[int] = set() matched_js: set[int] = set() |
