byte-array-ops 0.4.0

A no_std-compatible library for security-by-default byte array operations. Includes automatic memory zeroization, constant-time utilities, multiple input formats (hex, binary, UTF-8), bitwise operations, and comprehensive type conversions with minimal dependencies.
Documentation
//! This module encapsulates all errors that core can throw

use core::error::Error;
use core::fmt::{Display, Formatter};

#[derive(Debug, PartialEq, Eq)]
pub enum ByteArraySecurityError {
    DataRemnanceRisk, //TODO make this show the address of the pointer
}
#[derive(Debug, PartialEq, Eq)]
pub enum ByteArrayError {
    InvalidHexChar(char),
    InvalidBinaryChar(char),
    EmptyInput,
    SecurityError(ByteArraySecurityError),
}

impl Display for ByteArrayError {
    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
        match self {
            ByteArrayError::InvalidHexChar(c) => write!(f, "Invalid hex character: '{}'", c),
            ByteArrayError::InvalidBinaryChar(c) => write!(f, "Invalid binary character: '{}'", c),
            ByteArrayError::EmptyInput => write!(f, "Invalid empty input string"),
            ByteArrayError::SecurityError(sec_error) => {
                let base_msg = "Operational error due to security risk";
                match sec_error {
                    ByteArraySecurityError::DataRemnanceRisk => {
                        write!(f, "{base_msg}: Data Remnance Risk subverting secure wiping")
                    }
                }
            }
        }
    }
}

impl From<ByteArraySecurityError> for ByteArrayError {
    fn from(value: ByteArraySecurityError) -> Self {
        ByteArrayError::SecurityError(value)
    }
}

impl Error for ByteArrayError {}