# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/which-invariants-prevent-stale-agent-card-signatures-from-surviving-registry-revocation-in-federated-a2a-v1-0-meshes.md
# Remnant Warrant:    https://corpusfetch.com/c/which-invariants-prevent-stale-agent-card-signatures-from-surviving-registry-revocation-in-federated-a2a-v1-0-meshes.warrant.json
# Markdown SHA-256:   b97bb57588e7672285ad4531f21b94af4c219075644193aab3db5e34ba41c96c
# Code AST SHA-256:   a0532708463e7a29d9cf1543d0731d99d5765bff847152a2942ce1e17907b70e
# Verified Classes:   Verdict, AgentCardVerificationError, AgentCard, RevocationList
# Defensive Guards:   2 fail-closed invariants (zero external deps)

from dataclasses import dataclass
from enum import Enum

class Verdict(Enum):
    ACCEPT = "accept"
    REJECT = "reject"
    INDETERMINATE = "indeterminate"

class AgentCardVerificationError(RuntimeError):
    pass

@dataclass(frozen=True)
class AgentCard:
    agent_id: str
    issuer_key: str
    issued_at: int
    not_after: int

@dataclass(frozen=True)
class RevocationList:
    version: int
    revoked_keys: frozenset
    coverage_start: int
    coverage_end: int
    next_update: int

def verify_card(card: AgentCard, rl: RevocationList, now: int) -> Verdict:
    # Freshness of both artifacts.
    if now > card.not_after:
        return Verdict.REJECT
    if now > rl.next_update:
        # Stale RL is unverified, not a weak "no".
        return Verdict.INDETERMINATE

    # Epoch binding: the RL must actually cover the card's issuance epoch.
    if card.issued_at > rl.coverage_end or card.issued_at < rl.coverage_start:
        # Vacuous negative: "not revoked" says nothing about this card.
        return Verdict.INDETERMINATE

    if card.issuer_key in rl.revoked_keys:
        return Verdict.REJECT
    return Verdict.ACCEPT

def delegate_warrant(card: AgentCard, rl: RevocationList, now: int,
                     refresh_rl) -> Verdict:
    verdict = verify_card(card, rl, now)
    if verdict is Verdict.INDETERMINATE:
        fresh = refresh_rl(authoritative=True)
        verdict = verify_card(card, fresh, now)
        if verdict is Verdict.INDETERMINATE:
            raise AgentCardVerificationError(
                f"cannot bound revocation state for {card.agent_id} "
                f"at issuance {card.issued_at}; RL v{fresh.version} "
                f"covers [{fresh.coverage_start},{fresh.coverage_end}]"
            )
    if verdict is Verdict.REJECT:
        raise AgentCardVerificationError(
            f"key {card.issuer_key} revoked for card {card.agent_id}"
        )
    return verdict
