Skip to main content

iris_core/protocols/stream/quic/
header.rs

1//! Quic header types
2
3use serde::Serialize;
4
5use crate::protocols::stream::quic::QuicError;
6
7/// Quic Long Header
8#[derive(Debug, Serialize, Clone)]
9pub struct QuicLongHeader {
10    pub packet_type: LongHeaderPacketType,
11    pub type_specific: u8,
12    pub version: u32,
13    pub dcid_len: u8,              // length of dcid in bytes
14    pub dcid: String,              // hex string
15    pub scid_len: u8,              // length of scid in bytes
16    pub scid: String,              // hex string
17    pub token_len: Option<u64>,    // length of token in bytes, if packet is of type Init or Retry
18    pub token: Option<String>,     // hex string, if packet is of type Init or Retry
19    pub retry_tag: Option<String>, // hex string, if packet is of type Retry
20}
21
22/// Quic Short Header
23#[derive(Debug, Serialize, Clone)]
24pub struct QuicShortHeader {
25    pub dcid: Option<String>, // optional. If not pre-existing cid then none.
26}
27
28// Long Header Packet Types from RFC 9000 Table 5
29#[derive(Debug, Clone, Serialize, Copy)]
30pub enum LongHeaderPacketType {
31    Initial,
32    ZeroRTT,
33    Handshake,
34    Retry,
35}
36
37impl LongHeaderPacketType {
38    pub fn from_u8(value: u8) -> Result<LongHeaderPacketType, QuicError> {
39        match value {
40            0x00 => Ok(LongHeaderPacketType::Initial),
41            0x01 => Ok(LongHeaderPacketType::ZeroRTT),
42            0x02 => Ok(LongHeaderPacketType::Handshake),
43            0x03 => Ok(LongHeaderPacketType::Retry),
44            _ => Err(QuicError::UnknowLongHeaderPacketType),
45        }
46    }
47}