byte_array_ops/core/
errors.rs1use core::error::Error;
4use core::fmt::{Display, Formatter};
5
6#[derive(Debug)]
7#[cfg(feature = "sec_basic_hardening")]
8pub enum ByteArraySecurityError {
9 DataRemnanceRisk,
10}
11#[derive(Debug, PartialEq, Eq)]
12pub enum ByteArrayError {
13 InvalidHexChar(char),
14 InvalidBinaryChar(char),
15 EmptyInput,
16 #[cfg(feature = "sec_basic_hardening")]
17 SecurityError(ByteArraySecurityError),
18}
19
20impl Display for ByteArrayError {
21 fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
22 match self {
23 ByteArrayError::InvalidHexChar(c) => write!(f, "Invalid hex character: '{}'", c),
24 ByteArrayError::InvalidBinaryChar(c) => write!(f, "Invalid binary character: '{}'", c),
25 ByteArrayError::EmptyInput => write!(f, "Invalid empty input string"),
26 #[cfg(feature = "sec_basic_hardening")]
27 ByteArrayError::SecurityError(sec_error) => {
28 let base_msg = "Operational error due to security risk";
29 match sec_error {
30 ByteArraySecurityError::DataRemnanceRisk => {
31 write!(f, "{base_msg}: Data Remnance Risk subverting secure wiping")
32 }
33 }
34 }
35 }
36 }
37}
38
39impl Error for ByteArrayError {}