Skip to content

Commit

Permalink
Merge pull request #221 from crocs-muni/feat/track-doc-hashes
Browse files Browse the repository at this point in the history
Add document hashes.
  • Loading branch information
adamjanovsky committed May 30, 2022
2 parents de9e12c + ff6deb9 commit 191997b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions sec_certs/sample/common_criteria.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ class InternalState(ComplexSerializableType):

st_pdf_path: Path
report_pdf_path: Path
st_pdf_hash: Optional[str]
report_pdf_hash: Optional[str]
st_txt_path: Path
report_txt_path: Path
st_txt_hash: Optional[str]
report_txt_hash: Optional[str]

def __init__(
self,
Expand All @@ -124,8 +128,12 @@ def serialized_attributes(self) -> List[str]:
return [
"st_download_ok",
"report_download_ok",
"st_pdf_hash",
"report_pdf_hash",
"st_convert_ok",
"report_convert_ok",
"st_txt_hash",
"report_txt_hash",
"st_extract_ok",
"report_extract_ok",
"errors",
Expand Down Expand Up @@ -673,6 +681,8 @@ def download_pdf_report(cert: CommonCriteriaCert) -> CommonCriteriaCert:
logger.error(f"Cert dgst: {cert.dgst} " + error_msg)
cert.state.report_download_ok = False
cert.state.errors.append(error_msg)
else:
cert.state.report_pdf_hash = helpers.get_sha256_filepath(cert.state.report_pdf_path)
return cert

@staticmethod
Expand All @@ -693,6 +703,8 @@ def download_pdf_st(cert: CommonCriteriaCert) -> CommonCriteriaCert:
logger.error(f"Cert dgst: {cert.dgst}" + error_msg)
cert.state.st_download_ok = False
cert.state.errors.append(error_msg)
else:
cert.state.st_pdf_hash = helpers.get_sha256_filepath(cert.state.st_pdf_path)
return cert

@staticmethod
Expand All @@ -709,6 +721,8 @@ def convert_report_pdf(cert: CommonCriteriaCert) -> CommonCriteriaCert:
logger.error(f"Cert dgst: {cert.dgst}" + error_msg)
cert.state.report_convert_ok = False
cert.state.errors.append(error_msg)
else:
cert.state.report_txt_hash = helpers.get_sha256_filepath(cert.state.report_txt_path)
return cert

@staticmethod
Expand All @@ -725,6 +739,8 @@ def convert_st_pdf(cert: CommonCriteriaCert) -> CommonCriteriaCert:
logger.error(f"Cert dgst: {cert.dgst}" + error_msg)
cert.state.st_convert_ok = False
cert.state.errors.append(error_msg)
else:
cert.state.st_txt_hash = helpers.get_sha256_filepath(cert.state.st_txt_path)
return cert

@staticmethod
Expand Down

0 comments on commit 191997b

Please sign in to comment.