Skip to content

Commit 28911a5

Browse files
authored
feat(sbom): add checksum (#5347)
Use path to compute a checksum for the package. It is useful to identify if a package has changed or not. Signed-off-by: Fabrice Fontaine <[email protected]>
1 parent 8c0f847 commit 28911a5

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

cve_bin_tool/sbom_manager/generate.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright (C) 2024 Intel Corporation
22
# SPDX-License-Identifier: GPL-3.0-or-later
33

4+
import hashlib
45
from logging import Logger
56
from pathlib import Path
67
from typing import Optional
@@ -113,6 +114,10 @@ def generate_sbom(self) -> None:
113114
product_data
114115
].get("paths"):
115116
for path in self.all_cve_data[product_data]["paths"]:
117+
with open(path.split()[0], "rb") as f:
118+
file_data = f.read()
119+
sha256_hash = hashlib.sha256(file_data)
120+
my_package.set_checksum("SHA256", sha256_hash.hexdigest())
116121
if self.strip_scan_dir:
117122
evidence = strip_path(path, self.sbom_root)
118123
else:

0 commit comments

Comments
 (0)