multi-util 1.0.2

Multiformat utility functions and types
// SPDX-License-Identifier: Apache-2.0
/// Errors generated by the numeric type impls
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
    /// Multitrait decode error
    #[error(transparent)]
    Multitrait(#[from] multi_trait::Error),
    /// Multicodec decode error
    #[error(transparent)]
    Multicodec(#[from] multi_codec::Error),
    /// BaseEncoded error
    #[error(transparent)]
    BaseEncoded(#[from] BaseEncodedError),
    /// BaseEncoder error
    #[error(transparent)]
    BaseEncoder(#[from] BaseEncoderError),
    /// Custom error for inner types to use when nothing else works
    #[error("Custom error: {0}")]
    Custom(String),
    /// Insufficient data available for the claimed length
    ///
    /// This error occurs when a varint length claim exceeds the available buffer size.
    /// This prevents buffer overflow attacks where an attacker claims a large length
    /// but provides minimal data.
    ///
    /// # Security
    ///
    /// This validation prevents CWE-125 (Out-of-bounds Read) vulnerabilities.
    ///
    /// # Example
    ///
    /// ```rust
    /// use multi_util::Error;
    ///
    /// // This would trigger InsufficientData:
    /// // Varint claims 1000 bytes but only 3 bytes available
    /// ```
    #[error("insufficient data: expected {expected} bytes, but only {actual} bytes available")]
    InsufficientData {
        /// The number of bytes claimed by the length prefix
        expected: usize,
        /// The actual number of bytes available in the buffer
        actual: usize,
    },
}

impl Error {
    /// create a custom error instance
    pub fn custom(s: &str) -> Self {
        Error::Custom(s.to_string())
    }
}

/// Errors generated by the base encoding smart pointer
#[derive(Clone, Debug, thiserror::Error)]
#[non_exhaustive]
pub enum BaseEncodedError {
    /// BaseEncoder error
    #[error(transparent)]
    BaseEncoder(#[from] BaseEncoderError),
    /// Value decoding failed
    #[error("Failed to decode the tagged value")]
    ValueFailed,
}

/// Errors generated by the base encoding smart pointer
#[derive(Clone, Debug, thiserror::Error)]
#[non_exhaustive]
pub enum BaseEncoderError {
    /// Multibase decode error
    #[error(transparent)]
    Multibase(#[from] multi_base::Error),

    /// Base58 decode error
    #[error("Base58 error: {0}")]
    Base58(String),
}