FormatError

Enum FormatError 

Source
pub enum FormatError {
    Serialization(BincodeError),
    InvalidCiphertext,
    InvalidKeyType,
    InvalidKey,
}
Expand description

Errors related to data formatting, serialization, and structure validation.

与数据格式、序列化和结构验证相关的错误。

§Overview | 概述

These errors occur when data doesn’t conform to expected formats or when serialization/deserialization operations fail. They typically indicate either corrupted data or version incompatibilities.

当数据不符合预期格式或序列化/反序列化操作失败时会发生这些错误。 它们通常表示数据损坏或版本不兼容。

§Common Causes | 常见原因

  • Corrupted or truncated data

  • Version mismatches between serialization formats

  • Invalid key material or algorithm parameters

  • Malformed ciphertext or signature data

  • 损坏或截断的数据

  • 序列化格式之间的版本不匹配

  • 无效的密钥材料或算法参数

  • 格式错误的密文或签名数据

Variants§

§

Serialization(BincodeError)

Binary serialization or deserialization failure.

二进制序列化或反序列化失败。

This error occurs when bincode cannot serialize or deserialize data, typically due to:

  • Incompatible data structure versions
  • Corrupted serialized data
  • Insufficient buffer space

bincode 无法序列化或反序列化数据时发生此错误,通常由于:

  • 不兼容的数据结构版本
  • 损坏的序列化数据
  • 缓冲区空间不足

§Recovery | 恢复

  • Verify data integrity

  • Check version compatibility

  • Ensure sufficient buffer space

  • 验证数据完整性

  • 检查版本兼容性

  • 确保足够的缓冲区空间

§

InvalidCiphertext

Invalid or corrupted ciphertext format.

无效或损坏的密文格式。

This error indicates that the ciphertext data is malformed, incomplete, or has been corrupted. Common causes include:

  • Data truncation during transmission or storage
  • Bit flips due to hardware errors
  • Incorrect data handling or parsing

此错误表示密文数据格式错误、不完整或已损坏。常见原因包括:

  • 传输或存储期间的数据截断
  • 硬件错误导致的位翻转
  • 不正确的数据处理或解析

§Security Implications | 安全影响

This error should be treated as a potential security issue. Never attempt to process malformed ciphertext.

此错误应被视为潜在的安全问题。 永远不要尝试处理格式错误的密文。

§

InvalidKeyType

Unsupported or invalid key type.

不支持或无效的密钥类型。

This error occurs when:

  • A key is used with an incompatible algorithm
  • The key type is not supported by the current configuration
  • Key metadata is corrupted or missing

在以下情况下发生此错误:

  • 密钥与不兼容的算法一起使用
  • 当前配置不支持密钥类型
  • 密钥元数据损坏或丢失
§

InvalidKey

Invalid key material or structure.

无效的密钥材料或结构。

This error indicates that the key data itself is invalid:

  • Incorrect key length for the algorithm
  • Invalid key format or encoding
  • Corrupted key material
  • Missing required key components

此错误表示密钥数据本身无效:

  • 算法的密钥长度不正确
  • 无效的密钥格式或编码
  • 损坏的密钥材料
  • 缺少必需的密钥组件

§Security Note | 安全注意

Invalid keys should never be used for cryptographic operations. Always validate key material before use.

无效密钥永远不应用于密码操作。 使用前始终验证密钥材料。

Trait Implementations§

Source§

impl Debug for FormatError

Source§

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

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

impl Display for FormatError

Source§

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

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

impl Error for FormatError

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

impl From<BincodeError> for FormatError

Source§

fn from(source: BincodeError) -> Self

Converts to this type from the input type.
Source§

impl From<FormatError> for Error

Source§

fn from(source: FormatError) -> Self

Converts to this type from the input type.

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V