Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix json deserialization due to cert path handling #312

Merged
merged 1 commit into from
Feb 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 48 additions & 8 deletions src/sec_certs/sample/cc.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ class InternalState(ComplexSerializableType):
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,
Expand Down Expand Up @@ -150,6 +150,46 @@ def __init__(
self.st_txt_hash = st_txt_hash
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 [
Expand Down Expand Up @@ -754,13 +794,13 @@ def set_local_paths(
: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
Expand Down
36 changes: 33 additions & 3 deletions src/sec_certs/sample/fips.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ class InternalState(ComplexSerializableType):
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,
Expand All @@ -267,6 +267,36 @@ def __init__(
self.policy_pdf_hash = policy_pdf_hash
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 [
Expand Down