What changed, and why it matters
This commit is a build-system cleanup, not a security fix. It hides certain error types from builds that do not enable the 'alloc' feature, because those error types are only used by decoding functions that already require 'alloc'. There is no change to how data is decoded, checked, or handled at runtime.
No security action required; treat as a normal API/build hygiene change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch adds #[cfg(feature = “alloc”)] gates to Error, ErrorInner, IncorrectChecksumError, TooShortError, InvalidCharacterError, InvalidCharacterErrorInner and their impl blocks in base58/src/error.rs. These types are only produced by alloc-gated decoding paths, so exposing them in no-alloc builds causes unnecessary API surface and potential compile-time confusion. No decoding, checksum, or validation logic is modified.
Changed components
base58/src/error.rsInspect captured patch +20 / −0
diff --git a/base58/src/error.rs b/base58/src/error.rs
index f728b908..b624b67e 100644
--- a/base58/src/error.rs
+++ b/base58/src/error.rs
@@ -5,12 +5,15 @@
use core::convert::Infallible;
use core::fmt;
+#[cfg(feature = "alloc")]
use internals::write_err;
/// An error occurred during base58 decoding (with checksum).
+#[cfg(feature = "alloc")]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Error(pub(super) ErrorInner);
+#[cfg(feature = "alloc")]
#[derive(Debug, Clone, PartialEq, Eq)]
pub(super) enum ErrorInner {
/// Invalid character while decoding.
@@ -21,6 +24,7 @@ pub(super) enum ErrorInner {
TooShort(TooShortError),
}
+#[cfg(feature = "alloc")]
impl Error {
/// Returns the invalid base58 character, if encountered.
pub fn invalid_character(&self) -> Option<u8> {
@@ -47,10 +51,12 @@ impl Error {
}
}
+#[cfg(feature = "alloc")]
impl From<Infallible> for Error {
fn from(never: Infallible) -> Self { match never {} }
}
+#[cfg(feature = "alloc")]
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use ErrorInner::{Decode, IncorrectChecksum, TooShort};
@@ -76,18 +82,22 @@ impl std::error::Error for Error {
}
}
+#[cfg(feature = "alloc")]
impl From<InvalidCharacterError> for Error {
fn from(e: InvalidCharacterError) -> Self { Self(ErrorInner::Decode(e)) }
}
+#[cfg(feature = "alloc")]
impl From<IncorrectChecksumError> for Error {
fn from(e: IncorrectChecksumError) -> Self { Self(ErrorInner::IncorrectChecksum(e)) }
}
+#[cfg(feature = "alloc")]
impl From<TooShortError> for Error {
fn from(e: TooShortError) -> Self { Self(ErrorInner::TooShort(e)) }
}
+#[cfg(feature = "alloc")]
/// Checksum was not correct.
#[derive(Debug, Clone, PartialEq, Eq)]
pub(super) struct IncorrectChecksumError {
@@ -97,10 +107,12 @@ pub(super) struct IncorrectChecksumError {
pub(super) expected: u32,
}
+#[cfg(feature = "alloc")]
impl From<Infallible> for IncorrectChecksumError {
fn from(never: Infallible) -> Self { match never {} }
}
+#[cfg(feature = "alloc")]
impl fmt::Display for IncorrectChecksumError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
@@ -119,6 +131,7 @@ impl std::error::Error for IncorrectChecksumError {
}
}
+#[cfg(feature = "alloc")]
/// The decoded base58 data was too short (require at least 4 bytes for checksum).
#[derive(Debug, Clone, PartialEq, Eq)]
pub(super) struct TooShortError {
@@ -126,10 +139,12 @@ pub(super) struct TooShortError {
pub(super) length: usize,
}
+#[cfg(feature = "alloc")]
impl From<Infallible> for TooShortError {
fn from(never: Infallible) -> Self { match never {} }
}
+#[cfg(feature = "alloc")]
impl fmt::Display for TooShortError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
@@ -188,14 +203,17 @@ impl std::error::Error for InputTooLongError {
}
/// Found an invalid ASCII byte while decoding base58 string.
+#[cfg(feature = "alloc")]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct InvalidCharacterError(pub(super) InvalidCharacterErrorInner);
+#[cfg(feature = "alloc")]
#[derive(Debug, Clone, PartialEq, Eq)]
pub(super) struct InvalidCharacterErrorInner {
pub(super) invalid: u8,
}
+#[cfg(feature = "alloc")]
impl InvalidCharacterError {
#[cfg(feature = "alloc")]
pub(super) fn new(invalid: u8) -> Self { Self(InvalidCharacterErrorInner { invalid }) }
@@ -204,10 +222,12 @@ impl InvalidCharacterError {
pub fn invalid_character(&self) -> u8 { self.0.invalid }
}
+#[cfg(feature = "alloc")]
impl From<Infallible> for InvalidCharacterError {
fn from(never: Infallible) -> Self { match never {} }
}
+#[cfg(feature = "alloc")]
impl fmt::Display for InvalidCharacterError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "invalid base58 character {:#x}", self.0.invalid)
Why this scored 15/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.