Skip to main content

Error

Enum Error 

Source
#[non_exhaustive]
pub enum Error {
Show 22 variants InvalidHrp(String), MixedCase, InvalidStringLength(usize), InvalidChar { ch: char, position: usize, }, BchUncorrectable(String), UnsupportedCardType(u8), MalformedPayloadPadding, ChunkSetIdMismatch, ChunkedHeaderMalformed(String), MixedHeaderTypes, CrossChunkHashMismatch, UnsupportedVersion(u8), ReservedBitsSet, InvalidPolicyIdStubCount, InvalidPathIndicator(u8), PathTooDeep(u8), InvalidPathComponent(String), InvalidXpubVersion(u32), InvalidXpubPublicKey(String), UnexpectedEnd, TrailingBytes, CardPayloadTooLarge { bytecode_len: usize, max_supported: usize, },
}
Expand description

All errors mk-codec can produce.

Marked #[non_exhaustive] so that future versions can add variants without breaking external callers’ exhaustive match arms.

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.
§

InvalidHrp(String)

HRP is not mk or input is not a valid bech32-shaped string.

§

MixedCase

Input string mixes ASCII upper- and lower-case in its data part. BIP 173 forbids mixed case to remove an entire class of transcription ambiguity; the rule is inherited verbatim by mk1’s codex32-derived encoding.

§

InvalidStringLength(usize)

Input string’s data-part length is not a valid mk1 length: either below the regular-code minimum (14 5-bit symbols), in the reserved-invalid 94–95 gap between regular and long codes, or above the long-code maximum (108). The carried usize is the observed length; reported pessimistically to highlight which boundary the caller missed.

§

InvalidChar

Input string’s data part contains a character that is not in the 32-character bech32 alphabet (qpzry9x8gf2tvdw0s3jn54khce6mua7l). The offending character and its 0-indexed position within the data part are reported so a higher-level decoder report can surface a precise location for transcription-error feedback.

Fields

§ch: char

The character that was not in the bech32 alphabet.

§position: usize

0-indexed position within the data part (chars after mk1).

§

BchUncorrectable(String)

BCH checksum could not be corrected within the per-code-variant substitution capacity (4 for regular, 8 for long).

§

UnsupportedCardType(u8)

Chunk-header card-type byte is not in {0x00 SingleString, 0x01 Chunked}. The 5-bit type field’s reserved range 0x02..=0x1F MUST be rejected.

§

MalformedPayloadPadding

5-bit payload symbols, after BCH verification, do not byte-align (i.e., the trailing pad bits of the final 5-bit symbol are non-zero). Parallels md1’s MalformedPayloadPadding rejection.

§

ChunkSetIdMismatch

For chunked input: chunks have inconsistent chunk_set_id values. Used at reassembly time to detect mixed-card-set inputs.

§

ChunkedHeaderMalformed(String)

For chunked input: malformed chunked-string header (e.g., total_chunks = 0 or > 32, chunk_index >= total_chunks, gaps or duplicates in the index sequence at reassembly).

§

MixedHeaderTypes

Decoder received a multi-string input whose SingleString and Chunked header variants disagree across the supplied list: either the first string is SingleString but additional strings follow (caught early in pipeline::decode), or the first chunk is Chunked but a later chunk in the list is SingleString (caught in chunk::reassemble_from_chunks). Distinct from Error::ChunkedHeaderMalformed, which covers issues within a declared-chunked set (bad chunk_index, bad total_chunks, duplicates, gaps, etc.).

§

CrossChunkHashMismatch

For chunked input: reassembled bytecode’s trailing 4-byte cross_chunk_hash does not match SHA-256(canonical_bytecode)[0..4].

§

UnsupportedVersion(u8)

Bytecode-header version != 0 in v0.1.

§

ReservedBitsSet

A reserved bit in the bytecode header was set (bits 0, 1, 3 in v0.1; bit 2 is the fingerprint flag and is allowed).

§

InvalidPolicyIdStubCount

policy_id_stub_count == 0. The spec requires ≥ 1.

§

InvalidPathIndicator(u8)

Origin-path indicator byte is outside the standard table or in the reserved range. (Per SPEC §3.5: 0x00, 0x08-0x10, 0x16, 0x18-0xFD, 0xFF are reserved; 0x16 is reserved pending md1 dictionary update, see FOLLOWUPS md-path-dictionary-0x16-gap.)

§

PathTooDeep(u8)

Explicit path declared component_count > MAX_PATH_COMPONENTS (closure Q-3 lock: max 10, was 32 in the pre-closure draft).

§

InvalidPathComponent(String)

A path component’s encoded value is invalid (e.g., out of BIP 32 range, or hardened-bit set in an invalid position).

§

InvalidXpubVersion(u32)

xpub version field doesn’t match a known network’s xpub prefix.

§

InvalidXpubPublicKey(String)

xpub public_key bytes do not parse as a valid compressed secp256k1 point. Realistically unreachable for inputs that pass BCH verification; surfaces hand-constructed inputs.

§

UnexpectedEnd

Decoder hit end-of-stream mid-field.

§

TrailingBytes

Decoder finished consuming all expected fields but bytes remain.

§

CardPayloadTooLarge

Canonical bytecode + cross-chunk hash exceeds the v0.1 capacity of MAX_CHUNKS * CHUNKED_FRAGMENT_LONG_BYTES − CROSS_CHUNK_HASH_BYTES (= 32 × 53 − 4 = 1692 bytes). Reachable only through pathological hand-constructed inputs; typical mk1 cards land well below this ceiling per design/SPEC_mk_v0_1.md §2.4.

Fields

§bytecode_len: usize

Observed canonical-bytecode length in bytes.

§max_supported: usize

Maximum bytecode length the v0.1 chunking layer can carry.

Trait Implementations§

Source§

impl Debug for Error

Source§

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

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

impl Display for Error

Source§

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

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

impl Error for Error

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more

Auto Trait Implementations§

§

impl Freeze for Error

§

impl RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

§

impl UnwindSafe for Error

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.