use core::fmt::{self, Display};
use hmac::digest::InvalidLength;
pub type Result<T> = core::result::Result<T, Error>;
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum Error {
Base58,
Bip39,
ChildNumber,
Crypto,
Decode,
Depth,
SeedLength,
}
impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Base58 => f.write_str("base58 error"),
Error::Bip39 => f.write_str("bip39 error"),
Error::ChildNumber => f.write_str("invalid child number"),
Error::Crypto => f.write_str("cryptographic error"),
Error::Decode => f.write_str("decoding error"),
Error::Depth => f.write_str("maximum derivation depth exceeded"),
Error::SeedLength => f.write_str("seed length invalid"),
}
}
}
impl std::error::Error for Error {}
impl From<bs58::decode::Error> for Error {
fn from(_: bs58::decode::Error) -> Error {
Error::Base58
}
}
impl From<bs58::encode::Error> for Error {
fn from(_: bs58::encode::Error) -> Error {
Error::Base58
}
}
impl From<core::array::TryFromSliceError> for Error {
fn from(_: core::array::TryFromSliceError) -> Error {
Error::Decode
}
}
impl From<InvalidLength> for Error {
fn from(_: InvalidLength) -> Error {
Error::Crypto
}
}
impl From<libsecp256k1::Error> for Error {
fn from(_: libsecp256k1::Error) -> Error {
Error::Crypto
}
}