EIROQ-PHI / research /scripts /verify_release.py
PureOne's picture
Add EIROQ-PHI verified research release
17f5052 verified
Raw History Blame Contribute Delete
1.47 kB
"""Check the frozen SHA-256 manifest without modifying the release.
Integrity is not a certificate of scientific validity. Rebuilding a PDF or
rerunning into the frozen directory can legitimately change a hash; reproduce
into a new directory when comparing scientific results.
"""
from __future__ import annotations
import hashlib
from pathlib import Path
import sys
def main() -> None:
root = Path(__file__).resolve().parents[1]
manifest = root / 'SHA256SUMS.txt'
if not manifest.is_file():
raise SystemExit('No SHA256SUMS.txt found at the package root.')
failures = []
checked = 0
for number, line in enumerate(manifest.read_text().splitlines(), 1):
if not line.strip():
continue
try:
expected, relative = line.split(' ', 1)
path = (root / relative).resolve()
if not path.is_relative_to(root) or len(expected) != 64:
raise ValueError('unsafe or malformed entry')
actual = hashlib.sha256(path.read_bytes()).hexdigest()
if actual != expected:
failures.append(relative + ': hash mismatch')
checked += 1
except (ValueError, OSError) as exc:
failures.append(f'line {number}: {exc}')
if failures:
print('\n'.join(failures), file=sys.stderr)
raise SystemExit(1)
print(f'{checked} manifest entries verified; no mismatches.')
if __name__ == '__main__':
main()