From b05b86c32eb6068be317af1ce15e032f88d48807 Mon Sep 17 00:00:00 2001 From: J08nY Date: Mon, 5 Feb 2024 15:55:36 +0100 Subject: Add certificateId meta property. --- src/sec_certs/sample/cc_certificate_id.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src') diff --git a/src/sec_certs/sample/cc_certificate_id.py b/src/sec_certs/sample/cc_certificate_id.py index e5f86bba..023e6e54 100644 --- a/src/sec_certs/sample/cc_certificate_id.py +++ b/src/sec_certs/sample/cc_certificate_id.py @@ -2,6 +2,7 @@ from __future__ import annotations import re from dataclasses import dataclass +from functools import cached_property from sec_certs.cert_rules import rules @@ -27,6 +28,13 @@ class CertificateId: scheme: str raw: str + @cached_property + def meta(self): + for rule in rules["cc_cert_id"][self.scheme]: + if match := re.match(rule, self.clean): + return match.groupdict() + return {} + def _canonical_fr(self) -> str: new_cert_id = self.clean for rule in rules["cc_cert_id"]["FR"]: @@ -274,6 +282,16 @@ class CertificateId: else: return self.clean + def __hash__(self): + return hash((self.scheme, self.raw)) + + def __eq__(self, other): + if isinstance(other, str): + return self.canonical == other + if not isinstance(other, CertificateId): + return False + return self.canonical == other.canonical and self.scheme == other.scheme + def canonicalize(cert_id_str: str, scheme: str) -> str: return CertificateId(scheme, cert_id_str).canonical -- cgit v1.3.1