safename 0.1.0

Filename and path validation for security hardening
Documentation
//! Error type for filename validation.

use thiserror::Error;

/// Result type alias using [`SafeNameError`].
pub type SafeNameResult<T> = Result<T, SafeNameError>;

/// Error type describing why a filename is unsafe.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
pub enum SafeNameError {
    /// Filename length is outside valid range (1..=max_len)
    #[error("invalid length {len} (must be 1..={max})")]
    InvalidLength {
        /// Actual length of the filename
        len: usize,
        /// Maximum allowed length
        max: usize,
    },

    /// Filename contains an invalid byte
    #[error("invalid byte 0x{byte:02X} at index {index}")]
    InvalidByte {
        /// Byte index in the filename
        index: usize,
        /// The invalid byte value
        byte: u8,
    },
}