Package io.github.mahmoudimus.quic.token
Class Token
java.lang.Object
io.github.mahmoudimus.quic.token.Token
An address validation token: a payload and a random nonce. On the wire it is the payload sealed
with a one-time key derived from the nonce, followed by the 16-byte nonce in the clear.
type (1) | address: family (1), 4 or 16 bytes [, port (2) for Retry]
| [original DCID: length (1), bytes, for Retry] | issued, Unix seconds (8)
Immutable.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Tokencreate(TokenPayload payload, RandomGenerator random) A token with a fresh random nonce.static TokenOpens and decodes a token.byte[]Encodes and seals the token.byte[]nonce()The token's nonce, visible to the client.payload()What the token says.
-
Field Details
-
NONCE_LENGTH
public static final int NONCE_LENGTHThe nonce length, in bytes.- See Also:
-
-
Constructor Details
-
Token
A token.- Parameters:
payload- what the token saysnonce- a unique random value of 16 bytes
-
-
Method Details
-
create
A token with a fresh random nonce.- Parameters:
payload- what the token saysrandom- the source of randomness; aSecureRandomoutside tests- Returns:
- the token
-
payload
What the token says.- Returns:
- the payload
-
nonce
public byte[] nonce()The token's nonce, visible to the client.- Returns:
- a copy
-
encode
Encodes and seals the token.- Parameters:
key- the server's token key- Returns:
- the token as sent to the client
-
decode
Opens and decodes a token.- Parameters:
key- the server's token keyraw- the token from the client- Returns:
- the token, or null if it does not authenticate or decode, as for a token from another server or version
-