diff --git a/src/util/base58.rs b/src/util/base58.rs index 97fdb045..3fb7cf95 100644 --- a/src/util/base58.rs +++ b/src/util/base58.rs @@ -17,8 +17,9 @@ use std::{error, fmt, str, slice, iter}; use hashes::{sha256d, Hash}; +use secp256k1; -use util::endian; +use util::{endian, key}; /// An error that might occur during base58 decoding #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)] @@ -35,8 +36,8 @@ pub enum Error { InvalidVersion(Vec), /// Checked data was less than 4 bytes TooShort(usize), - /// Any other error - Other(String) + /// Secp256k1 error while parsing a secret key + Secp256k1(secp256k1::Error), } impl fmt::Display for Error { @@ -47,7 +48,7 @@ impl fmt::Display for Error { Error::InvalidLength(ell) => write!(f, "length {} invalid for this base58 type", ell), Error::InvalidVersion(ref v) => write!(f, "version {:?} invalid for this base58 type", v), Error::TooShort(_) => write!(f, "base58ck data not even long enough for a checksum"), - Error::Other(ref s) => f.write_str(s) + Error::Secp256k1(ref e) => fmt::Display::fmt(&e, f), } } } @@ -237,6 +238,15 @@ pub fn check_encode_slice_to_fmt(fmt: &mut fmt::Formatter, data: &[u8]) -> fmt:: format_iter(fmt, iter) } +#[doc(hidden)] +impl From for Error { + fn from(e: key::Error) -> Self { + match e { + key::Error::Secp256k1(e) => Error::Secp256k1(e), + key::Error::Base58(e) => e, + } + } +} #[cfg(test)] mod tests {