# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-a-peer-s-verifiable-credential-as-revoked-when-revocation-state-propagates-asynchronously-across-domains.md
# Remnant Warrant:    https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-a-peer-s-verifiable-credential-as-revoked-when-revocation-state-propagates-asynchronously-across-domains.warrant.json
# Markdown SHA-256:   8af71d11ced0230f1aebfa918a3605e7bf2b4de6f0abc07ae8b4dcec2ff7da46
# Code AST SHA-256:   fb77112bc6761f9e9ddc4debf9b8f9c7a57b89b63e5505b5f604e7bb860d98f1
# Verified Classes:   RevocationBlindZoneError, StatusList, Credential
# Defensive Guards:   3 fail-closed invariants (zero external deps)

import time
from dataclasses import dataclass


class RevocationBlindZoneError(RuntimeError):
    """Raised when a credential is inside its revocation-propagation blind zone
    and therefore cannot be trusted for a cross-domain handoff, even though it
    is unexpired and locally reported as unrevoked."""


@dataclass
class StatusList:
    valid_from: float
    last_successful_sync: float
    revoked_indices: frozenset


@dataclass
class Credential:
    subject: str
    exp: float
    status_index: int


def assert_cross_domain_trustworthy(
    cred: Credential,
    status: StatusList,
    issuer_max_propagation_delay: float,
    hard_ttl: float,
    now: float,
) -> None:
    # 1. Cryptographic/expiry sanity (assumed checked upstream); here we only
    #    enforce the propagation-boundary invariant.
    if cred.status_index in status.revoked_indices:
        raise RevocationBlindZoneError(
            f"credential for {cred.subject} is explicitly revoked"
        )

    # 2. Hard TTL on the status list. Soft-fail tolerance is NOT consulted here:
    #    a stale list may keep a same-domain session alive but cannot authorize
    #    a new cross-domain handoff.
    if now - status.last_successful_sync > hard_ttl:
        raise RevocationBlindZoneError(
            f"status list for {cred.subject} exceeded hard TTL "
            f"({now - status.last_successful_sync:.0f}s > {hard_ttl:.0f}s); "
            f"cross-domain authority withheld"
        )

    # 3. Blind-zone rule: the last max_propagation_delay seconds of the
    #    credential's life are treated as already expired for cross-domain use,
    #    because a revocation issued inside that window cannot yet be observed.
    if now > cred.exp - issuer_max_propagation_delay:
        raise RevocationBlindZoneError(
            f"credential for {cred.subject} is inside its revocation blind zone "
            f"(now={now:.0f}, exp={cred.exp:.0f}, "
            f"propagation_delay={issuer_max_propagation_delay:.0f}); "
            f"refusing cross-domain handoff despite unrevoked status"
        )
