tiny.quic.packet
Defined in tiny.quic.
API (23)
Actions
Public operations.
ConnectionId.initConnectionId.sliceLong.packetNumberOffsetVersionIterator.nextVersionNegotiation.iteratordecodeLongdecodeShortencodeLongencodeShortpacketNumberLength
Types and contracts
Public types and contracts.
CommonConnectionId: A 20-byte array with the count of bytes in use holds the identifier a packet header carries, the connection ID.DecodeErrorEncodeErrorInitialLongNumberProtectedRetryShortVersionIteratorVersionNegotiation
Values and defaults
Public values and defaults.
Source
Source: lib/quic/src/packet/model.zig:32
pub const Common = struct { first: u8, version: u32, destination: ConnectionId, source: ConnectionId,};Source: lib/quic/src/packet/model.zig:12
/// A 20-byte array with the count of bytes in use holds the identifier a packet header carries, the/// connection ID. A caller reads one out of a decoded header, or builds one to encode, and passes/// it by value. RFC 9000 section 17.2 bounds a version 1 connection ID at 20 bytes, so the array/// holds every legal value and the value copies without touching an allocator. Building one from a/// longer slice gives `ConnectionIdTooLong`. The bytes past the length are zero, and `slice`/// returns the bytes in use.pub const ConnectionId = struct { bytes: ConnectionIdBytes, length: u5, pub fn init(input: []const u8) error{ConnectionIdTooLong}!ConnectionId { if (input.len > connection_id_bytes_max) return error.ConnectionIdTooLong; var result = ConnectionId{ .bytes = @splat(0), .length = @intCast(input.len), }; @memcpy(result.bytes[0..input.len], input); return result; } pub fn slice(self: *const ConnectionId) []const u8 { std.debug.assert(self.length <= connection_id_bytes_max); return self.bytes[0..self.length]; }};Source: lib/quic/src/packet/model.zig:39
pub const Initial = struct { common: Common, token: []const u8, length: u62, packet_number_offset: usize,};Source: lib/quic/src/packet/model.zig:81
pub const Long = union(enum) { initial: Initial, zero_rtt: Protected, handshake: Protected, retry: Retry, version_negotiation: VersionNegotiation, pub fn packetNumberOffset(self: Long) ?usize { return switch (self) { .initial => |value| value.packet_number_offset, .zero_rtt, .handshake => |value| value.packet_number_offset, .retry, .version_negotiation => null, }; }};Source: lib/quic/src/packet/model.zig:46
pub const Protected = struct { common: Common, length: u62, packet_number_offset: usize,};Source: lib/quic/src/packet/model.zig:52
pub const Retry = struct { common: Common, token: []const u8, integrity_tag: [16]u8,};Source: lib/quic/src/packet/model.zig:97
pub const Short = struct { first: u8, destination: ConnectionId, packet_number_offset: usize,};Source: lib/quic/src/packet/model.zig:67
pub const VersionIterator = struct { bytes: []const u8, index: usize, pub fn next(self: *VersionIterator) ?u32 { std.debug.assert(self.index <= self.bytes.len); if (self.index == self.bytes.len) return null; std.debug.assert(self.bytes.len - self.index >= 4); const value = std.mem.readInt(u32, self.bytes[self.index..][0..4], .big); self.index += 4; return value; }};Source: lib/quic/src/packet/model.zig:58
pub const VersionNegotiation = struct { common: Common, versions: []const u8, pub fn iterator(self: VersionNegotiation) VersionIterator { return .{ .bytes = self.versions, .index = 0 }; }};Source: lib/quic/src/packet/header.zig:25
pub const DecodeError = cursor.ReadError || varint.DecodeError || DecodeSpecific;Source: lib/quic/src/packet/header.zig:26
pub const EncodeError = cursor.WriteError || varint.EncodeError || EncodeSpecific;Source: lib/quic/src/packet/header.zig:94
pub fn decodeLong(bytes: []const u8) DecodeError!model.Long { var input = cursor.Read.init(bytes); const first = try input.byte(); if (first & 0x80 == 0) return error.InvalidHeader; const version = try input.int(u32); const common = try readCommon(&input, first, version); if (version == 0) return decodeVersionNegotiation(&input, common); if (version != 1) return error.UnsupportedVersion; if (first & 0x40 == 0) return error.InvalidHeader; return switch ((first >> 4) & 0x03) { 0 => decodeInitial(&input, common), 1 => .{ .zero_rtt = try decodeProtected(&input, common) }, 2 => .{ .handshake = try decodeProtected(&input, common) }, 3 => decodeRetry(&input, common), else => unreachable, };}Source: lib/quic/src/packet/header.zig:168
pub fn decodeShort(bytes: []const u8, destination_length: u5) DecodeError!model.Short { if (destination_length > model.connection_id_bytes_max) { return error.ConnectionIdTooLong; } var input = cursor.Read.init(bytes); const first = try input.byte(); if (first & 0x80 != 0) return error.InvalidHeader; if (first & 0x40 == 0) return error.InvalidHeader; const destination = model.ConnectionId.init(try input.take(destination_length)) catch return error.ConnectionIdTooLong; return .{ .first = first, .destination = destination, .packet_number_offset = input.index, };}Source: lib/quic/src/packet/header.zig:139
pub fn encodeLong(value: model.Long, output: *cursor.Write) EncodeError!void { switch (value) { .version_negotiation => |packet| { if (packet.common.version != 0) return error.InvalidHeader; if (packet.versions.len == 0) return error.InvalidVersionList; if (packet.versions.len % 4 != 0) return error.InvalidVersionList; try writeCommon(packet.common, output); try output.put(packet.versions); }, .initial => |packet| { try validateVersionOne(packet.common, 0); if (packet.length == 0) return error.InvalidLength; try writeCommon(packet.common, output); _ = try varint.write(@intCast(packet.token.len), output); try output.put(packet.token); _ = try varint.write(packet.length, output); }, .zero_rtt => |packet| try writeProtected(packet, 1, output), .handshake => |packet| try writeProtected(packet, 2, output), .retry => |packet| { try validateVersionOne(packet.common, 3); if (packet.token.len == 0) return error.InvalidRetry; try writeCommon(packet.common, output); try output.put(packet.token); try output.put(&packet.integrity_tag); }, }}Source: lib/quic/src/packet/header.zig:185
pub fn encodeShort(value: model.Short, output: *cursor.Write) EncodeError!void { if (value.first & 0x80 != 0) return error.InvalidHeader; if (value.first & 0x40 == 0) return error.InvalidHeader; try output.byte(value.first); try output.put(value.destination.slice());}Source: lib/quic/src/packet/header.zig:192
pub fn packetNumberLength(first: u8) u3 { return @as(u3, @intCast(first & 0x03)) + 1;}Source: lib/quic/src/packet/model.zig:3
pub const connection_id_bytes_max: u5 = 20;Source: lib/quic/src/packet/root.zig
const header = @import("header.zig");const model = @import("model.zig");const number = @import("number.zig");pub const connection_id_bytes_max = model.connection_id_bytes_max;pub const ConnectionId = model.ConnectionId;pub const Common = model.Common;pub const Initial = model.Initial;pub const Protected = model.Protected;pub const Retry = model.Retry;pub const VersionNegotiation = model.VersionNegotiation;pub const VersionIterator = model.VersionIterator;pub const Long = model.Long;pub const Short = model.Short;pub const Number = struct { pub const Truncated: type = number.Truncated; pub const truncate = number.truncate; pub const expand = number.expand;};pub const DecodeError = header.DecodeError;pub const EncodeError = header.EncodeError;pub const decodeLong = header.decodeLong;pub const encodeLong = header.encodeLong;pub const decodeShort = header.decodeShort;pub const encodeShort = header.encodeShort;pub const packetNumberLength = header.packetNumberLength;Source: lib/quic/src/root.zig:48
pub const packet = @import("packet/root.zig");Complete call list for packet.decodeLong
8 direct calls.
tiny.quic.cursor.Read.byte[method] atlib/quic/src/cursor.zig:28tiny.quic.cursor.Read.init[function] atlib/quic/src/cursor.zig:10tiny.quic.cursor.Read.int[method] atlib/quic/src/cursor.zig:32lib.quic.src.packet.header.decodeInitial[function] — private source atlib/quic/src/packet/header.zig:59in nearest public ownerlib.quic.src.packet.headerlib.quic.src.packet.header.decodeProtected[function] — private source atlib/quic/src/packet/header.zig:72in nearest public ownerlib.quic.src.packet.headerlib.quic.src.packet.header.decodeRetry[function] — private source atlib/quic/src/packet/header.zig:82in nearest public ownerlib.quic.src.packet.headerlib.quic.src.packet.header.decodeVersionNegotiation[function] — private source atlib/quic/src/packet/header.zig:49in nearest public ownerlib.quic.src.packet.headerlib.quic.src.packet.header.readCommon[function] — private source atlib/quic/src/packet/header.zig:35in nearest public ownerlib.quic.src.packet.header
Audit
| Definitions | 23 |
|---|---|
| Public names | 23 |
| Members | 28 |
| Version | 26.7.0 |
| Revision | daab053ee433 |