1use core::convert::Infallible;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub enum Error {
7 InvalidSecretKey,
9
10 InvalidPublicKey,
12
13 InvalidMessage,
15
16 InvalidSignature,
18
19 FailedToSign,
21
22 KeyNotFound,
24
25 KeystoreNotAvailable,
27
28 NotEnoughMemory,
30
31 InvalidMnemonic,
33
34 Bip32Error,
36}
37
38impl From<Error> for Infallible {
39 fn from(_: Error) -> Infallible {
40 unreachable!()
41 }
42}
43
44impl From<Infallible> for Error {
45 fn from(_: Infallible) -> Error {
46 unreachable!()
47 }
48}
49
50#[cfg(feature = "std")]
51mod use_std {
52 use super::*;
53 use coins_bip39::MnemonicError;
54 use std::{
55 error,
56 fmt,
57 io,
58 };
59
60 impl From<MnemonicError> for Error {
61 fn from(_: MnemonicError) -> Self {
62 Self::InvalidMnemonic
63 }
64 }
65
66 impl From<coins_bip32::Bip32Error> for Error {
67 fn from(_: coins_bip32::Bip32Error) -> Self {
68 Self::Bip32Error
69 }
70 }
71
72 impl fmt::Display for Error {
73 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
74 write!(f, "{self:?}")
75 }
76 }
77
78 impl error::Error for Error {
79 fn source(&self) -> Option<&(dyn error::Error + 'static)> {
80 None
81 }
82 }
83
84 impl From<Error> for io::Error {
85 fn from(e: Error) -> io::Error {
86 io::Error::new(io::ErrorKind::Other, e)
87 }
88 }
89}