Skip to main content

Payload

Enum Payload 

Source
#[non_exhaustive]
pub enum Payload { Entr(Vec<u8>), Mnem { language: u8, entropy: Vec<u8>, }, }
Expand description

v0.1 payload.

Caller-wrap contract (SPEC v0.9.0 §1 item 2): the Vec<u8> inside Payload::Entr is NOT zeroize-wrapped — widening the public type to Zeroizing<Vec<u8>> is a breaking change deferred indefinitely per SPEC §3 OOS-2. Callers MUST wrap the byte buffer at the use site (e.g., let bytes = Zeroizing::new((*p.as_bytes()).to_vec());) so that the secret-material lifetime ends with a scrubbed drop. ms-codec internally minimizes the un-scrubbed lifetime: encode + decode path locals are Zeroizing<Vec<u8>>; only the public Payload::Entr boundary is unwrapped.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Entr(Vec<u8>)

BIP-39 entropy. Length MUST be in {16, 20, 24, 28, 32} bytes (bijective with BIP-39 word counts {12, 15, 18, 21, 24}).

Caller responsibility: ms-codec does NOT check the statistical quality of these bytes. Callers are responsible for sourcing entropy from a vetted CSPRNG, or from a BIP-39 mnemonic the user already trusts. FIPS-style entropy-quality checks would slow encoding and provide false assurance — they cannot detect attacker-supplied “pseudo-random” seeds crafted to pass standard randomness tests. See SPEC §3.6.

Caller-wrap reminder: wrap this Vec<u8> in Zeroizing at the use site so it scrubs on drop. ms-codec cannot wrap this for you without a breaking public-API change.

§

Mnem

BIP-39 mnemonic entropy with wordlist language tag. On-wire payload: [0x02][language_byte][entropy:N] where language_byte indexes into consts::MNEM_LANGUAGE_NAMES (0 = English, 1 = Japanese, …, 9 = Portuguese). Entropy length MUST be in {16, 20, 24, 28, 32} bytes.

Caller-wrap reminder: wrap entropy in Zeroizing at the use site.

Fields

§language: u8

BIP-39 wordlist language index (0..=9).

§entropy: Vec<u8>

BIP-39 entropy bytes (16/20/24/28/32 B).

Implementations§

Source§

impl Payload

Source

pub fn validate(&self) -> Result<()>

Validate the payload’s intrinsic structure (byte length for Entr/Mnem; language code range for Mnem). Encoder MUST call this before emitting; decoder calls it after extracting the payload bytes following the prefix byte.

Source

pub fn kind(&self) -> PayloadKind

The PayloadKind discriminant.

Source

pub fn as_bytes(&self) -> &[u8]

Borrow the inner entropy byte slice. For Payload::Mnem, returns the entropy bytes only (without prefix or language byte).

Trait Implementations§

Source§

impl Clone for Payload

Source§

fn clone(&self) -> Payload

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Payload

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Payload

Source§

impl PartialEq for Payload

Source§

fn eq(&self, other: &Payload) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Payload

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.