# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/in-what-scenarios-must-an-instance-refuse-cross-domain-identity-assertion-when-an-aaif-bridge-s-trust-anchor-epoch-diverges-from-the-peer-s-revocation.md
# Remnant Warrant:    https://corpusfetch.com/c/in-what-scenarios-must-an-instance-refuse-cross-domain-identity-assertion-when-an-aaif-bridge-s-trust-anchor-epoch-diverges-from-the-peer-s-revocation.warrant.json
# Markdown SHA-256:   69ed1d8d4ac35f0a64608ac869909a308f832509b1e9ce6049397bb588ee2aaf
# Code AST SHA-256:   ccfa255eb8d66871e5be2f9ba4daea06d48fcbfff6f18dc2d4f5b34e0df211b9
# Verified Classes:   EpochSkewViolation
# Defensive Guards:   3 fail-closed invariants (zero external deps)

class EpochSkewViolation(RuntimeError):
    """Raised when a trust-anchor epoch or card issuance time is not covered
    by the resolver's revocation horizon. The identity assertion is unsound
    not because the signature is invalid, but because revocation knowledge
    does not span the trust decision being made."""
    pass


def admit_identity(card, anchor_epoch, horizon_time, prev_anchor_epoch=None):
    """
    card: dict with issued_at (epoch seconds)
    anchor_epoch: dict with effective_at (epoch seconds)
    horizon_time: latest revocation horizon the resolver can observe
    """
    required_coverage = max(anchor_epoch["effective_at"], card["issued_at"])

    if horizon_time >= required_coverage:
        return {"admitted": True, "epoch": anchor_epoch["id"]}

    # Epoch advanced past revocation coverage: try fallback to prior epoch.
    if anchor_epoch["effective_at"] > horizon_time:
        if prev_anchor_epoch and horizon_time >= max(
            prev_anchor_epoch["effective_at"], card["issued_at"]
        ):
            return {"admitted": True, "epoch": prev_anchor_epoch["id"],
                    "fell_back": True}

        raise EpochSkewViolation(
            f"anchor epoch {anchor_epoch['id']} effective_at="
            f"{anchor_epoch['effective_at']} exceeds revocation horizon "
            f"{horizon_time}; trust decision uncovered by revocation knowledge"
        )

    # Card postdates all observable revocations.
    if card["issued_at"] > horizon_time:
        raise EpochSkewViolation(
            f"card issued_at={card['issued_at']} postdates revocation horizon "
            f"{horizon_time}; any revocation against it is invisible"
        )

    raise EpochSkewViolation("uncovered identity assertion")
