diff --git a/quinn-proto/src/lib.rs b/quinn-proto/src/lib.rs index def4168ed8..98cb7de93e 100644 --- a/quinn-proto/src/lib.rs +++ b/quinn-proto/src/lib.rs @@ -31,7 +31,10 @@ mod cid_queue; #[doc(hidden)] pub mod coding; mod constant_time; + mod packet; +pub use packet::{LongType, PacketDecodeError, PartialDecode, PlainHeader, PlainInitialHeader}; + mod range_set; #[cfg(all(test, feature = "rustls"))] mod tests; diff --git a/quinn-proto/src/packet.rs b/quinn-proto/src/packet.rs index 4d741862d7..c44c961832 100644 --- a/quinn-proto/src/packet.rs +++ b/quinn-proto/src/packet.rs @@ -22,7 +22,6 @@ use crate::{ /// across QUIC versions), which gives us the destination CID and allows us /// to inspect the version and packet type (which depends on the version). /// This information allows us to fully decode and decrypt the packet. -#[allow(unreachable_pub)] // fuzzing only #[cfg_attr(test, derive(Clone))] #[derive(Debug)] pub struct PartialDecode { @@ -100,7 +99,8 @@ impl PartialDecode { } } - pub(crate) fn dst_cid(&self) -> &ConnectionId { + /// The destination connection ID of the packet + pub fn dst_cid(&self) -> &ConnectionId { self.plain_header.dst_cid() } @@ -490,8 +490,10 @@ impl PartialEncode { } } +/// Plain header of a packet #[derive(Clone, Debug)] -pub(crate) enum PlainHeader { +#[allow(missing_docs)] +pub enum PlainHeader { Initial(PlainInitialHeader), Long { ty: LongType, @@ -501,7 +503,9 @@ pub(crate) enum PlainHeader { version: u32, }, Retry { + /// Destination Connection ID dst_cid: ConnectionId, + /// Source Connection ID src_cid: ConnectionId, version: u32, }, @@ -517,14 +521,15 @@ pub(crate) enum PlainHeader { } impl PlainHeader { - pub(crate) fn as_initial(&self) -> Option<&PlainInitialHeader> { + fn as_initial(&self) -> Option<&PlainInitialHeader> { match self { Self::Initial(x) => Some(x), _ => None, } } - fn dst_cid(&self) -> &ConnectionId { + /// The destination Connection ID of the packet. + pub fn dst_cid(&self) -> &ConnectionId { use self::PlainHeader::*; match self { Initial(header) => &header.dst_cid, @@ -622,13 +627,19 @@ impl PlainHeader { } } +/// A Plain QUIC Header #[derive(Clone, Debug)] -pub(crate) struct PlainInitialHeader { - pub(crate) dst_cid: ConnectionId, - pub(crate) src_cid: ConnectionId, - pub(crate) token_pos: Range, - pub(crate) len: u64, - pub(crate) version: u32, +pub struct PlainInitialHeader { + /// Destination Connection ID + pub dst_cid: ConnectionId, + /// Source Connection ID + pub src_cid: ConnectionId, + /// The position of a token in the packet buffer + pub token_pos: Range, + /// Length of the packet payload + pub len: u64, + /// QUIC version + pub version: u32, } #[derive(Clone, Debug)] @@ -779,20 +790,27 @@ impl From for u8 { /// Long packet types with uniform header structure #[derive(Clone, Copy, Debug, Eq, PartialEq)] -pub(crate) enum LongType { +pub enum LongType { + /// Long header type for Handshake packets Handshake, + /// Long header type for 0-RTT packets ZeroRtt, } -#[allow(unreachable_pub)] // fuzzing only #[derive(Debug, Error, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] +/// Packet decode error pub enum PacketDecodeError { + /// The packet uses a QUIC version that is not supported #[error("unsupported version {version:x}")] UnsupportedVersion { + /// The source connection ID src_cid: ConnectionId, + /// The destination connection ID dst_cid: ConnectionId, + /// The version that was not supported version: u32, }, + /// The header of the packet is invalid #[error("invalid header: {0}")] InvalidHeader(&'static str), }