"""Verify the release's checked file set using the Python standard library.""" import hashlib from pathlib import Path import sys root = Path(sys.argv[1] if len(sys.argv) > 1 else '.').resolve() seen = set() for line in (root / 'SHA256SUMS.txt').read_text(encoding='utf-8').splitlines(): digest, relative = line.split(' ', 1) path = (root / relative).resolve() if root not in path.parents or relative in seen: raise ValueError('Unsafe or duplicate checksum entry: ' + relative) seen.add(relative) if hashlib.sha256(path.read_bytes()).hexdigest() != digest: raise ValueError('Checksum mismatch: ' + relative) print('PASS: ' + str(len(seen)) + ' files match SHA256SUMS.txt')