quic_address_token (quic v1.6.2)

View Source

Summary

Functions

Decode a token envelope. Returns the kind, bound address, timestamp, and (for retries) the original DCID. Signature is NOT verified here; callers pass the result through validate/3.

Encode a NEW_TOKEN for a client address.

Encode a retry token binding a client address, timestamp, and the original DCID from the Initial that triggered the retry.

Validate a decoded token: the signature must match (checked in decode/2) and the timestamp must be within max_age_ms of now. The address is checked by the listener against the current source. The retry token's ODCID is NOT compared here — it carries the client's original DCID so the server can recover it for the original_destination_connection_id transport param (RFC 9000 §7.3), not to be matched against the retried Initial's DCID.

Types

addr/0

-type addr() :: {inet:ip_address(), inet:port_number()}.

kind/0

-type kind() :: retry | new_token.

Functions

decode(Secret, Token)

-spec decode(binary(), binary()) ->
                {ok,
                 #{kind := kind(),
                   addr := addr(),
                   ts := non_neg_integer(),
                   odcid := binary() | undefined}} |
                {error, term()}.

Decode a token envelope. Returns the kind, bound address, timestamp, and (for retries) the original DCID. Signature is NOT verified here; callers pass the result through validate/3.

encode_new_token(Secret, Addr, Ts)

-spec encode_new_token(binary(), addr(), non_neg_integer()) -> binary().

Encode a NEW_TOKEN for a client address.

encode_retry(Secret, Addr, ODCID, Ts)

-spec encode_retry(binary(), addr(), binary(), non_neg_integer()) -> binary().

Encode a retry token binding a client address, timestamp, and the original DCID from the Initial that triggered the retry.

validate(_, Opts)

-spec validate(map(), #{max_age_ms => non_neg_integer()}) -> ok | {error, term()}.

Validate a decoded token: the signature must match (checked in decode/2) and the timestamp must be within max_age_ms of now. The address is checked by the listener against the current source. The retry token's ODCID is NOT compared here — it carries the client's original DCID so the server can recover it for the original_destination_connection_id transport param (RFC 9000 §7.3), not to be matched against the retried Initial's DCID.