anychain_kms/bip32/
error.rs1use core::fmt::{self, Display};
4
5use hmac::digest::InvalidLength;
6
7pub type Result<T> = core::result::Result<T, Error>;
9
10#[derive(Copy, Clone, Debug, Eq, PartialEq)]
12#[non_exhaustive]
13pub enum Error {
14 Base58,
16
17 Bip39,
19
20 ChildNumber,
22
23 Crypto,
25
26 Decode,
28
29 Depth,
31
32 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
70impl From<InvalidLength> for Error {
80 fn from(_: InvalidLength) -> Error {
81 Error::Crypto
82 }
83}
84impl From<libsecp256k1::Error> for Error {
100 fn from(_: libsecp256k1::Error) -> Error {
101 Error::Crypto
102 }
103}