From 1c40cbf9a2e4f1de9b0a01c05a8a5c810658b3a0 Mon Sep 17 00:00:00 2001 From: Adam Janovsky Date: Tue, 23 Feb 2021 19:01:23 +0100 Subject: dgst is serialized as a field in certificate - Previously as a part of dataset where certs changed to dictionary - For rendering at webserver, list is more convenient --- sec_certs/certificate.py | 4 ++-- sec_certs/dataset.py | 4 ++-- test/data/test_cc_oop/fictional_cert.json | 1 + test/data/test_cc_oop/toy_dataset.json | 10 ++++++---- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/sec_certs/certificate.py b/sec_certs/certificate.py index c253222c..837e16bb 100644 --- a/sec_certs/certificate.py +++ b/sec_certs/certificate.py @@ -47,10 +47,11 @@ class Certificate(ABC): return self.dgst == other.dgst def to_dict(self): - return copy.deepcopy(self.__dict__) + return {**{'dgst': self.dgst}, **copy.deepcopy(self.__dict__)} @classmethod def from_dict(cls: Type[T], dct: dict) -> T: + dct.pop('dgst') return cls(*(tuple(dct.values()))) def to_json(self, output_path: Union[Path, str]): @@ -809,7 +810,6 @@ class CommonCriteriaCert(Certificate, ComplexSerializableType): report_pdf_path: Path st_txt_path: Path report_txt_path: Path - errors: List[str] def __init__(self, st_link_ok: bool = True, report_link_ok: bool = True, st_convert_ok: bool = True, report_convert_ok: bool = True, diff --git a/sec_certs/dataset.py b/sec_certs/dataset.py index 5018f9e9..56cd3a1b 100644 --- a/sec_certs/dataset.py +++ b/sec_certs/dataset.py @@ -70,11 +70,11 @@ class Dataset(ABC): def to_dict(self): return {'timestamp': self.timestamp, 'sha256_digest': self.sha256_digest, 'name': self.name, 'description': self.description, - 'n_certs': len(self), 'certs': self.certs} + 'n_certs': len(self), 'certs': list(self.certs.values())} @classmethod def from_dict(cls, dct: Dict): - certs = {x.dgst: x for x in dct['certs'].values()} + certs = {x.dgst: x for x in dct['certs']} dset = cls(certs, Path('./'), dct['name'], dct['description']) if len(dset) != (claimed := dct['n_certs']): logger.error( diff --git a/test/data/test_cc_oop/fictional_cert.json b/test/data/test_cc_oop/fictional_cert.json index 80f116e0..33a1aafb 100644 --- a/test/data/test_cc_oop/fictional_cert.json +++ b/test/data/test_cc_oop/fictional_cert.json @@ -1,5 +1,6 @@ { "_type": "CommonCriteriaCert", + "dgst": "9cf077f8b3c4a825", "status": "archived", "category": "Sample category", "name": "Sample certificate name", diff --git a/test/data/test_cc_oop/toy_dataset.json b/test/data/test_cc_oop/toy_dataset.json index ffacaae6..aaafb53c 100644 --- a/test/data/test_cc_oop/toy_dataset.json +++ b/test/data/test_cc_oop/toy_dataset.json @@ -13,9 +13,10 @@ "name": "toy dataset", "description": "toy dataset description", "n_certs": 2, - "certs": { - "7ef8227c1aed06bb": { + "certs": [ + { "_type": "CommonCriteriaCert", + "dgst": "7ef8227c1aed06bb", "status": "active", "category": "Access Control Devices and Systems", "name": "NetIQ Identity Manager 4.7", @@ -53,8 +54,9 @@ "st_keywords": null } }, - "561a012d9a30e960": { + { "_type": "CommonCriteriaCert", + "dgst": "561a012d9a30e960", "status": "active", "category": "Access Control Devices and Systems", "name": "Magic SSO V4.0", @@ -95,5 +97,5 @@ "st_keywords": null } } - } + ] } \ No newline at end of file -- cgit v1.3.1