Skip to main content

SphinxOnionCodec

Trait SphinxOnionCodec 

Source
pub trait SphinxOnionCodec {
    type Decoded;
    type Current;

    const PACKET_DATA_LEN: usize;
    const CURRENT_VERSION: u8;

    // Required methods
    fn pack(decoded: &Self::Decoded) -> Vec<u8> ;
    fn unpack(version: u8, buf: &[u8]) -> Option<Self::Decoded>;
    fn to_current(decoded: Self::Decoded) -> Self::Current;
    fn is_version_allowed(version: u8) -> bool;
    fn hop_data_len(version: u8, buf: &[u8]) -> Option<usize>;
}
Expand description

Trait for encoding/decoding Sphinx onion packet hop data.

This trait abstracts over different onion packet formats (payment vs trampoline), allowing the generic peel_sphinx_onion and create_sphinx_onion functions to work with any format.

Required Associated Constants§

Source

const PACKET_DATA_LEN: usize

Source

const CURRENT_VERSION: u8

The onion packet version used when creating new packets.

Required Associated Types§

Required Methods§

Source

fn pack(decoded: &Self::Decoded) -> Vec<u8>

Packs the decoded data for transmission. Must use CURRENT_VERSION format.

Source

fn unpack(version: u8, buf: &[u8]) -> Option<Self::Decoded>

Unpacks data received from the network. Must handle all versions allowed by is_version_allowed.

Source

fn to_current(decoded: Self::Decoded) -> Self::Current

Source

fn is_version_allowed(version: u8) -> bool

Returns true if the given version is allowed for this codec.

Source

fn hop_data_len(version: u8, buf: &[u8]) -> Option<usize>

Returns the total length of hop data (including any headers) for the specified version.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§