net_wire/quic/builder/
mod.rs1use core::fmt;
4
5use super::packet::header::{QuicConnectionIdField, QuicVersion};
6use super::varint::QuicVarIntBuildError;
7
8mod long;
9mod short;
10mod terminal;
11
12#[derive(Clone, Copy, Debug, Eq, PartialEq)]
14pub enum QuicPacketBuildField {
15 TokenLength,
17 ProtectedLength,
19}
20
21#[derive(Clone, Copy, Debug, Eq, PartialEq)]
23pub enum QuicPacketBuildError {
24 UnusedBitsOutOfRange {
26 maximum: u8,
28 actual: u8,
30 },
31 ProtectedLowBitsOutOfRange {
33 maximum: u8,
35 actual: u8,
37 },
38 UnsupportedVersion {
40 version: QuicVersion,
42 },
43 ConnectionIdTooLong {
45 field: QuicConnectionIdField,
47 maximum: usize,
49 actual: usize,
51 },
52 EmptyVersionList,
54 EmptyRetryToken,
56 ProtectedRemainderTooShort {
58 minimum: usize,
60 actual: usize,
62 },
63 VarInt {
65 field: QuicPacketBuildField,
67 error: QuicVarIntBuildError,
69 },
70 LengthOverflow {
72 component: &'static str,
74 offset: usize,
76 length: usize,
78 },
79 BufferTooShort {
81 required: usize,
83 available: usize,
85 },
86}
87
88impl fmt::Display for QuicPacketBuildError {
89 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
90 match self {
91 Self::UnusedBitsOutOfRange { maximum, actual } => write!(
92 f,
93 "QUIC unused bits value {actual:#04x} exceeds maximum {maximum:#04x}"
94 ),
95 Self::ProtectedLowBitsOutOfRange { maximum, actual } => write!(
96 f,
97 "QUIC protected low bits value {actual:#04x} exceeds maximum {maximum:#04x}"
98 ),
99 Self::UnsupportedVersion { version } => write!(
100 f,
101 "QUIC packet construction does not support version {:#010x}",
102 version.raw()
103 ),
104 Self::ConnectionIdTooLong {
105 field,
106 maximum,
107 actual,
108 } => write!(
109 f,
110 "QUIC {field:?} connection ID length {actual} exceeds maximum {maximum}"
111 ),
112 Self::EmptyVersionList => write!(
113 f,
114 "QUIC Version Negotiation construction requires a nonempty version list"
115 ),
116 Self::EmptyRetryToken => {
117 write!(f, "QUIC Retry construction requires a nonempty Retry Token")
118 }
119 Self::ProtectedRemainderTooShort { minimum, actual } => write!(
120 f,
121 "QUIC protected packet remainder is too short: need at least {minimum} bytes, have {actual}"
122 ),
123 Self::VarInt { field, error } => {
124 write!(f, "QUIC {field:?} field cannot be encoded: {error}")
125 }
126 Self::LengthOverflow {
127 component,
128 offset,
129 length,
130 } => write!(
131 f,
132 "QUIC packet size overflows while adding {component}: offset {offset} plus length {length}"
133 ),
134 Self::BufferTooShort {
135 required,
136 available,
137 } => write!(
138 f,
139 "QUIC packet destination is too short: need {required} bytes, have {available}"
140 ),
141 }
142 }
143}
144
145pub use long::{QuicHandshakePacketBuilder, QuicInitialPacketBuilder, QuicZeroRttPacketBuilder};
146pub use short::QuicShortPacketBuilder;
147pub use terminal::{QuicRetryPacketBuilder, QuicVersionNegotiationPacketBuilder};