Remove base58::Error::Other variant in favor of specific variant

This commit is contained in:
Riccardo Casatta 2020-11-18 14:01:28 +01:00
parent 0eaf45ca81
commit bace07d8f8
No known key found for this signature in database
GPG Key ID: FD986A969E450397
1 changed files with 14 additions and 4 deletions

View File

@ -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<u8>),
/// 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<key::Error> 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 {