# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/what-invariants-prevent-compromised-recovery-attempts-from-deepening-compromise.md # Remnant Warrant: https://corpusfetch.com/c/what-invariants-prevent-compromised-recovery-attempts-from-deepening-compromise.warrant.json # Markdown SHA-256: b4fad808b71c5f527c0c2415fb24c07fa299af91043c3923637972126011a02f # Code AST SHA-256: 5a9508d2fabcc401431f2fb44a2e665d7710de6f5a572f027a057985af3f727e # Verified Classes: RecoveryVerdict, RecoveryAttempt, RecoveryPolicy, RecoveryManifest, CompromisedRecoveryGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class RecoveryVerdict(Enum): NO_COMPROMISE = auto() SAFE_RECOVERY = auto() COMPROMISED_PATH = auto() VISIBILITY_RISK = auto() @dataclass(frozen=True) class RecoveryAttempt: attempt_id: str compromise_detected: bool recovery_path_verified: bool recovery_isolated: bool recovery_visibility_bounded: bool recovery_irreversible: bool @dataclass(frozen=True) class RecoveryPolicy: require_path_verification: bool @dataclass(frozen=True) class RecoveryManifest: verdict: RecoveryVerdict directive: str manifest_digest: str class CompromisedRecoveryGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_attempt( cls, attempt: RecoveryAttempt, policy: RecoveryPolicy ) -> RecoveryManifest: # Gate 1: No compromise if not attempt.compromise_detected: digest = cls._hash(json.dumps({ "attempt": attempt.attempt_id, "compromise": False }, sort_keys=True)) return RecoveryManifest( verdict=RecoveryVerdict.NO_COMPROMISE, directive=f"PROCEED: No compromise for attempt {attempt.attempt_id}.", manifest_digest=digest ) # Gate 2: Path verification if policy.require_path_verification and not attempt.recovery_path_verified: if not attempt.recovery_isolated and not attempt.recovery_irreversible: return RecoveryManifest( verdict=RecoveryVerdict.COMPROMISED_PATH, directive=f"HALT: Attempt {attempt.attempt_id} recovery path unverified.", manifest_digest=cls._hash(f"UNVERIFIED:{attempt.attempt_id}") ) # Gate 3: Visibility risk if not attempt.recovery_visibility_bounded: if not attempt.recovery_isolated: return RecoveryManifest( verdict=RecoveryVerdict.VISIBILITY_RISK, directive=f"FLAG: Attempt {attempt.attempt_id} visibility not bounded.", manifest_digest=cls._hash(f"VISIBILITY:{attempt.attempt_id}") ) # Gate 4: Safe digest = cls._hash(json.dumps({ "attempt": attempt.attempt_id, "path_verified": attempt.recovery_path_verified, "isolated": attempt.recovery_isolated }, sort_keys=True)) return RecoveryManifest( verdict=RecoveryVerdict.SAFE_RECOVERY, directive=f"PROCEED: Attempt {attempt.attempt_id} recovery safe.", manifest_digest=digest )