TZH-nh/moonwire/packet does not have a README file

    PacketError

    pub(all) suberror PacketError {
    EmptyPacket
    UnknownMessageType(Byte)
    InvalidPacketLength(msg_type~ : Byte, expected~ : Int, actual~ : Int)
    NonZeroReservedBytes
    InvalidFieldLength(field~ : String, expected~ : Int, actual~ : Int)
    InvalidInnerIpPacket(String)
    InvalidIpAddress(String)
    } derive(Eq,
    Debug
    )

    CookieReply

    pub(all) struct CookieReply {
    receiver_index : UInt
    nonce : Bytes
    encrypted_cookie : Bytes
    } derive(Eq,
    Debug
    )

    Type 3: WireGuard Cookie Reply message (64 bytes, §5.4.7).

    CookieReply::encode

    fn CookieReply::encode(self : CookieReply) -> Bytes raise PacketError

    Encode CookieReply into its canonical 64-byte wire format.

    HandshakeInitiation

    pub(all) struct HandshakeInitiation {
    sender_index : UInt
    unencrypted_ephemeral : Bytes
    encrypted_static : Bytes
    encrypted_timestamp : Bytes
    mac1 : Bytes
    mac2 : Bytes
    } derive(Eq,
    Debug
    )

    Type 1: WireGuard Handshake Initiation message (148 bytes, §5.4.2).

    HandshakeInitiation::encode

    fn HandshakeInitiation::encode(self : HandshakeInitiation) -> Bytes raise PacketError

    Encode HandshakeInitiation into its canonical 148-byte wire format.

    HandshakeInitiation::encode_prefix_for_mac1

    fn HandshakeInitiation::encode_prefix_for_mac1(sender_index : UInt, unencrypted_ephemeral : BytesView, encrypted_static : BytesView, encrypted_timestamp : BytesView) -> Bytes

    Encode the 116-byte prefix [0..116) covered by mac1 for HandshakeInitiation.

    HandshakeResponse

    pub(all) struct HandshakeResponse {
    sender_index : UInt
    receiver_index : UInt
    unencrypted_ephemeral : Bytes
    encrypted_nothing : Bytes
    mac1 : Bytes
    mac2 : Bytes
    } derive(Eq,
    Debug
    )

    Type 2: WireGuard Handshake Response message (92 bytes, §5.4.3).

    HandshakeResponse::encode

    fn HandshakeResponse::encode(self : HandshakeResponse) -> Bytes raise PacketError

    Encode HandshakeResponse into its canonical 92-byte wire format.

    HandshakeResponse::encode_prefix_for_mac1

    fn HandshakeResponse::encode_prefix_for_mac1(sender_index : UInt, receiver_index : UInt, unencrypted_ephemeral : BytesView, encrypted_nothing : BytesView) -> Bytes

    Encode the 60-byte prefix [0..60) covered by mac1 for HandshakeResponse.

    InnerIpInfo

    pub(all) struct InnerIpInfo {
    version : Int
    src : IpAddr
    dst : IpAddr
    next_proto : Byte
    total_len : Int
    trimmed_packet : Bytes
    } derive(Eq,
    Debug
    )

    Parsed metadata and padding-trimmed slice of an inner encapsulated IPv4 or IPv6 packet.

    IpAddr

    pub(all) enum IpAddr {
    V4(UInt)
    V6(Bytes)
    } derive(Eq,
    Debug
    )

    Canonical IPv4 or IPv6 network address.
    impl Show for IpAddr

    IpAddr::to_text

    fn IpAddr::to_text(self : IpAddr) -> String

    Format IpAddr into human-readable dotted-quad or colon-hex text.

    TransportData

    pub(all) struct TransportData {
    receiver_index : UInt
    counter : UInt64
    encrypted_packet : Bytes
    } derive(Eq,
    Debug
    )

    Type 4: WireGuard Transport Data message (>= 32 bytes, §5.4.6).

    TransportData::encode

    fn TransportData::encode(self : TransportData) -> Bytes raise PacketError

    Encode TransportData into wire bytes (16-byte header || encrypted_packet).

    WirePacket

    pub(all) enum WirePacket {
    Initiation(HandshakeInitiation)
    Response(HandshakeResponse)
    Cookie(CookieReply)
    Transport(TransportData)
    } derive(Eq,
    Debug
    )

    Parsed WireGuard outer UDP frame.

    WirePacket::encode

    fn WirePacket::encode(self : WirePacket) -> Bytes raise PacketError

    Encode any WirePacket variant into wire bytes.

    AEAD_TAG_LEN

    let AEAD_TAG_LEN : Int

    let COOKIE_REPLY_LEN : Int

    HANDSHAKE_INITIATION_LEN

    let HANDSHAKE_INITIATION_LEN : Int

    HANDSHAKE_RESPONSE_LEN

    let HANDSHAKE_RESPONSE_LEN : Int

    let MSG_COOKIE_REPLY : Byte

    MSG_HANDSHAKE_INITIATION

    let MSG_HANDSHAKE_INITIATION : Byte

    MSG_HANDSHAKE_RESPONSE

    let MSG_HANDSHAKE_RESPONSE : Byte

    MSG_TRANSPORT_DATA

    let MSG_TRANSPORT_DATA : Byte

    TRANSPORT_HEADER_LEN

    let TRANSPORT_HEADER_LEN : Int

    build_ipv4_icmp_echo

    fn build_ipv4_icmp_echo(src_v4 : UInt, dst_v4 : UInt, identifier : Int, sequence : Int, payload : BytesView, is_reply? : Bool) -> Bytes

    Build a standards-compliant IPv4 ICMP Echo Request (icmp_type = 8) or Reply (icmp_type = 0) packet with valid IPv4 header and ICMP checksums for userspace tunnel testing.

    describe_inner_ip

    fn describe_inner_ip(decrypted : BytesView) -> String

    Summarize an inner IP packet into a concise human-readable diagnostic string (e.g., for PCAP inspection).

    inspect_and_trim_inner_ip

    fn inspect_and_trim_inner_ip(decrypted : BytesView) -> InnerIpInfo raise PacketError

    Inspect a decrypted inner WireGuard payload, validate its IPv4/IPv6 header length, strip WireGuard 16-byte block padding, and extract (src, dst, next_proto).

    internet_checksum

    fn internet_checksum(data : BytesView) -> Int

    RFC 1071 16-bit one's complement Internet checksum.

    ipv4

    fn ipv4(a : Byte, b : Byte, c : Byte, d : Byte) -> IpAddr

    Construct IpAddr::V4 from four octets a.b.c.d.

    ipv6_from_bytes

    fn ipv6_from_bytes(raw16 : BytesView) -> IpAddr raise PacketError

    Construct IpAddr::V6 from 16 raw big-endian bytes.

    pad_inner_packet

    fn pad_inner_packet(plaintext : BytesView) -> Bytes

    Pad an inner IP packet with trailing 0x00 bytes to a multiple of 16 bytes (WireGuard §5.4.6).

    parse_ip_addr

    fn parse_ip_addr(text : StringView) -> IpAddr raise PacketError

    Parse an IPv4 (a.b.c.d) or IPv6 (:: compressed or full 8-group hex) address string.

    parse_wire_packet

    fn parse_wire_packet(raw : BytesView, strict_reserved? : Bool) -> WirePacket raise PacketError

    Parse raw UDP datagram bytes into a typed WirePacket. When strict_reserved is true, non-zero reserved bytes [1..4) raise NonZeroReservedBytes.

    read_u16_be

    fn read_u16_be(data : BytesView, offset : Int) -> Int

    write_u16_be

    fn write_u16_be(out : FixedArray[Byte], offset : Int, val : Int) -> Unit

    Source Files