Skip to main content

FormatDefect

Enum FormatDefect 

Source
#[non_exhaustive]
pub enum FormatDefect {
Show 18 variants Truncated, BadMagic, ExtTooLarge { len: u32, }, MalformedTlv, UnknownCriticalTag { tag: u16, }, NotAKeyFile, WrongKeyFileType, MalformedPublicKey, WrongKind { kind: u8, }, MalformedHeader, MalformedPayloadStream, OversizedHeader { header_len: u32, }, RecipientCountOutOfRange { count: u16, }, MalformedTypeName, MalformedRecipientEntry, RecipientFlagsReserved, MalformedPrivateKey, UnsupportedArchiveVersion { version: u8, },
}
Expand description

Structural defects detected while parsing a FerroCrypt encrypted file or key file. Carried inside CryptoError::InvalidFormat so format failures can be pattern-matched without substring comparisons and without parsing display text.

Each variant is the most granular structural class FORMAT.md §12 admits. Resource-cap exceedances are not FormatDefects — they are top-level CryptoError variants in the *CapExceeded family (e.g. FormatDefect::OversizedHeader is the structural max violation; the local-cap counterpart is CryptoError::HeaderLenCapExceeded).

This enum remains Copy: structural defects carry values that can be pattern-matched without heap-allocated strings, including future variants.

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

Truncated

The input ended before the 12-byte .fcr prefix, the header the prefix declares, or the 32-byte header MAC was complete, whether it was cut short or a damaged header_len declares more than it holds. Decryptor::open and decryption report an input shorter than the prefix this way whatever bytes it holds, so it need not be a FerroCrypt file; probe_recipient_mode returns None for one without the magic instead. A key file or an encrypted payload that ends early reports its own error, such as CryptoError::PayloadTruncated.

§

BadMagic

Leading magic bytes do not match "FCR\0".

§

ExtTooLarge

ext_len in a .fcr header’s fixed section exceeds the reader’s structural cap (EXT_LEN_MAX, 64 KiB). The shared TLV scanner re-checks its cap on every region it is handed, but the FCA and private.key regions are capped by their containing formats first (the latter as Self::MalformedPrivateKey), so only the .fcr fixed-section check is reachable from input. Carried as u32 because the cap is 65_536, which exceeds u16::MAX.

Fields

§len: u32

Declared extension-region length, in bytes.

§

MalformedTlv

A TLV entry in the extension region is malformed: bad ordering, duplicate or reserved tag, incomplete entry header, or a value length exceeding the region or configured per-value cap. FORMAT.md §6.

§

UnknownCriticalTag

A TLV tag in the critical range (0x8001..=0xFFFF) is not recognised by this release. Per FORMAT.md §6, unknown critical TLV tags must cause file rejection. The message advises a newer FerroCrypt, except for the critical test tag 0x8001, which §6 sets aside and no release will implement.

Fields

§tag: u16

Unknown critical TLV tag value.

§

NotAKeyFile

Input is not recognized as a key file: a private key has incorrect magic bytes, or a public key file is not valid UTF-8.

§

WrongKeyFileType

A private-key operation was given a file that starts like a public.key, with fcr1, or a public-key operation was given one with the private.key signature (FORMAT.md §8 and §7.1). A private-key operation given a FerroCrypt file of another kind reports FormatDefect::WrongKind instead.

§

MalformedPublicKey

public.key text file violates the canonical grammar (FORMAT.md §7.1): the file must contain the lowercase fcr1… recipient string optionally followed by exactly one trailing \n, OR the typed payload itself is structurally invalid. Leading/trailing whitespace other than a single final LF, CRLF line endings, extra blank lines, internal whitespace, header length-field violations, and internal-checksum mismatch all surface here. One case reports differently: a recipient string that is ASCII, longer than the recipient-string cap, and within the 20,000-character ceiling is refused as CryptoError::RecipientStringCapExceeded even when it also has one of these defects, because FORMAT.md §7 applies the cap before the Bech32 rules. In a public.key file that passes the file checks of FORMAT.md §7.1, the string is the text left once one final LF is removed.

§

WrongKind

A binary FerroCrypt artifact’s kind byte does not match the expected value for this operation (e.g. a caller asked for an encrypted .fcr but got a binary private.key, or vice versa). FORMAT.md §3.1 and §8.

Fields

§kind: u8

Raw kind byte from the binary artifact header.

§

MalformedHeader

Structural defect in the header_fixed layout (non-zero header_flags, ext_len over the structural cap, or length fields that don’t sum to header_len). Distinct from Self::OversizedHeader (header_len > 16 MiB structural max) and Self::RecipientCountOutOfRange (recipient_count outside 1..=4096). FORMAT.md §3.2.

§

MalformedPayloadStream

The authenticated payload stream violates the canonical chunk grammar in FORMAT.md §5. Currently this means an empty final chunk following one or more non-final chunks; an empty final chunk is valid only when it is the stream’s sole chunk and represents empty plaintext.

§

OversizedHeader

header_len exceeds the structural maximum (HEADER_LEN_MAX = 16 MiB per FORMAT.md §3.1). Distinct from CryptoError::HeaderLenCapExceeded which fires on the caller-configured local cap (resource policy, not format violation).

Fields

§header_len: u32

Header length declared by the .fcr prefix, in bytes.

§

RecipientCountOutOfRange

recipient_count is outside the structural range 1..=4096 (FORMAT.md §3.2). Distinct from CryptoError::RecipientCountCapExceeded which fires on the caller-configured local cap.

Fields

§count: u16

Recipient count declared by header_fixed.

§

MalformedTypeName

Recipient type_name does not satisfy the grammar in FORMAT.md §3.3 (lowercase ASCII, allowed character set, no leading/trailing punctuation, no .. or //).

§

MalformedRecipientEntry

Recipient entry framing is structurally invalid: 8-byte header truncated, length fields out of range, declared entry size exceeds the bytes available, or the recipient region’s per-entry total accounting doesn’t add up to recipient_entries_len. Also covers invalid native flags, body lengths, public-key encodings, and all-zero X25519 shared secrets (FORMAT.md §4).

§

RecipientFlagsReserved

Recipient entry has reserved bits set in recipient_flags. Per FORMAT.md §3.4, only bit 0 (the critical flag) is defined; all other bits must be zero on the wire.

§

MalformedPrivateKey

A private.key violates its structural or authenticated consistency rules: a short header, reserved version or flags, invalid lengths, mismatched total size, or invalid native key material. After unlock, this also covers a stored public key that does not match the secret. Incorrect magic returns Self::NotAKeyFile instead.

§

UnsupportedArchiveVersion

Inner FCA archive version byte is a nonzero value this release cannot read (zero is reserved and rejects as malformed). Distinct from the outer .fcr / private.key version rejection in UnsupportedVersion: this variant fires inside the encrypted payload after the outer container is accepted, so it is a structural defect of the inner archive grammar (FCA), not of the outer FerroCrypt file. Per FORMAT.md §9 / §12.

Fields

§version: u8

FCA archive version byte from the encrypted payload.

Trait Implementations§

Source§

impl Clone for FormatDefect

Source§

fn clone(&self) -> Self

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 Copy for FormatDefect

Source§

impl Debug for FormatDefect

Source§

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

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

impl Display for FormatDefect

Source§

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

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

impl Eq for FormatDefect

Source§

impl PartialEq for FormatDefect

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FormatDefect

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> Same for T

Source§

type Output = T

Should always be Self
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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.