From bcbb31e609c1f03f8b66b9e0bc0c27ce9cd7e562 Mon Sep 17 00:00:00 2001 From: Adam Janovsky Date: Mon, 27 Jan 2025 16:11:32 +0100 Subject: forbid empty PP links in ProtectionProfile objects --- src/sec_certs/dataset/protection_profile.py | 18 ++++++++---------- src/sec_certs/sample/protection_profile.py | 20 +++++++++++++++----- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/sec_certs/dataset/protection_profile.py b/src/sec_certs/dataset/protection_profile.py index 1bb2e3f1..4a938d1c 100644 --- a/src/sec_certs/dataset/protection_profile.py +++ b/src/sec_certs/dataset/protection_profile.py @@ -226,16 +226,14 @@ class ProtectionProfileDataset(Dataset[ProtectionProfile], ComplexSerializableTy return {} body = list(tables[0].find_all("tr"))[1:] - try: - table_certs = { - x.dgst: x - for x in [ - ProtectionProfile.from_html_row(row, cert_status, category_string, is_collaborative) - for row in body - ] - } - except ValueError as e: - raise ValueError(f"Bad html file: {file.name} ({str(e)})") from e + table_certs = {} + for row in body: + try: + pp = ProtectionProfile.from_html_row(row, cert_status, category_string, is_collaborative) + table_certs[pp.dgst] = pp + except ValueError as e: + logger.error(f"Error when creating ProtectionProfile object: {e}") + return table_certs cert_status: Literal["active", "archived"] = "active" if "active" in file.name else "archived" diff --git a/src/sec_certs/sample/protection_profile.py b/src/sec_certs/sample/protection_profile.py index 36f13130..079c9319 100644 --- a/src/sec_certs/sample/protection_profile.py +++ b/src/sec_certs/sample/protection_profile.py @@ -19,7 +19,7 @@ from sec_certs.sample.certificate import Heuristics as BaseHeuristics from sec_certs.sample.certificate import PdfData as BasePdfData from sec_certs.sample.document_state import DocumentState from sec_certs.serialization.json import ComplexSerializableType -from sec_certs.utils import helpers +from sec_certs.utils import helpers, sanitization class ProtectionProfile( @@ -83,18 +83,23 @@ class ProtectionProfile( f"Unexpected number of