Skip to main content

PacketHeader

Struct PacketHeader 

Source
#[repr(C)]
pub struct PacketHeader { pub version: u8, pub session_id: SessionId, pub stream_id: StreamId, pub packet_number: PacketNumber, pub flags: PacketFlags, pub epoch: u8, pub path_id: u8, }
Available on crate feature std only.
Expand description

Packet header — 15 bytes on the wire (PacketHeader::SIZE); the AEAD AAD is the separate, larger 47-byte image (PacketHeader::AAD_SIZE).

Serialised by PacketHeader::to_wire as an explicit, fixed big-endian (network byte order) image, version first (no serialization library). The WIRE v6 (anti-fingerprint) wire layout is a contiguous 15-byte span, the WHOLE of which is HP-masked on the wire (HP_PROTECTED_OFFSET = 0 — no constant cleartext byte). The 32-byte session_id is off-wire: it is a struct field bound into the AEAD AAD but never transmitted (dropped from the wire in v5 / the ε CID collapse), reconstructed by the receiver from session context.

off  0  version        u8       (= WIRE_VERSION = 6)            HP-MASKED ┐
off  1  packet_number  u64 be   (① per-direction monotonic)    HP-MASKED │
off  9  flags          u16 be                                  HP-MASKED │ [0..15]
off 11  stream_id      u16 be                                  HP-MASKED │
off 13  epoch          u8                                      HP-MASKED │
off 14  path_id        u8                                      HP-MASKED ┘

The 47-byte AEAD AAD image (Self::to_aad_image) is the cleartext header reconstructed off-wire (it additionally binds the off-wire session_id), so flipping any authenticated byte (version / session_id included) fails decryption. On the wire the whole [0..15] span is XOR-masked by the per-session HeaderProtector (a wire mutation of the masked region unmasks to a wrong header → wrong AAD → AEAD fails — no new oracle); the recv path reconstructs the cleartext header via RawPacket::unmask_header before computing the AAD. epoch/stream_id/path_id are authenticated in the AAD but NOT in the nonce (which is prefix‖packet_number). The recv path also drops a frame whose version != WIRE_VERSION. Frozen by core/tests/wire_vectors/packet_header.bin; grammar in docs/protocol/PROTOCOL.md § 4.2.

Fields§

§version: u8

On-wire packet-format version. Pinned to WIRE_VERSION; the first wire byte (see PacketHeader::to_wire).

§session_id: SessionId

256-bit session identifier, used as encryption salt

§stream_id: StreamId

Stream within session (0 = control)

§packet_number: PacketNumber

Per-direction monotonic AEAD packet number (① — Phase 4). Feeds the AEAD nonce and the per-direction replay window; assigned at send time.

§flags: PacketFlags

Packet flags

§epoch: u8

Rekey generation. Zero at session establishment, incremented in lock- step on each in-band rekey (Phase 1.5).

§path_id: u8

Connection-migration path identifier (Phase 4.2). 0 = the implicit, always-validated handshake path; bumped per migrate() so the peer challenges the new path.

Implementations§

Source§

impl PacketHeader

Source

pub const SIZE: usize = 15

On-wire header size in bytes (ε / WIRE v5: version(1) + the 14 HP-masked fields; session_id is off-wire). The AEAD AAD is the larger Self::AAD_SIZE image (which still binds session_id).

Source

pub const AAD_SIZE: usize = 47

Size of the AEAD AAD header image: the byte-identical 47-byte v4 logical header (version ‖ session_id ‖ packet_number ‖ flags ‖ stream_id ‖ epoch ‖ path_id), reconstructed off-wire by Self::to_aad_image. Kept at 47 so the v4 AEAD security argument carries over unchanged (design §2.2).

Source

pub fn new( session_id: SessionId, stream_id: StreamId, packet_number: PacketNumber, flags: PacketFlags, ) -> Self

Create a new packet header (version = WIRE_VERSION, epoch = 0, path_id = 0).

Source

pub fn with_epoch(self, epoch: u8) -> Self

Set the rekey epoch — used by Session::rekey (Phase 1.5).

Source

pub fn with_path_id(self, path_id: u8) -> Self

Set the path id — stamped by the connection-migration path machinery (Phase 4.2; 0 = the implicit handshake path).

Source

pub fn to_wire(&self) -> [u8; 15]

Serialise to the fixed 15 on-wire bytes (big-endian, version first; ε / WIRE v5). session_id is not emitted — it is off-wire and lives only in the AEAD AAD (Self::to_aad_image) and the session context.

Source

pub fn to_aad_image(&self) -> [u8; 47]

The AEAD AAD image: the byte-identical 47-byte v4 logical header (version ‖ session_id ‖ packet_number ‖ flags ‖ stream_id ‖ epoch ‖ path_id). session_id is off-wire, so the data plane reconstructs it from the session context (Session::id) into self.session_id before computing the AAD; this keeps the AEAD binding (and its security argument) byte-identical to v4 (design §2.2).

Source

pub fn from_wire(bytes: &[u8]) -> Result<Self, WireError>

Parse a header from the first Self::SIZE (= 15) bytes of bytes. Does not validate version — the recv path gates on it separately. session_id is off-wire (ε / WIRE v5): it is left the placeholder zero here and set by Session::parse_protected from the routed session context.

Trait Implementations§

Source§

impl Clone for PacketHeader

Source§

fn clone(&self) -> PacketHeader

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for PacketHeader

Source§

impl Debug for PacketHeader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for PacketHeader

Source§

impl PartialEq for PacketHeader

Source§

fn eq(&self, other: &PacketHeader) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for PacketHeader

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> CompatExt for T

Source§

fn compat(self) -> Compat<T>
where T: Sized,

Applies the Compat adapter by value. Read more
Source§

fn compat_ref(&self) -> Compat<&T>

Applies the Compat adapter by shared reference. Read more
Source§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the Compat adapter by mutable reference. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

Source§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
Source§

unsafe fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
Source§

unsafe fn consume_handle(handle: Handle) -> Arc<T>

Consume a handle, getting back the initial Arc<> Read more
Source§

unsafe fn get_arc(handle: Handle) -> Arc<Self>

Get a clone of the Arc<> using a “borrowed” handle. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more