# -*- coding: utf-8 -*-
# 只读本目录合成输入，不联网、不修改设备。
import json,hashlib
from pathlib import Path
base=Path(__file__).resolve().parent
manifest=json.loads((base/'manifest.json').read_text(encoding='utf-8'))
seen=set()
for item in manifest['files']:
    rel=Path(item['path']); path=(base/rel).resolve()
    assert not rel.is_absolute() and path.is_relative_to(base) and path!=base,'路径越界'
    assert str(path) not in seen,'重复条目'
    seen.add(str(path))
    data=path.read_bytes()
    assert len(data)==item['bytes'],('大小不一致',item['path'])
    assert hashlib.sha256(data).hexdigest()==item['sha256'],('摘要不一致',item['path'])
    if item['media_type']=='text/plain': data.decode('utf-8')
    print(item['path'],'大小、SHA-256与UTF-8检查通过')
assert manifest['evidence_type']=='synthetic-demo'
print('仅为合成证据包核验；现场用例、录像与截图未测。')
