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 packet is a long header but not an Initial packet.
20	#[error("not an Initial packet (type bits: {0:#04x})")]
21	NotInitialPacket(u8),
22
23	/// A connection ID length field exceeds the protocol maximum of 20 bytes.
24	#[error("connection ID length {0} exceeds maximum of 20")]
25	InvalidCidLength(u8),
26
27	/// The QUIC version is not supported for decryption.
28	#[error("unsupported QUIC version for decryption: {0:#010x}")]
29	UnsupportedVersion(u32),
30
31	/// AEAD decryption or key derivation failed.
32	#[error("decryption failed: {0}")]
33	DecryptionFailed(String),
34
35	/// A CRYPTO frame was truncated before its declared length.
36	#[error("truncated CRYPTO frame at offset {offset}")]
37	TruncatedFrame {
38		/// The byte offset within the decrypted payload where truncation occurred.
39		offset: u64,
40	},
41
42	/// The variable-length integer encoding is malformed.
43	#[error("invalid varint encoding")]
44	InvalidVarint,
45}