What changed, and why it matters
This commit removes an old, already-deprecated error type called FromSliceError from the rust-bitcoin hashes crate. The function that used to return this error was removed in an earlier version, so this change just cleans up leftover code. It is a routine API cleanup, not a security fix.
No security action needed. Downstream users relying on the deprecated FromSliceError type will need to update their code when upgrading, as expected for a breaking API cleanup.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch deletes hashes/src/error.rs and removes the deprecated pub type FromSliceError alias from hashes/src/lib.rs. It also updates the API test to stop referencing the removed type. The commit message states that Hash::from_slice was deprecated in v0.15.0 and removed in the upcoming release, making FromSliceError unused. No functional behavior changes; this is a breaking API removal of an unused public type.
Changed components
hashes/src/error.rshashes/src/lib.rshashes/tests/api.rsInspect captured patch +1 / −51
diff --git a/hashes/src/error.rs b/hashes/src/error.rs
deleted file mode 100644
index ce2c82af..00000000
--- a/hashes/src/error.rs
+++ /dev/null
@@ -1,42 +0,0 @@
-// SPDX-License-Identifier: CC0-1.0
-
-//! Error code for the `hashes` crate.
-
-use core::convert::Infallible;
-use core::fmt;
-
-/// Attempted to create a hash from an invalid length slice.
-#[derive(Debug, Clone, PartialEq, Eq)]
-pub struct FromSliceError(pub(crate) FromSliceErrorInner);
-
-impl From<Infallible> for FromSliceError {
- fn from(never: Infallible) -> Self { match never {} }
-}
-
-impl FromSliceError {
- /// Returns the expected slice length.
- pub fn expected_length(&self) -> usize { self.0.expected }
-
- /// Returns the invalid slice length.
- pub fn invalid_length(&self) -> usize { self.0.got }
-}
-
-/// Attempted to create a hash from an invalid length slice.
-#[derive(Debug, Clone, PartialEq, Eq)]
-pub(crate) struct FromSliceErrorInner {
- pub(crate) expected: usize,
- pub(crate) got: usize,
-}
-
-impl From<Infallible> for FromSliceErrorInner {
- fn from(never: Infallible) -> Self { match never {} }
-}
-
-impl fmt::Display for FromSliceError {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "invalid slice length {} (expected {})", self.0.got, self.0.expected)
- }
-}
-
-#[cfg(feature = "std")]
-impl std::error::Error for FromSliceError {}
diff --git a/hashes/src/lib.rs b/hashes/src/lib.rs
index 4f7e1d3a..1829ad2a 100644
--- a/hashes/src/lib.rs
+++ b/hashes/src/lib.rs
@@ -91,8 +91,6 @@ pub mod _export {
}
}
-#[deprecated(since = "TBD", note = "unused now that `Hash::from_slice` is deprecated")]
-mod error;
mod internal_macros;
pub mod cmp;
@@ -153,11 +151,6 @@ pub use sha512_256::Hash as Sha512_256;
#[doc(inline)]
pub use siphash24::Hash as Siphash24;
-/// Attempted to create a hash from an invalid length slice.
-#[deprecated(since = "TBD", note = "unused now that `Hash::from_slice` is deprecated")]
-#[allow(deprecated_in_future)]
-pub type FromSliceError = crate::error::FromSliceError; // Alias instead of re-export so we can deprecate it.
-
/// Tagged SHA-256: Type alias for the [`sha256t::Hash`] hash type.
pub type Sha256t<T> = sha256t::Hash<T>;
diff --git a/hashes/tests/api.rs b/hashes/tests/api.rs
index afa3f9c2..bdb10145 100644
--- a/hashes/tests/api.rs
+++ b/hashes/tests/api.rs
@@ -14,7 +14,7 @@
// Import using module style e.g., `sha256::Hash`.
use bitcoin_hashes::{
hash160, hash_newtype, hkdf, hmac, ripemd160, sha1, sha256, sha256d, sha256t, sha256t_tag,
- sha384, sha3_256, sha512, sha512_256, siphash24, FromSliceError, Hash, HashEngine,
+ sha384, sha3_256, sha512, sha512_256, siphash24, Hash, HashEngine,
};
// Import using type alias style e.g., `Sha256`.
use bitcoin_hashes::{
@@ -165,7 +165,6 @@ struct Keyed<T: Hash> {
// These derives are the policy of `rust-bitcoin` not Rust API guidelines.
#[derive(Debug, Clone, PartialEq, Eq)] // All public types implement Debug (C-DEBUG).
struct Errors {
- a: FromSliceError,
b: hkdf::MaxLengthError,
c: sha256::MidstateError,
}
Why this scored 19/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.