secure_gate/
error.rs

1//! Centralized error types for the secure-gate crate.
2
3#[cfg(feature = "encoding-bech32")]
4/// Error type for Bech32 encoding operations.
5#[derive(Clone, Copy, Debug, PartialEq, Eq, thiserror::Error)]
6pub enum Bech32EncodingError {
7    #[error("invalid Human-Readable Part (HRP)")]
8    InvalidHrp,
9    #[error("encoding operation failed")]
10    EncodingFailed,
11}
12
13/// Error for slice length mismatches in TryFrom impls.
14#[derive(Debug)]
15pub struct FromSliceError {
16    pub(crate) actual_len: usize,
17    pub(crate) expected_len: usize,
18}
19
20impl FromSliceError {
21    /// Create a new FromSliceError with the actual and expected lengths.
22    pub(crate) fn new(actual_len: usize, expected_len: usize) -> Self {
23        Self {
24            actual_len,
25            expected_len,
26        }
27    }
28}
29
30impl core::fmt::Display for FromSliceError {
31    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
32        write!(
33            f,
34            "slice length mismatch: expected {} bytes, got {} bytes",
35            self.expected_len, self.actual_len
36        )
37    }
38}
39
40impl std::error::Error for FromSliceError {}