LIORAEN-Omega / research /tools /verify_integrity.py
PureOne's picture
LIORAEN-Omega research release 1.0.0; HF packaging 1.0.0-hf.1
1d047d9 verified
Raw History Blame Contribute Delete
787 Bytes
"""Verify delivered payload hashes, rejecting traversal and missing files."""
from pathlib import Path
import hashlib,json,sys
ROOT=Path(__file__).resolve().parents[1]
def main():
entries=[]
for line in (ROOT/'SHA256SUMS.txt').read_text().splitlines():
if not line.strip():continue
digest,name=line.split(' ',1)
path=(ROOT/name).resolve()
if not path.is_relative_to(ROOT):raise RuntimeError('unsafe manifest path')
if not path.is_file():raise RuntimeError(f'missing file: {name}')
actual=hashlib.sha256(path.read_bytes()).hexdigest()
if actual!=digest:raise RuntimeError(f'SHA-256 mismatch: {name}')
entries.append(name)
print(f'PASS: {len(entries)} file SHA-256 hashes match.')
if __name__=='__main__':main()