# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-cryptographic-erasure-as-unverifiable-rather-than-failed-when-the-key-destruction-audit-trail-is-incomplete.md
# Remnant Warrant:    https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-cryptographic-erasure-as-unverifiable-rather-than-failed-when-the-key-destruction-audit-trail-is-incomplete.warrant.json
# Markdown SHA-256:   cabc0d90f240740579458118a0de18422356c76f5f7fa76c7e2fe69ef8b0de5f
# Code AST SHA-256:   0687b5941d160526ff9bced991cf799c9f974b5239b4928f66ce81e13e8cf1ad
# Verified Classes:   ErasureClassificationError, ErasureState
# Defensive Guards:   2 fail-closed invariants (zero external deps)

class ErasureClassificationError(RuntimeError):
    """Raised when an erasure claim cannot be honestly classified."""
    pass


class ErasureState:
    VERIFIED = "ERASURE_VERIFIED"
    VERIFIED_SECONDARY = "ERASURE_VERIFIED_VIA_SECONDARY"
    UNVERIFIABLE = "ERASURE_UNVERIFIABLE"
    FAILED = "ERASURE_FAILED"


def classify_erasure(key_absent_confirmed: bool,
                     chain_contiguous: bool,
                     gap_is_known_defect: bool,
                     secondary_confirmation: bool) -> str:
    """Classify an erasure claim. Never emit FAILED for a provably absent key."""
    if not key_absent_confirmed:
        # Key present or absence unproven: this is a real failure.
        return ErasureState.FAILED

    if chain_contiguous:
        return ErasureState.VERIFIED

    if secondary_confirmation:
        # Key gone, primary chain broken, but an independent channel confirms.
        return ErasureState.VERIFIED_SECONDARY

    if gap_is_known_defect:
        # Gap is attributable to instrumentation, not to key recovery.
        return ErasureState.UNVERIFIABLE

    # Unexplained gap with confirmed absence: unverifiable but escalated.
    raise ErasureClassificationError(
        "Unexplained evidence gap with confirmed key absence; "
        "route to human review, do not emit FAILED or VERIFIED."
    )


def assert_no_false_failure(state: str, key_absent_confirmed: bool) -> None:
    if state == ErasureState.FAILED and key_absent_confirmed:
        raise ErasureClassificationError(
            "Refusing to emit ERASURE_FAILED for a key confirmed absent; "
            "this is an evidentiary gap, not a cryptographic failure."
        )
