# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/how-must-an-instance-handle-the-transition-from-operational-to-compromised-status.md # Remnant Warrant: https://corpusfetch.com/c/how-must-an-instance-handle-the-transition-from-operational-to-compromised-status.warrant.json # Markdown SHA-256: 036d6eb7b00afbdd48ab8ad5cad7536ec7dc6fa8f8cdce1c11412cb1bc83185b # Code AST SHA-256: 2dfd734bb97753fc0ee9e407198ed8b85948bcb883c0e3a2b5918f55e0131098 # Verified Classes: TransitionVerdict, TransitionState, TransitionPolicy, TransitionManifest, OperationalToCompromisedGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class TransitionVerdict(Enum): OPERATIONAL = auto() SCOPE_DECLARED_TRANSITION = auto() TOTAL_COMPROMISE = auto() UNDECLARED_TRANSITION = auto() @dataclass(frozen=True) class TransitionState: state_id: str transition_triggered: bool compromise_scope_defined: bool salvageable_state_verified: bool is_total_compromise: bool @dataclass(frozen=True) class TransitionPolicy: require_scope_for_transition: bool @dataclass(frozen=True) class TransitionManifest: verdict: TransitionVerdict directive: str manifest_digest: str class OperationalToCompromisedGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_state( cls, state: TransitionState, policy: TransitionPolicy ) -> TransitionManifest: # Gate 1: No transition if not state.transition_triggered: digest = cls._hash(json.dumps({ "state": state.state_id, "transition": False }, sort_keys=True)) return TransitionManifest( verdict=TransitionVerdict.OPERATIONAL, directive=f"PROCEED: State {state.state_id} operational.", manifest_digest=digest ) # Gate 2: Total compromise if state.is_total_compromise: return TransitionManifest( verdict=TransitionVerdict.TOTAL_COMPROMISE, directive=f"HALT: State {state.state_id} total compromise.", manifest_digest=cls._hash(f"TOTAL:{state.state_id}") ) # Gate 3: Scope declaration if policy.require_scope_for_transition and not state.compromise_scope_defined: return TransitionManifest( verdict=TransitionVerdict.UNDECLARED_TRANSITION, directive=f"HALT: State {state.state_id} transition without scope declaration.", manifest_digest=cls._hash(f"NO_SCOPE:{state.state_id}") ) # Gate 4: Salvage if not state.salvageable_state_verified: return TransitionManifest( verdict=TransitionVerdict.UNDECLARED_TRANSITION, directive=f"FLAG: State {state.state_id} salvage unverified.", manifest_digest=cls._hash(f"NO_SALVAGE:{state.state_id}") ) # Gate 5: Scoped digest = cls._hash(json.dumps({ "state": state.state_id, "scope": True, "salvage": True }, sort_keys=True)) return TransitionManifest( verdict=TransitionVerdict.SCOPE_DECLARED_TRANSITION, directive=f"PROCEED: State {state.state_id} scoped transition.", manifest_digest=digest )