From 4fbb063846eb2375ac735c88ca0abb7df7c11267 Mon Sep 17 00:00:00 2001 From: J08nY Date: Mon, 5 Feb 2024 13:50:58 +0100 Subject: Improve Korean rules. --- src/sec_certs/rules.yaml | 8 +++++--- src/sec_certs/sample/cc_certificate_id.py | 13 +++++++++++++ tests/cc/test_cc_misc.py | 5 +++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/sec_certs/rules.yaml b/src/sec_certs/rules.yaml index c0acd3d4..5e000144 100644 --- a/src/sec_certs/rules.yaml +++ b/src/sec_certs/rules.yaml @@ -58,10 +58,12 @@ cc_cert_id: # 2020-34-INF-3784- v1 # 2019-20-INF-3379-v1 KR: - # Korea + - "KECS[-‐](?PISIS|NISS|CISS)[-‐](?P[0-9]{2,4})[-‐](?P[0-9]{4})" # XXX: Do not use KECS-CR as those refer to the certificate report and do not represent the certificate id. - # - "KECS[-‐]CR[-‐][0-9]+[-‐][0-9]+" # Korea KECS-CR-20-61 - - "KECS[-‐](?:ISIS|NISS|CISS)[-‐][0-9]+[-‐][0-9]{4}" # Korea KECS-ISIS-1234-2011 + # Examples: + # KECS-ISIS-0579-2015 + # KECS-NISS-0792-2017 + # KECS-CISS-1210-2023 JP: - "(?:CRP|ACR)-C(?P[0-9]+)-(?P[0-9]+)" - "JISEC-CC-CRP-C(?P[0-9]+)-(?P[0-9]+)-(?P[0-9]{4})" diff --git a/src/sec_certs/sample/cc_certificate_id.py b/src/sec_certs/sample/cc_certificate_id.py index 88e1f4a7..5facf1a5 100644 --- a/src/sec_certs/sample/cc_certificate_id.py +++ b/src/sec_certs/sample/cc_certificate_id.py @@ -163,6 +163,18 @@ class CertificateId: break return new_cert_id + def _canonical_kr(self): + new_cert_id = self.clean + for rule in rules["cc_cert_id"]["KR"]: + if match := re.match(rule, new_cert_id): + groups = match.groupdict() + word = groups["word"] + counter = int(groups["counter"]) + year = _parse_year(groups["year"]) + new_cert_id = f"KECS-{word}-{counter:04}-{year}" + break + return new_cert_id + def _canonical_no(self): new_cert_id = self.clean cert_num = int(new_cert_id.split("-")[1]) @@ -218,6 +230,7 @@ class CertificateId: "NO": self._canonical_no, "NL": self._canonical_nl, "AU": self._canonical_au, + "KR": self._canonical_kr, # SG is canonical by default # IT is canonucal by default } diff --git a/tests/cc/test_cc_misc.py b/tests/cc/test_cc_misc.py index 2c93c546..50bd81c0 100644 --- a/tests/cc/test_cc_misc.py +++ b/tests/cc/test_cc_misc.py @@ -63,6 +63,11 @@ def test_canonicalize_jp(): assert canonicalize("JISEC-CC-CRP-C0689-01-2020", "JP") == "JISEC-CC-CRP-C0689-01-2020" +def test_canonicalize_KR(): + assert canonicalize("KECS-ISIS-0579-2015", "KR") == "KECS-ISIS-0579-2015" + assert canonicalize("KECS-CISS-10-2023", "KR") == "KECS-CISS-0010-2023" + + def test_canonicalize_no(): assert canonicalize("SERTIT-12", "NO") == "SERTIT-012" -- cgit v1.3.1