Skip to content

Commit

Permalink
Merge pull request #412 from J08nY/fix/cc-link-compat
Browse files Browse the repository at this point in the history
Fix/cc link compat
  • Loading branch information
J08nY authored Jun 9, 2024
2 parents 3191333 + 703c643 commit 52c6a9f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/sec_certs/sample/cc.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ class MaintenanceReport(ComplexSerializableType):

def __post_init__(self):
super().__setattr__(
"maintenance_report_link", sec_certs.utils.sanitization.sanitize_link(self.maintenance_report_link)
"maintenance_report_link", sec_certs.utils.sanitization.sanitize_cc_link(self.maintenance_report_link)
)
super().__setattr__(
"maintenance_st_link", sec_certs.utils.sanitization.sanitize_link(self.maintenance_st_link)
"maintenance_st_link", sec_certs.utils.sanitization.sanitize_cc_link(self.maintenance_st_link)
)
super().__setattr__(
"maintenance_title", sec_certs.utils.sanitization.sanitize_string(self.maintenance_title)
Expand Down Expand Up @@ -430,9 +430,9 @@ def __init__(
self.security_level = sec_certs.utils.sanitization.sanitize_security_levels(security_level)
self.not_valid_before = sec_certs.utils.sanitization.sanitize_date(not_valid_before)
self.not_valid_after = sec_certs.utils.sanitization.sanitize_date(not_valid_after)
self.report_link = sec_certs.utils.sanitization.sanitize_link(report_link)
self.st_link = sec_certs.utils.sanitization.sanitize_link(st_link)
self.cert_link = sec_certs.utils.sanitization.sanitize_link(cert_link)
self.report_link = sec_certs.utils.sanitization.sanitize_cc_link(report_link)
self.st_link = sec_certs.utils.sanitization.sanitize_cc_link(st_link)
self.cert_link = sec_certs.utils.sanitization.sanitize_cc_link(cert_link)
self.manufacturer_web = sec_certs.utils.sanitization.sanitize_link(manufacturer_web)
self.protection_profiles = protection_profiles
self.maintenance_updates = maintenance_updates
Expand Down
12 changes: 11 additions & 1 deletion src/sec_certs/utils/sanitization.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ def sanitize_link(record: str | None) -> str | None:
return record.replace(":443", "").replace(" ", "%20").replace("http://", "https://")


def sanitize_cc_link(record: str | None) -> str | None:
record = sanitize_link(record)
if not record:
return None
record = record.replace("nfs/ccpfiles/", "")
if record == "https://www.commoncriteriaportal.org/files/epfiles/":
return None
return record


def sanitize_date(record: pd.Timestamp | date | np.datetime64) -> date | None:
if pd.isnull(record):
return None
Expand All @@ -42,7 +52,7 @@ def sanitize_string(record: str) -> str:
def sanitize_security_levels(record: str | set[str]) -> set[str]:
if isinstance(record, str):
record = set(record.split(","))
return record - {"Basic", "ND-PP", "PP\xa0Compliant", "None", "Medium"}
return record - {"Basic", "ND-PP", "PP\xa0Compliant", "None", "Medium", ""}


def sanitize_protection_profiles(record: str) -> list:
Expand Down

0 comments on commit 52c6a9f

Please sign in to comment.