"""Validate this Hugging Face distribution's SHA-256 manifest (standard library only).""" from pathlib import Path import hashlib ROOT = Path(__file__).resolve().parent def main(): count = 0 seen = set() for line in (ROOT / 'SHA256SUMS.txt').read_text(encoding='utf-8').splitlines(): if not line.strip(): continue digest, name = line.split(' ', 1) path = (ROOT / name).resolve() if name in seen or len(digest) != 64 or any(c not in '0123456789abcdef' for c in digest): raise SystemExit('Invalid or duplicate manifest entry: ' + name) if not path.is_relative_to(ROOT) or not path.is_file(): raise SystemExit('Missing file or unsafe path: ' + name) actual = hashlib.sha256(path.read_bytes()).hexdigest() if actual != digest: raise SystemExit('SHA-256 mismatch: ' + name) seen.add(name) count += 1 if not count: raise SystemExit('Manifest is empty.') print(f'PASS: {count} distribution file hashes match.') print('Integrity verifies bytes; it does not certify mathematical correctness.') if __name__ == '__main__': main()