Skip to main content

ripple_keypairs/
error.rs

1//! Errors
2
3use std::{error, fmt, result};
4
5use base_x;
6
7pub use Error::*;
8
9/// Result with error type
10pub type Result<T> = result::Result<T, Error>;
11
12/// Error enum type
13#[allow(missing_docs)]
14#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
15pub enum Error {
16    ExpectedMinEntorpyLenght(usize),
17    DecodeError,
18    InvalidSignature,
19    DeriveKeyPairError,
20}
21
22impl error::Error for Error {
23    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
24        None
25    }
26}
27
28impl fmt::Display for Error {
29    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30        match self {
31            ExpectedMinEntorpyLenght(n) => write!(f, "{} {}", "entropy lenght must be >=", n),
32            DecodeError => f.write_str("decode error"),
33            InvalidSignature => f.write_str("invalid signature"),
34            DeriveKeyPairError => f.write_str("derive keypair error"),
35        }
36    }
37}
38
39macro_rules! impl_from_error {
40    ($t:ty => $m:ident) => {
41        #[doc(hidden)]
42        impl From<$t> for Error {
43            fn from(_: $t) -> Self {
44                $m
45            }
46        }
47    };
48}
49
50impl_from_error!(base_x::DecodeError => DecodeError);
51impl_from_error!(secp256k1::Error => InvalidSignature);