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§
const PACKET_DATA_LEN: usize
Sourceconst CURRENT_VERSION: u8
const CURRENT_VERSION: u8
The onion packet version used when creating new packets.
Required Associated Types§
Required Methods§
Sourcefn pack(decoded: &Self::Decoded) -> Vec<u8> ⓘ
fn pack(decoded: &Self::Decoded) -> Vec<u8> ⓘ
Packs the decoded data for transmission. Must use CURRENT_VERSION format.
Sourcefn unpack(version: u8, buf: &[u8]) -> Option<Self::Decoded>
fn unpack(version: u8, buf: &[u8]) -> Option<Self::Decoded>
Unpacks data received from the network. Must handle all versions allowed by is_version_allowed.
fn to_current(decoded: Self::Decoded) -> Self::Current
Sourcefn is_version_allowed(version: u8) -> bool
fn is_version_allowed(version: u8) -> bool
Returns true if the given version is allowed for this codec.
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.