Class PacketProtection
java.lang.Object
io.github.mahmoudimus.quic.packet.PacketProtection
Applies packet protection (RFC 9001 section 5) to an encoded packet in place: fills in the
Length field, seals the payload and then masks the header. Removing protection is
ProtectedPacket.unprotect(io.github.mahmoudimus.quic.crypto.DirectionalKeys, long).
All methods are static; thread confinement follows from the keys passed in.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe longest long header packet, from the packet number to the end of the tag, that the two-byte Length field this module writes can describe. -
Method Summary
Modifier and TypeMethodDescriptionstatic intminPayloadLength(int packetNumberLength) The fewest payload bytes a packet needs so that the header protection sample, which starts four bytes after the packet number, lies within the ciphertext and tag.static intprotect(ByteBuffer packet, HeaderLayout layout, int payloadEnd, long packetNumber, DirectionalKeys keys) Protects an encoded packet in place.
-
Field Details
-
MAX_LONG_PACKET_REMAINDER
public static final int MAX_LONG_PACKET_REMAINDERThe longest long header packet, from the packet number to the end of the tag, that the two-byte Length field this module writes can describe.- See Also:
-
-
Method Details
-
minPayloadLength
public static int minPayloadLength(int packetNumberLength) The fewest payload bytes a packet needs so that the header protection sample, which starts four bytes after the packet number, lies within the ciphertext and tag.- Parameters:
packetNumberLength- the packet number length, 1 to 4- Returns:
- the minimum plaintext payload length
-
protect
public static int protect(ByteBuffer packet, HeaderLayout layout, int payloadEnd, long packetNumber, DirectionalKeys keys) Protects an encoded packet in place. The header was written byPacketHeader.encode(java.nio.ByteBuffer)atlayout, followed by the plaintext payload up topayloadEnd; the buffer needs 16 bytes of capacity after it for the tag. Indexes are absolute; the buffer's position and limit are not changed.- Parameters:
packet- the packet bufferlayout- where the header's fields arepayloadEnd- the index just past the plaintext payloadpacketNumber- the full packet number in the headerkeys- the sender's keys for the packet's level- Returns:
- the index just past the protected packet
- Throws:
IllegalArgumentException- if the payload is shorter thanminPayloadLength(int)or too long for the Length field, or the header is not a protected one
-