diff options
| author | adamjanovsky | 2023-02-05 17:29:48 +0100 |
|---|---|---|
| committer | GitHub | 2023-02-05 17:29:48 +0100 |
| commit | a13e085b06cb2772ec812e4bd364a7fe938c806f (patch) | |
| tree | 86edd4c21525b66226875392aeb53602ed009c27 | |
| parent | 29ef79f28d0940208b14109c2f39be52aec3a59a (diff) | |
| parent | 8fb06872885579c756c5ac4856a3fd5e9a96b2ac (diff) | |
| download | sec-certs-a13e085b06cb2772ec812e4bd364a7fe938c806f.tar.gz sec-certs-a13e085b06cb2772ec812e4bd364a7fe938c806f.tar.zst sec-certs-a13e085b06cb2772ec812e4bd364a7fe938c806f.zip | |
Merge pull request #312 from crocs-muni/fix/improve-path-setting-cert-internal-state
fix json deserialization due to cert path handling
| -rw-r--r-- | src/sec_certs/sample/cc.py | 56 | ||||
| -rw-r--r-- | src/sec_certs/sample/fips.py | 36 |
2 files changed, 81 insertions, 11 deletions
diff --git a/src/sec_certs/sample/cc.py b/src/sec_certs/sample/cc.py index 3930104b..9f73aefa 100644 --- a/src/sec_certs/sample/cc.py +++ b/src/sec_certs/sample/cc.py @@ -116,10 +116,10 @@ class CCCertificate( st_txt_hash: str | None report_txt_hash: str | None - st_pdf_path: Path - report_pdf_path: Path - st_txt_path: Path - report_txt_path: Path + _st_pdf_path: Path | None = None + _report_pdf_path: Path | None = None + _st_txt_path: Path | None = None + _report_txt_path: Path | None = None def __init__( self, @@ -151,6 +151,46 @@ class CCCertificate( self.report_txt_hash = report_txt_hash @property + def st_pdf_path(self) -> Path: + if not self._st_pdf_path: + raise ValueError(f"st_pdf_path not set on {type(self)}") + return self._st_pdf_path + + @st_pdf_path.setter + def st_pdf_path(self, pth: str | Path | None) -> None: + self._st_pdf_path = Path(pth) if pth else None + + @property + def report_pdf_path(self) -> Path: + if not self._report_pdf_path: + raise ValueError(f"report_pdf_path not set on {type(self)}") + return self._report_pdf_path + + @report_pdf_path.setter + def report_pdf_path(self, pth: str | Path | None) -> None: + self._report_pdf_path = Path(pth) if pth else None + + @property + def st_txt_path(self) -> Path: + if not self._st_txt_path: + raise ValueError(f"st_txt_path not set on {type(self)}") + return self._st_txt_path + + @st_txt_path.setter + def st_txt_path(self, pth: str | Path | None) -> None: + self._st_txt_path = Path(pth) if pth else None + + @property + def report_txt_path(self) -> Path: + if not self._report_txt_path: + raise ValueError(f"report_txt_path not set on {type(self)}") + return self._report_txt_path + + @report_txt_path.setter + def report_txt_path(self, pth: str | Path | None) -> None: + self._report_txt_path = Path(pth) if pth else None + + @property def serialized_attributes(self) -> list[str]: return [ "st_download_ok", @@ -754,13 +794,13 @@ class CCCertificate( :param Optional[Union[str, Path]] report_txt_dir: Directory where txt reports shall be stored :param Optional[Union[str, Path]] st_txt_dir: Directory where txt security targets shall be stored """ - if report_pdf_dir is not None: + if report_pdf_dir: self.state.report_pdf_path = Path(report_pdf_dir) / (self.dgst + ".pdf") - if st_pdf_dir is not None: + if st_pdf_dir: self.state.st_pdf_path = Path(st_pdf_dir) / (self.dgst + ".pdf") - if report_txt_dir is not None: + if report_txt_dir: self.state.report_txt_path = Path(report_txt_dir) / (self.dgst + ".txt") - if st_txt_dir is not None: + if st_txt_dir: self.state.st_txt_path = Path(st_txt_dir) / (self.dgst + ".txt") @staticmethod diff --git a/src/sec_certs/sample/fips.py b/src/sec_certs/sample/fips.py index 4a9d573f..09f29fae 100644 --- a/src/sec_certs/sample/fips.py +++ b/src/sec_certs/sample/fips.py @@ -243,9 +243,9 @@ class FIPSCertificate( policy_pdf_hash: str | None policy_txt_hash: str | None - policy_pdf_path: Path - policy_txt_path: Path - module_html_path: Path + _policy_pdf_path: Path | None = None + _policy_txt_path: Path | None = None + _module_html_path: Path | None = None def __init__( self, @@ -268,6 +268,36 @@ class FIPSCertificate( self.policy_txt_hash = policy_txt_hash @property + def policy_pdf_path(self) -> Path: + if not self._policy_pdf_path: + raise ValueError(f"policy_pdf_path not set on {type(self)}") + return self._policy_pdf_path + + @policy_pdf_path.setter + def policy_pdf_path(self, pth: str | Path | None) -> None: + self._policy_pdf_path = Path(pth) if pth else None + + @property + def policy_txt_path(self) -> Path: + if not self._policy_txt_path: + raise ValueError(f"policy_txt_path not set on {type(self)}") + return self._policy_txt_path + + @policy_txt_path.setter + def policy_txt_path(self, pth: str | Path | None) -> None: + self._policy_txt_path = Path(pth) if pth else None + + @property + def module_html_path(self) -> Path: + if not self._module_html_path: + raise ValueError(f"module_html_path not set on {type(self)}") + return self._module_html_path + + @module_html_path.setter + def module_html_path(self, pth: str | Path | None) -> None: + self._module_html_path = Path(pth) if pth else None + + @property def serialized_attributes(self) -> list[str]: return [ "module_download_ok", |
