Skip to main content

quic_parser/
error.rs

1/* src/error.rs */
2
3/// Errors that can occur during QUIC packet parsing and decryption.
4#[derive(Debug, thiserror::Error)]
5pub enum Error {
6	/// The input buffer is shorter than required.
7	#[error("buffer too short: need at least {need} bytes, have {have}")]
8	BufferTooShort {
9		/// Minimum number of bytes required.
10		need: usize,
11		/// Actual number of bytes available.
12		have: usize,
13	},
14
15	/// The packet does not have the long header form bit set.
16	#[error("not a QUIC long header packet")]
17	NotLongHeader,
18
19	/// The fixed bit (bit 6) of the first byte is not set to 1.
20	#[error("QUIC fixed bit is not set")]
21	InvalidFixedBit,
22
23	/// The packet is a long header but not an Initial packet.
24	#[error("not an Initial packet (type bits: {0:#04x})")]
25	NotInitialPacket(u8),
26
27	/// A connection ID length field exceeds the protocol maximum of 20 bytes.
28	#[error("connection ID length {0} exceeds maximum of 20")]
29	InvalidCidLength(u8),
30
31	/// The QUIC version is not supported for decryption.
32	#[error("unsupported QUIC version for decryption: {0:#010x}")]
33	UnsupportedVersion(u32),
34
35	/// AEAD decryption or key derivation failed.
36	#[error("decryption failed: {0}")]
37	DecryptionFailed(String),
38
39	/// A CRYPTO frame was truncated before its declared length.
40	#[error("truncated CRYPTO frame at offset {offset}")]
41	TruncatedFrame {
42		/// The byte offset within the decrypted payload where truncation occurred.
43		offset: u64,
44	},
45
46	/// The variable-length integer encoding is malformed.
47	#[error("invalid varint encoding")]
48	InvalidVarint,
49}