Files
WoW-Hybrid-gateway/ops/weapon_presentation_dependency.py
2026-11-19 03:45:34 +02:00

49 lines
2.4 KiB
Python

"""Read-only check of an already qualified Source weapon addon dependency.
Payload provenance is supplied by the owning package's accepted file pins;
this check neither generates item data nor establishes native damage parity.
"""
import hashlib
from pathlib import Path
import re
DATA = 'SourceWeaponDamageData.lua'
PROVIDER = 'SourceWeaponDamage.lua'
TOC = 'WoWHybridUI.toc'
def verify(addon, *, provider_sha256, data_sha256, toc_bytes=None):
"""Require exact qualified files and one data-before-provider load entry.
A candidate TOC can be checked before a caller's reversible transaction.
Omitting it verifies the actual on-disk manifest. No files are written.
"""
addon = Path(addon)
if addon.is_symlink() or not addon.is_dir():
raise ValueError('Source weapon addon directory differs')
pins = {DATA: data_sha256, PROVIDER: provider_sha256}
for name, expected in pins.items():
if not isinstance(expected, str) or re.fullmatch('[0-9a-f]{64}', expected) is None:
raise ValueError('Source weapon accepted file pin required')
path = addon / name
if path.is_symlink() or not path.is_file() or not 0 < path.stat().st_size <= 1048576:
raise ValueError('Source weapon dependency file type/size differs: ' + name)
if hashlib.sha256(path.read_bytes()).hexdigest() != expected:
raise ValueError('Source weapon dependency bytes differ: ' + name)
if toc_bytes is None:
path = addon / TOC
if path.is_symlink() or not path.is_file() or not 0 < path.stat().st_size <= 65536:
raise ValueError('Source weapon addon manifest type/size differs')
toc_bytes = path.read_bytes()
if not isinstance(toc_bytes, bytes) or not 0 < len(toc_bytes) <= 65536:
raise ValueError('Source weapon addon manifest byte bound differs')
entries = [line.strip() for line in toc_bytes.decode('utf-8').splitlines()
if line.strip() and not line.lstrip().startswith('#')]
if (entries.count(DATA) != 1 or entries.count(PROVIDER) != 1
or entries.index(DATA) >= entries.index(PROVIDER)):
raise ValueError('Source weapon dependency load order differs')
return dict(provider_sha256=provider_sha256, data_sha256=data_sha256,
toc_sha256=hashlib.sha256(toc_bytes).hexdigest(),
ordered_dependencies=[DATA, PROVIDER], file_pins_verified=True,
gameplay_verified=False)