anychain_kms/bip32/
error.rs

1//! Error type.
2
3use core::fmt::{self, Display};
4
5use hmac::digest::InvalidLength;
6
7/// Result type.
8pub type Result<T> = core::result::Result<T, Error>;
9
10/// Error type.
11#[derive(Copy, Clone, Debug, Eq, PartialEq)]
12#[non_exhaustive]
13pub enum Error {
14    /// Base58 errors.
15    Base58,
16
17    /// BIP39-related errors.
18    Bip39,
19
20    /// Child number-related errors.
21    ChildNumber,
22
23    /// Cryptographic errors.
24    Crypto,
25
26    /// Decoding errors (not related to Base58).
27    Decode,
28
29    /// Maximum derivation depth exceeded.
30    Depth,
31
32    /// Seed length invalid.
33    SeedLength,
34}
35
36impl Display for Error {
37    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38        match self {
39            Error::Base58 => f.write_str("base58 error"),
40            Error::Bip39 => f.write_str("bip39 error"),
41            Error::ChildNumber => f.write_str("invalid child number"),
42            Error::Crypto => f.write_str("cryptographic error"),
43            Error::Decode => f.write_str("decoding error"),
44            Error::Depth => f.write_str("maximum derivation depth exceeded"),
45            Error::SeedLength => f.write_str("seed length invalid"),
46        }
47    }
48}
49
50impl std::error::Error for Error {}
51
52impl From<bs58::decode::Error> for Error {
53    fn from(_: bs58::decode::Error) -> Error {
54        Error::Base58
55    }
56}
57
58impl From<bs58::encode::Error> for Error {
59    fn from(_: bs58::encode::Error) -> Error {
60        Error::Base58
61    }
62}
63
64impl From<core::array::TryFromSliceError> for Error {
65    fn from(_: core::array::TryFromSliceError) -> Error {
66        Error::Decode
67    }
68}
69
70/*
71impl From<digest::InvalidKeyLength> for Error {
72    fn from(_: hmac::crypto_mac::InvalidKeyLength) -> Error {
73        Error::Crypto
74    }
75
76}
77 */
78
79impl From<InvalidLength> for Error {
80    fn from(_: InvalidLength) -> Error {
81        Error::Crypto
82    }
83}
84/*
85impl From<k256::elliptic_curve::Error> for Error {
86    fn from(_: k256::elliptic_curve::Error) -> Error {
87        Error::Crypto
88    }
89}
90
91
92impl From<k256::ecdsa::Error> for Error {
93    fn from(_: k256::ecdsa::Error) -> Error {
94        Error::Crypto
95    }
96}
97*/
98
99impl From<libsecp256k1::Error> for Error {
100    fn from(_: libsecp256k1::Error) -> Error {
101        Error::Crypto
102    }
103}