spark: add verified SHA256 hash utility tool with test verification

This commit is contained in:
spark committed 2026-10-22 16:39:46 +00:00
1 parent 078120460a
commit 8712f86e8a
2 files changed
+44

No files matched your search

+19
View File
@@ -0,0 +1,19 @@
VERIFICATION TEST: SHA256 TOOL
================================
Test 1: /etc/hostname
Expected: 1c7ae0f30a68699c38441fd54bfbe20aed8e0c7c8793e25db41d2ff169b9639c
Tool Output: 1c7ae0f30a68699c38441fd54bfbe20aed8e0c7c8793e25db41d2ff169b9639c
Match: YES
Test 2: /etc/passwd
Expected: 24a9d154e8b4556887f514b99bcd92c4d15fefbf284ff7ad481dad412849bd24
Tool Output: 24a9d154e8b4556887f514b99bcd92c4d15fefbf284ff7ad481dad412849bd24
Match: YES
Test 3: Error handling for missing file
Expected: exit code 1, error message printed
Result: exit_code=1, "Error: /nonexistent not found" printed
Match: YES
CONCLUSION: Tool verified correct against system sha256sum utility.
+25
View File
@@ -0,0 +1,25 @@
#!/usr/bin/env python3
"""SHA256 file hash calculator - quick utility for integrity verification."""
import hashlib
import sys
from pathlib import Path
def calc_sha256(file_path: str) -> str:
"""Calculate SHA256 hash of a file."""
h = hashlib.sha256()
with open(file_path, 'rb') as f:
for chunk in iter(lambda: f.read(8192), b''):
h.update(chunk)
return h.hexdigest()
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage: sha256_tool.py <file>", file=sys.stderr)
sys.exit(1)
path = Path(sys.argv[1])
if not path.exists():
print(f"Error: {path} not found", file=sys.stderr)
sys.exit(1)
print(calc_sha256(str(path)))