Skip to content
Open
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
5 changes: 4 additions & 1 deletion src/spdx_tools/spdx/parser/tagvalue/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,10 @@ def p_license_list_version(self, p):

@grammar_rule("ext_doc_ref : EXT_DOC_REF LINE")
def p_external_document_ref(self, p):
external_doc_ref_regex = re.compile(r"(.*)(\s*SHA1:\s*[a-f0-9]{40})")
external_doc_ref_regex = re.compile(
r"(.*)(\s*(?:ADLER32|BLAKE2b-256|BLAKE2b-384|BLAKE2b-512|BLAKE3|MD2|MD4|MD5|MD6|SHA1|SHA224|SHA256|"
r"SHA384|SHA512|SHA3-256|SHA3-384|SHA3-512):\s*[a-f0-9]*)"
)
external_doc_ref_match = external_doc_ref_regex.match(p[2])
if not external_doc_ref_match:
self.creation_info["logger"].append(
Expand Down
33 changes: 32 additions & 1 deletion tests/spdx/parser/tagvalue/test_creation_info_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,37 @@ def test_parse_creation_info():
]


def test_parse_external_document_ref_with_sha256_checksum():
document_str = "\n".join(
[
"SPDXVersion: SPDX-2.3",
"DataLicense: CC0-1.0",
"DocumentName: Sample_Document-V2.3",
f"SPDXID: {DOCUMENT_SPDX_ID}",
"DocumentNamespace: https://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301",
"ExternalDocumentRef: DocumentRef-spdx-tool-1.2 "
"http://spdx.org/spdxdocs/spdx-tools-v1.2-3F2504E0-4F89-41D3-9A0C-0305E82C3301 "
"SHA256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"Creator: Person: Bob (bob@example.com)",
"Created: 2010-02-03T00:00:00Z",
]
)
parser = Parser()
document = parser.parse(document_str)
assert document is not None
creation_info = document.creation_info
assert creation_info.external_document_refs == [
ExternalDocumentRef(
"DocumentRef-spdx-tool-1.2",
"http://spdx.org/spdxdocs/spdx-tools-v1.2-3F2504E0-4F89-41D3-9A0C-0305E82C3301",
Checksum(
ChecksumAlgorithm.SHA256,
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
),
)
]


@pytest.mark.parametrize(
"document_str, expected_message",
(
Expand Down Expand Up @@ -110,7 +141,7 @@ def test_parse_creation_info():
"Error while parsing CreationInfo: ['Multiple values for LicenseListVersion found. Line: 2']",
),
(
"ExternalDocumentRef: Document_ref document_uri SHA1: afded",
"ExternalDocumentRef: Document_ref document_uri MD7: afded",
"Error while parsing CreationInfo: [\"Error while parsing ExternalDocumentRef: Couldn't match "
'Checksum. Line: 1"]',
),
Expand Down