cgeq-image-depth / verify.py
pyfccc's picture
Release verified CGEQ KITTI-derived depth calibration cache
643f4cb verified
Raw History Blame Contribute Delete
1.12 kB
"""Verify every downloaded cache file against its original SHA-256."""
from pathlib import Path
import argparse, hashlib, json
EXPECTED = "281e4e8672ea7a47bb1e569e1e0c435b59a331be1352a1604b292a924ca2fe59"
def digest(path):
h = hashlib.sha256()
with path.open("rb") as f:
for block in iter(lambda: f.read(8 * 1024**2), b""): h.update(block)
return h.hexdigest()
def verify(cache):
cache = Path(cache).resolve()
if digest(cache / "manifest.json") != EXPECTED: raise ValueError("Unexpected manifest")
manifest = json.loads((cache / "manifest.json").read_text())
for row in manifest["frames"]:
path = (cache / row["path"]).resolve()
if not path.is_relative_to(cache): raise ValueError("Unsafe manifest path")
if digest(path) != row["sha256"]: raise ValueError(f"Hash mismatch: {row['path']}")
print(f"PASS: {len(manifest['frames'])} files match the original frozen cache.")
if __name__ == "__main__":
p=argparse.ArgumentParser(); p.add_argument("--cache",type=Path,default=Path(__file__).resolve().parent/"frozen_depth")
verify(p.parse_args().cache)