Files
troupe-standup/wizard-work/spark/checksum_validator.py
T

44 lines
1.3 KiB
Python

#!/usr/bin/env python3
"""
Self-validating checksum script.
Verifies its own SHA256 hash matches EXPECTED_HASH constant.
The hash excludes the EXPECTED_HASH line (lines 11-12) for self-consistency.
"""
import hashlib
import sys
from pathlib import Path
EXPECTED_HASH = "a80cd19cb447c3f7183965bc9055cb160daf9411f598fd8028dc95cbadf33f15"
def compute_self_hash():
"""Compute SHA256 hash excluding the EXPECTED_HASH value line."""
script_path = Path(__file__).resolve()
lines = script_path.read_text().split('\n')
# Exclude lines 11-12 (0-indexed: 10-11) which contain EXPECTED_HASH
relevant_lines = lines[:10] + lines[12:]
relevant_content = '\n'.join(relevant_lines) + '\n'
return hashlib.sha256(relevant_content.encode()).hexdigest()
def main():
actual_hash = compute_self_hash()
print(f"Computed hash: {actual_hash}")
script_path = Path(__file__).resolve()
content = script_path.read_text()
# Extract current expected hash from file
for line in content.split('\n'):
if line.startswith('EXPECTED_HASH = '):
expected = line.split('"')[1]
break
if actual_hash == expected:
print("VERIFIED")
return 0
else:
print(f"FAILED: expected {expected}")
return 1
if __name__ == "__main__":
sys.exit(main())