Skip to main content

datex_crypto_facade/
error.rs

1use core::fmt::Display;
2#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3pub enum B58DecodeError {
4    InvalidBase58,
5    WrongLength { expected: usize, got: usize },
6}
7impl Display for B58DecodeError {
8    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
9        match self {
10            B58DecodeError::InvalidBase58 => write!(f, "Invalid Base58 string"),
11            B58DecodeError::WrongLength { expected, got } => write!(
12                f,
13                "Invalid length for Base58 decoded data: expected {} bytes, got {} bytes",
14                expected, got
15            ),
16        }
17    }
18}
19
20// crate::error.rs
21
22#[derive(Debug, Clone, PartialEq, Eq)]
23pub enum BackendError {
24    /// The backend/platform cannot do this operation (algo not available, feature off).
25    Unsupported(&'static str),
26    /// The backend could do it, but is not currently usable (not initialized, no entropy, etc).
27    Unavailable(&'static str),
28}
29
30#[derive(Debug, Clone, PartialEq, Eq)]
31pub enum RandomBytesError {
32    Backend(BackendError),
33}
34
35#[derive(Debug, Clone, PartialEq, Eq)]
36pub enum Sha256Error {
37    Backend(BackendError),
38}
39
40#[derive(Debug, Clone, PartialEq, Eq)]
41pub enum HkdfError {
42    Backend(BackendError),
43}
44
45#[derive(Debug, Clone, PartialEq, Eq)]
46pub enum Ed25519GenError {
47    Backend(BackendError),
48}
49
50#[derive(Debug, Clone, PartialEq, Eq)]
51pub enum Ed25519SignError {
52    /// Private key bytes not acceptable (wrong length/format).
53    InvalidPrivateKey,
54    Backend(BackendError),
55}
56
57#[derive(Debug, Clone, PartialEq, Eq)]
58pub enum Ed25519VerifyError {
59    /// Public key bytes not acceptable (wrong length/format).
60    InvalidPublicKey,
61    /// Signature bytes not acceptable (wrong length/format).
62    InvalidSignature,
63    Backend(BackendError),
64}
65
66#[derive(Debug, Clone, PartialEq, Eq)]
67pub enum AesCtrError {
68    Backend(BackendError),
69}
70
71#[derive(Debug, Clone, PartialEq, Eq)]
72pub enum KeyWrapError {
73    Backend(BackendError),
74}
75
76#[derive(Debug, Clone, PartialEq, Eq)]
77pub enum KeyUnwrapError {
78    IntegrityCheckFailed,
79    Backend(BackendError),
80}
81
82#[derive(Debug, Clone, PartialEq, Eq)]
83pub enum X25519GenError {
84    Backend(BackendError),
85}
86
87#[derive(Debug, Clone, PartialEq, Eq)]
88pub enum X25519DeriveError {
89    InvalidPrivateKey,
90    InvalidPeerPublicKey,
91    Backend(BackendError),
92}