diff options
| author | J08nY | 2024-02-05 15:55:36 +0100 |
|---|---|---|
| committer | J08nY | 2024-02-05 15:55:36 +0100 |
| commit | b05b86c32eb6068be317af1ce15e032f88d48807 (patch) | |
| tree | ac2771a2a72421b2212ac8f37fe69d9d79c00a42 /src | |
| parent | d1b16b7086c63ee9b837f9a5b77971d9d7db9874 (diff) | |
| download | sec-certs-b05b86c32eb6068be317af1ce15e032f88d48807.tar.gz sec-certs-b05b86c32eb6068be317af1ce15e032f88d48807.tar.zst sec-certs-b05b86c32eb6068be317af1ce15e032f88d48807.zip | |
Add certificateId meta property.
Diffstat (limited to 'src')
| -rw-r--r-- | src/sec_certs/sample/cc_certificate_id.py | 18 |
1 files changed, 18 insertions, 0 deletions
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 |
