Files
WoW-Hybrid-gateway/ops/spell_family_membership_proof.py

54 lines
3.2 KiB
Python

"""Explicit reviewed family-metadata exception; never a full effect closure."""
from copy import deepcopy
def approved_membership(proofs, ident, family, legacy):
"""Validate the reviewed identity against retained native row bindings.
Return a detached proof including operation/correspondence restrictions.
Never mutate legacy closure or authorize an individual modifier operation.
"""
def positive(value):
return type(value) is int and 0 < value <= 0x7fffffff
if type(proofs) is not dict or type(legacy) is not dict:
raise ValueError('explicit family membership proof required')
proof = proofs.get(ident)
if (type(proof) is not dict or proof.get('schema') != 'spell-family-membership-proof-v1' or
proof.get('accepted_for_family_metadata') is not True or
proof.get('membership_complete') is not True or
proof.get('membership_held_reasons') != [] or
type(proof.get('membership_held_reasons')) is not list or
type(proof.get('spell_id')) is not int or proof['spell_id'] != ident or
type(legacy.get('spell_id')) is not int or legacy['spell_id'] != ident):
raise ValueError('unapproved or mismatched family membership proof')
identity = proof.get('identity')
if (type(identity) is not dict or type(identity.get('source_family')) is not int or
identity['source_family'] != family or
type(identity.get('native_name_row_id')) is not int or identity['native_name_row_id'] != ident):
raise ValueError('family membership source or native name binding differs')
misc = identity.get('default_misc_row_ids')
effects = identity.get('active_native_effect_row_ids')
if (type(misc) is not list or len(misc) != 1 or not positive(misc[0]) or
type(effects) is not list or not effects or not all(positive(x) for x in effects) or
len(set(effects)) != len(effects)):
raise ValueError('missing or ambiguous native membership bindings')
rows = legacy.get('rows')
native = legacy.get('default_effect_rows')
if (type(rows) is not dict or type(rows.get('SpellName')) is not int or
rows['SpellName'] != ident or rows.get('SpellMisc') != misc or type(native) is not list):
raise ValueError('membership bindings differ from retained closure')
active = []
for row in native:
if (type(row) is not dict or not positive(row.get('ID')) or
type(row.get('SpellID')) is not int or row['SpellID'] != ident or
type(row.get('DifficultyID')) is not int or row['DifficultyID'] != 0 or
type(row.get('Effect')) is not int or row['Effect'] < 0):
raise ValueError('invalid retained native effect binding')
if row['Effect'] > 0:
active.append(row['ID'])
if len(set(active)) != len(active) or sorted(active) != sorted(effects):
raise ValueError('active membership effects differ from retained closure')
if any(type(proof.get(key)) is not dict for key in ('operation_qualification', 'full_effect_correspondence')):
raise ValueError('membership proof must retain operation and correspondence restrictions')
return deepcopy(proof)