#[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
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
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.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()