diff options
| author | J08nY | 2023-04-18 14:47:39 +0200 |
|---|---|---|
| committer | J08nY | 2023-04-18 14:47:39 +0200 |
| commit | c372cb89e876cfdd103bf361a518d024246854c5 (patch) | |
| tree | f3ba68d67430c16c51ac31e031a8eab25159e277 | |
| parent | 86590b3f058186bf7e2598961ab5d036e1a8f568 (diff) | |
| download | sec-certs-c372cb89e876cfdd103bf361a518d024246854c5.tar.gz sec-certs-c372cb89e876cfdd103bf361a518d024246854c5.tar.zst sec-certs-c372cb89e876cfdd103bf361a518d024246854c5.zip | |
More comments in matching.
| -rw-r--r-- | src/sec_certs/model/cc_matching.py | 7 | ||||
| -rw-r--r-- | src/sec_certs/model/fips_matching.py | 5 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/sec_certs/model/cc_matching.py b/src/sec_certs/model/cc_matching.py index 3cc38a40..350a2e9d 100644 --- a/src/sec_certs/model/cc_matching.py +++ b/src/sec_certs/model/cc_matching.py @@ -57,21 +57,28 @@ class CCSchemeMatcher(AbstractMatcher[CCCertificate]): :return: The match score. """ # This one is full of magic numbers, there is some idea to it but adjust as necessary. + # We want to match the same scheme. if self.scheme != cert.scheme: return 0 + # If we have a perfect cert_id match, take it. if self._canonical_cert_id and cert.heuristics.cert_id == self._canonical_cert_id: return 100 + # We need to have something to match to. if self._product is None or self._vendor is None or cert.name is None or cert.manufacturer is None: return 0 cert_name = fully_sanitize_string(cert.name) cert_manufacturer = fully_sanitize_string(cert.manufacturer) + # If we match exactly, return early. if self._product == cert.name and self._vendor == cert.manufacturer: return 99 + # If we match the report hash, return early. if cert.state.report_pdf_hash == self._report_hash and self._report_hash is not None: return 95 + # If we match the target hash, return early. if cert.state.st_pdf_hash == self._target_hash and self._target_hash is not None: return 93 + # Fuzzy match at the end with some penalization. product_rating = self._compute_match(self._product, cert_name) vendor_rating = self._compute_match(self._vendor, cert_manufacturer) return max((0, product_rating * 0.5 + vendor_rating * 0.5 - 2)) diff --git a/src/sec_certs/model/fips_matching.py b/src/sec_certs/model/fips_matching.py index eefb88bb..50079611 100644 --- a/src/sec_certs/model/fips_matching.py +++ b/src/sec_certs/model/fips_matching.py @@ -37,19 +37,24 @@ class FIPSProcessMatcher(AbstractMatcher[FIPSCertificate]): :param cert: The certificate to match against. :return: The match score. """ + # We want to match the same standard. if cert.web_data.standard != self._standard: return 0 + # We need to have something to match to. if cert.name is None or cert.manufacturer is None: return 0 + # We can't match to a cert that predates us (MIP or IUT always predates the cert). if cert.web_data.validation_history and not any( validation_entry.date > self._date for validation_entry in cert.web_data.validation_history ): return 0 + # If we match exactly, return early. cert_name = fully_sanitize_string(cert.name) cert_manufacturer = fully_sanitize_string(cert.manufacturer) if self._product == cert_name and self._vendor == cert_manufacturer: return 99 + # Fuzzy match at the end with some penalization. product_rating = self._compute_match(self._product, cert_name) vendor_rating = self._compute_match(self._vendor, cert_manufacturer) return max((0, product_rating * 0.5 + vendor_rating * 0.5 - 2)) |
