What changed, and why it matters
This commit is a routine code cleanup: it renames the `Error` type in the base58 module to the more descriptive `DecodeCheckError`, and adds a deprecated type alias so existing code using `base58::Error` continues to work. There is no change to how data is decoded, validated, or handled, and no security bug is fixed.
No security action required. Treat as a normal API-maintenance change. Consumers may optionally migrate from `base58::Error` to `base58::DecodeCheckError` before the deprecated alias is removed in a future release.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch is a pure refactor across five files. It renames base58::Error to base58::DecodeCheckError (and the corresponding inner/private types), updates all internal references and From impls in addresses, crypto::key, and key_expression::bip32, and introduces #[deprecated(since = "TBD", note = "use DecodeCheckError instead")] pub type Error = DecodeCheckError; to preserve backward compatibility. No logic, parsing, checksum verification, or error handling behavior is altered.
Changed components
base58/src/error.rsbase58/src/lib.rsaddresses/src/error.rscrypto/src/key.rskey_expression/src/bip32.rsInspect captured patch +45 / −39
diff --git a/addresses/src/error.rs b/addresses/src/error.rs
index 3f879527..fea37505 100644
--- a/addresses/src/error.rs
+++ b/addresses/src/error.rs
@@ -249,7 +249,7 @@ impl std::error::Error for ParseBech32Error {
#[non_exhaustive]
pub enum Base58Error {
/// Parse legacy Base58 error.
- ParseBase58(base58::Error),
+ ParseBase58(base58::DecodeCheckError),
/// Legacy address is too long.
LegacyAddressTooLong(LegacyAddressTooLongError),
/// Invalid base58 payload data length for legacy address.
@@ -286,8 +286,8 @@ impl std::error::Error for Base58Error {
}
}
-impl From<base58::Error> for Base58Error {
- fn from(e: base58::Error) -> Self { Self::ParseBase58(e) }
+impl From<base58::DecodeCheckError> for Base58Error {
+ fn from(e: base58::DecodeCheckError) -> Self { Self::ParseBase58(e) }
}
impl From<LegacyAddressTooLongError> for Base58Error {
diff --git a/base58/src/error.rs b/base58/src/error.rs
index f2f5a850..0c880c71 100644
--- a/base58/src/error.rs
+++ b/base58/src/error.rs
@@ -9,16 +9,21 @@ use internals::write_err;
/// An error occurred during base58 decoding (with checksum).
#[cfg(feature = "alloc")]
+#[deprecated(since = "TBD", note = "use DecodeCheckError instead")]
+pub type Error = DecodeCheckError;
+
+#[cfg(feature = "alloc")]
+/// An error occurred during base58 decoding (with checksum).
#[derive(Debug, Clone, PartialEq, Eq)]
-pub struct Error(pub(super) ErrorInner);
+pub struct DecodeCheckError(pub(super) DecodeCheckErrorInner);
#[cfg(not(feature = "alloc"))]
/// An error occurred during base58 decoding (with checksum).
#[derive(Debug, Clone, PartialEq, Eq)]
-pub(crate) struct Error(pub(super) ErrorInner);
+pub(crate) struct DecodeCheckError(pub(super) DecodeCheckErrorInner);
#[derive(Debug, Clone, PartialEq, Eq)]
-pub(super) enum ErrorInner {
+pub(super) enum DecodeCheckErrorInner {
/// Invalid character while decoding.
Decode(InvalidCharacterError),
/// Checksum was not correct.
@@ -27,11 +32,11 @@ pub(super) enum ErrorInner {
TooShort(TooShortError),
}
-impl Error {
+impl DecodeCheckError {
/// Returns the invalid base58 character, if encountered.
pub fn invalid_character(&self) -> Option<u8> {
match self.0 {
- ErrorInner::Decode(ref e) => Some(e.invalid_character()),
+ DecodeCheckErrorInner::Decode(ref e) => Some(e.invalid_character()),
_ => None,
}
}
@@ -39,7 +44,7 @@ impl Error {
/// Returns the incorrect checksum along with the expected checksum, if encountered.
pub fn incorrect_checksum(&self) -> Option<(u32, u32)> {
match self.0 {
- ErrorInner::IncorrectChecksum(ref e) => Some((e.incorrect, e.expected)),
+ DecodeCheckErrorInner::IncorrectChecksum(ref e) => Some((e.incorrect, e.expected)),
_ => None,
}
}
@@ -47,19 +52,19 @@ impl Error {
/// Returns the invalid base58 string length (require at least 4 bytes for checksum), if encountered.
pub fn invalid_length(&self) -> Option<usize> {
match self.0 {
- ErrorInner::TooShort(ref e) => Some(e.length),
+ DecodeCheckErrorInner::TooShort(ref e) => Some(e.length),
_ => None,
}
}
}
-impl From<Infallible> for Error {
+impl From<Infallible> for DecodeCheckError {
fn from(never: Infallible) -> Self { match never {} }
}
-impl fmt::Display for Error {
+impl fmt::Display for DecodeCheckError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use ErrorInner::{Decode, IncorrectChecksum, TooShort};
+ use DecodeCheckErrorInner::{Decode, IncorrectChecksum, TooShort};
match self.0 {
Decode(ref e) => write_err!(f, "decode"; e),
@@ -70,9 +75,9 @@ impl fmt::Display for Error {
}
#[cfg(feature = "std")]
-impl std::error::Error for Error {
+impl std::error::Error for DecodeCheckError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- use ErrorInner::{Decode, IncorrectChecksum, TooShort};
+ use DecodeCheckErrorInner::{Decode, IncorrectChecksum, TooShort};
match self.0 {
Decode(ref e) => Some(e),
@@ -82,16 +87,16 @@ impl std::error::Error for Error {
}
}
-impl From<InvalidCharacterError> for Error {
- fn from(e: InvalidCharacterError) -> Self { Self(ErrorInner::Decode(e)) }
+impl From<InvalidCharacterError> for DecodeCheckError {
+ fn from(e: InvalidCharacterError) -> Self { Self(DecodeCheckErrorInner::Decode(e)) }
}
-impl From<IncorrectChecksumError> for Error {
- fn from(e: IncorrectChecksumError) -> Self { Self(ErrorInner::IncorrectChecksum(e)) }
+impl From<IncorrectChecksumError> for DecodeCheckError {
+ fn from(e: IncorrectChecksumError) -> Self { Self(DecodeCheckErrorInner::IncorrectChecksum(e)) }
}
-impl From<TooShortError> for Error {
- fn from(e: TooShortError) -> Self { Self(ErrorInner::TooShort(e)) }
+impl From<TooShortError> for DecodeCheckError {
+ fn from(e: TooShortError) -> Self { Self(DecodeCheckErrorInner::TooShort(e)) }
}
/// Checksum was not correct.
@@ -200,7 +205,7 @@ pub struct DecodeCheckArrayError(pub(super) DecodeCheckArrayErrorInner);
#[derive(Debug, Clone, PartialEq, Eq)]
pub(super) enum DecodeCheckArrayErrorInner {
/// Decoding the base58check string failed (invalid character, bad checksum or too short).
- Decode(Error),
+ Decode(DecodeCheckError),
/// The decoded payload length did not match the requested array length.
UnexpectedLength(UnexpectedLengthError),
}
diff --git a/base58/src/lib.rs b/base58/src/lib.rs
index 8d3488f9..7da963c1 100644
--- a/base58/src/lib.rs
+++ b/base58/src/lib.rs
@@ -50,12 +50,12 @@ use crate::error::{
UnexpectedLengthError,
};
#[cfg(not(feature = "alloc"))]
-use crate::error::{Error, InputTooLongErrorInner, InvalidCharacterError};
+use crate::error::{DecodeCheckError, InputTooLongErrorInner, InvalidCharacterError};
#[rustfmt::skip] // Keep public re-exports separate.
#[cfg(feature = "alloc")]
#[doc(no_inline)]
-pub use self::error::{Error, InvalidCharacterError};
+pub use self::error::{DecodeCheckError, InvalidCharacterError};
#[doc(no_inline)]
pub use self::error::{DecodeCheckArrayError, InputTooLongError};
@@ -143,7 +143,7 @@ pub fn decode(data: &str) -> Result<Vec<u8>, InvalidCharacterError> {
/// * The decoded data is less than 4 bytes (too short for checksum verification).
/// * The checksum does not match the expected value.
#[cfg(feature = "alloc")]
-pub fn decode_check(data: &str) -> Result<Vec<u8>, Error> {
+pub fn decode_check(data: &str) -> Result<Vec<u8>, DecodeCheckError> {
let mut ret: Vec<u8> = decode(data)?;
let (remaining, &data_check) =
ret.split_last_chunk::<4>().ok_or(TooShortError { length: ret.len() })?;
@@ -186,7 +186,8 @@ pub fn decode_check_to_array<const N: usize>(data: &str) -> Result<[u8; N], Deco
expected: N,
actual: data.len() * 11 / 15,
}),
- Base256Error::InvalidChar(err) => DecodeCheckArrayErrorInner::Decode(Error::from(err)),
+ Base256Error::InvalidChar(err) =>
+ DecodeCheckArrayErrorInner::Decode(DecodeCheckError::from(err)),
})
.map_err(DecodeCheckArrayError)?;
@@ -206,9 +207,9 @@ pub fn decode_check_to_array<const N: usize>(data: &str) -> Result<[u8; N], Deco
let decoded = &decoded[..decoded_len];
let (payload, &data_check) = decoded.split_last_chunk::<4>().ok_or_else(|| {
- DecodeCheckArrayError(DecodeCheckArrayErrorInner::Decode(Error::from(TooShortError {
- length: decoded_len,
- })))
+ DecodeCheckArrayError(DecodeCheckArrayErrorInner::Decode(DecodeCheckError::from(
+ TooShortError { length: decoded_len },
+ )))
})?;
if payload.len() != N {
@@ -222,9 +223,9 @@ pub fn decode_check_to_array<const N: usize>(data: &str) -> Result<[u8; N], Deco
let actual = u32::from_le_bytes(data_check);
if actual != expected {
- return Err(DecodeCheckArrayError(DecodeCheckArrayErrorInner::Decode(Error::from(
- IncorrectChecksumError { incorrect: actual, expected },
- ))));
+ return Err(DecodeCheckArrayError(DecodeCheckArrayErrorInner::Decode(
+ DecodeCheckError::from(IncorrectChecksumError { incorrect: actual, expected }),
+ )));
}
Ok(payload.try_into().expect("payload length checked to equal N"))
diff --git a/crypto/src/key.rs b/crypto/src/key.rs
index 28770338..cc8a9a4e 100644
--- a/crypto/src/key.rs
+++ b/crypto/src/key.rs
@@ -1635,7 +1635,7 @@ pub mod error {
#[cfg(feature = "alloc")]
pub enum FromWifError {
/// A base58 decoding error.
- Base58(base58::Error),
+ Base58(base58::DecodeCheckError),
/// Base58 decoded data was an invalid length.
InvalidBase58PayloadLength(InvalidBase58PayloadLengthError),
/// Base58 decoded data contained an invalid address version byte.
diff --git a/key_expression/src/bip32.rs b/key_expression/src/bip32.rs
index 1150ae50..39011fa3 100644
--- a/key_expression/src/bip32.rs
+++ b/key_expression/src/bip32.rs
@@ -1282,7 +1282,7 @@ pub mod error {
#[non_exhaustive]
pub enum ParseXprivError {
/// Base58 encoding error.
- Base58(base58::Error),
+ Base58(base58::DecodeCheckError),
/// Base58 decoded data was an invalid length.
InvalidBase58PayloadLength(InvalidBase58PayloadLengthError),
/// Binary xpriv decode error.
@@ -1314,8 +1314,8 @@ pub mod error {
}
}
- impl From<base58::Error> for ParseXprivError {
- fn from(e: base58::Error) -> Self { Self::Base58(e) }
+ impl From<base58::DecodeCheckError> for ParseXprivError {
+ fn from(e: base58::DecodeCheckError) -> Self { Self::Base58(e) }
}
/// Error parsing a base58check BIP-0032 xpub string.
@@ -1323,7 +1323,7 @@ pub mod error {
#[non_exhaustive]
pub enum ParseXpubError {
/// Base58 encoding error.
- Base58(base58::Error),
+ Base58(base58::DecodeCheckError),
/// Base58 decoded data was an invalid length.
InvalidBase58PayloadLength(InvalidBase58PayloadLengthError),
/// Binary xpub decode error.
@@ -1355,8 +1355,8 @@ pub mod error {
}
}
- impl From<base58::Error> for ParseXpubError {
- fn from(e: base58::Error) -> Self { Self::Base58(e) }
+ impl From<base58::DecodeCheckError> for ParseXpubError {
+ fn from(e: base58::DecodeCheckError) -> Self { Self::Base58(e) }
}
/// Attempted to derive a child of depth 256 or higher.
Why this scored 20/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.