hashes: Remove code deprecated in 0.15.0
What changed, and why it matters
This commit removes old, deprecated functions from the rust-bitcoin `hashes` crate that were marked for removal two releases ago. It is a routine cleanup change: it deletes functions like `from_slice`, `const_hash`, and `as_u64` that users were already warned not to use, and switches internal code to use the newer replacements. There is no bug fix or security patch here.
No security action required. Downstream users should ensure they are not relying on the removed deprecated functions (`from_slice`, `const_hash`, `as_u64`, `serde_macros`) before upgrading, as this is a breaking API change.
Security signals we found
No security-relevant code change identified
Removal of deprecated public API only
No memory-safety, cryptographic, or input-validation changes
Evidence from the diff
The commit deletes deprecated API surface introduced in hashes 0.15.0: Hash::from_slice and its implementations across HMAC, SHA-256, SHA-256 tagged, SipHash24, and macro-generated hash types; sha256::Hash::const_hash; siphash24::Hash::as_u64; and the serde_macros re-export module. It also updates the serde macro to import from crate::macros::serde_details directly. The stated motivation is project policy (remove deprecated items after two releases) and to simplify the upcoming primitives stable release by removing FromSliceError from cross-crate macro APIs. No vulnerability is fixed or introduced in the diff.
Changed components
hashes/src/hmac/mod.rshashes/src/internal_macros.rshashes/src/lib.rshashes/src/macros.rshashes/src/sha256/mod.rshashes/src/sha256t/mod.rshashes/src/siphash24/mod.rsInspect captured patch +1 / −86
diff --git a/hashes/src/hmac/mod.rs b/hashes/src/hmac/mod.rs
index aebe2e60..8651aa4d 100644
--- a/hashes/src/hmac/mod.rs
+++ b/hashes/src/hmac/mod.rs
@@ -123,11 +123,6 @@ impl<T: Hash> Hash for Hmac<T> {
fn from_byte_array(bytes: T::Bytes) -> Self { Hmac(T::from_byte_array(bytes)) }
- #[allow(deprecated_in_future)] // Because of `FromSliceError`.
- fn from_slice(sl: &[u8]) -> Result<Hmac<T>, crate::FromSliceError> {
- T::from_slice(sl).map(Hmac)
- }
-
fn to_byte_array(self) -> Self::Bytes { self.0.to_byte_array() }
fn as_byte_array(&self) -> &Self::Bytes { self.0.as_byte_array() }
diff --git a/hashes/src/internal_macros.rs b/hashes/src/internal_macros.rs
index 21f37dca..a837225a 100644
--- a/hashes/src/internal_macros.rs
+++ b/hashes/src/internal_macros.rs
@@ -34,12 +34,6 @@ macro_rules! hash_trait_impls {
fn from_byte_array(bytes: Self::Bytes) -> Self { Self::from_byte_array(bytes) }
- #[allow(deprecated_in_future)] // Because of `FromSliceError`.
- #[allow(deprecated)] // Because of `from_slice`.
- fn from_slice(sl: &[u8]) -> $crate::_export::_core::result::Result<Hash<$($gen),*>, $crate::FromSliceError> {
- Self::from_slice(sl)
- }
-
fn to_byte_array(self) -> Self::Bytes { self.to_byte_array() }
fn as_byte_array(&self) -> &Self::Bytes { self.as_byte_array() }
@@ -133,24 +127,6 @@ macro_rules! hash_type_no_default {
/// Constructs a new hash from the underlying byte array.
pub const fn from_byte_array(bytes: [u8; $bits / 8]) -> Self { Hash(bytes) }
- /// Copies a byte slice into a hash object.
- #[deprecated(since = "0.15.0", note = "use `from_byte_array` instead")]
- #[allow(deprecated_in_future)] // Because of `FromSliceError`.
- pub fn from_slice(
- sl: &[u8],
- ) -> $crate::_export::_core::result::Result<Hash, $crate::FromSliceError> {
- if sl.len() != $bits / 8 {
- Err($crate::error::FromSliceError($crate::error::FromSliceErrorInner {
- expected: $bits / 8,
- got: sl.len(),
- }))
- } else {
- let mut ret = [0; $bits / 8];
- ret.copy_from_slice(sl);
- Ok(Self::from_byte_array(ret))
- }
- }
-
/// Returns the underlying byte array.
pub const fn to_byte_array(self) -> [u8; $bits / 8] { self.0 }
diff --git a/hashes/src/lib.rs b/hashes/src/lib.rs
index 9258b1ad..5242ef53 100644
--- a/hashes/src/lib.rs
+++ b/hashes/src/lib.rs
@@ -117,17 +117,6 @@ pub mod sha512;
pub mod sha512_256;
pub mod siphash24;
-#[deprecated(since = "0.15.0", note = "use crate::macros instead")]
-pub mod serde_macros {
- //! Macros for serde trait implementations, and supporting code.
-
- #[cfg(feature = "serde")]
- pub mod serde_details {
- //! Functions used by serde impls of all hashes.
- pub use crate::macros::serde_details::*;
- }
-}
-
use core::fmt::{self, Write as _};
use core::{convert, hash};
@@ -227,11 +216,6 @@ pub trait Hash:
/// Constructs a new hash from the underlying byte array.
fn from_byte_array(bytes: Self::Bytes) -> Self;
- /// Copies a byte slice into a hash object.
- #[allow(deprecated_in_future)] // Because of `FromSliceError`.
- #[deprecated(since = "TBD", note = "use `from_byte_array` instead")]
- fn from_slice(sl: &[u8]) -> Result<Self, FromSliceError>;
-
/// Returns the underlying byte array.
fn to_byte_array(self) -> Self::Bytes;
diff --git a/hashes/src/macros.rs b/hashes/src/macros.rs
index d45ebbc5..2b1f8071 100644
--- a/hashes/src/macros.rs
+++ b/hashes/src/macros.rs
@@ -139,14 +139,6 @@ macro_rules! hash_newtype {
$newtype(<$hash>::from_byte_array(bytes))
}
- /// Copies a byte slice into a hash object.
- #[deprecated(since = "0.15.0", note = "use `from_byte_array` instead")]
- #[allow(deprecated_in_future)] // Because of `FromSliceError`.
- #[allow(deprecated)] // Because of `from_slice`.
- pub fn from_slice(sl: &[u8]) -> $crate::_export::_core::result::Result<$newtype, $crate::FromSliceError> {
- Ok($newtype(<$hash as $crate::Hash>::from_slice(sl)?))
- }
-
/// Returns the underlying byte array.
pub const fn to_byte_array(self) -> <$hash as $crate::Hash>::Bytes {
self.0.to_byte_array()
@@ -165,13 +157,6 @@ macro_rules! hash_newtype {
fn from_byte_array(bytes: Self::Bytes) -> Self { Self::from_byte_array(bytes) }
- #[inline]
- #[allow(deprecated_in_future)] // Because of `FromSliceError`.
- #[allow(deprecated)] // Because of `from_slice`.
- fn from_slice(sl: &[u8]) -> $crate::_export::_core::result::Result<$newtype, $crate::FromSliceError> {
- Self::from_slice(sl)
- }
-
fn to_byte_array(self) -> Self::Bytes { self.to_byte_array() }
fn as_byte_array(&self) -> &Self::Bytes { self.as_byte_array() }
@@ -506,7 +491,7 @@ macro_rules! serde_impl(
impl<'de $(, $gen: $gent)*> $crate::serde::Deserialize<'de> for $t<$($gen),*> {
fn deserialize<D: $crate::serde::Deserializer<'de>>(d: D) -> core::result::Result<$t<$($gen),*>, D::Error> {
- use $crate::serde_macros::serde_details::{BytesVisitor, HexVisitor};
+ use $crate::macros::serde_details::{BytesVisitor, HexVisitor};
if d.is_human_readable() {
d.deserialize_str(HexVisitor::<Self>::default())
diff --git a/hashes/src/sha256/mod.rs b/hashes/src/sha256/mod.rs
index 39c3257b..cea61a63 100644
--- a/hashes/src/sha256/mod.rs
+++ b/hashes/src/sha256/mod.rs
@@ -147,12 +147,6 @@ impl Hash {
#[must_use]
pub fn hash_again(&self) -> sha256d::Hash { sha256d::Hash::from_byte_array(hash(&self.0).0) }
- /// Computes hash from `bytes` in `const` context.
- ///
- /// Warning: this function is inefficient. It should be only used in `const` context.
- #[deprecated(since = "0.15.0", note = "use `Self::hash_unoptimized` instead")]
- pub const fn const_hash(bytes: &[u8]) -> Self { Hash::hash_unoptimized(bytes) }
-
/// Computes hash from `bytes` in `const` context.
///
/// Warning: this function is inefficient. It should be only used in `const` context.
diff --git a/hashes/src/sha256t/mod.rs b/hashes/src/sha256t/mod.rs
index 5b6d91db..b1a3c5dc 100644
--- a/hashes/src/sha256t/mod.rs
+++ b/hashes/src/sha256t/mod.rs
@@ -65,21 +65,6 @@ where
/// Constructs a new hash from the underlying byte array.
pub const fn from_byte_array(bytes: [u8; 32]) -> Self { Self(PhantomData, bytes) }
- /// Copies a byte slice into a hash object.
- #[deprecated(since = "0.15.0", note = "use `from_byte_array` instead")]
- #[allow(deprecated_in_future)] // Because of `FromSliceError`.
- pub fn from_slice(sl: &[u8]) -> Result<Hash<T>, crate::FromSliceError> {
- use crate::error::FromSliceErrorInner;
-
- if sl.len() != 32 {
- Err(crate::error::FromSliceError(FromSliceErrorInner { expected: 32, got: sl.len() }))
- } else {
- let mut ret = [0; 32];
- ret.copy_from_slice(sl);
- Ok(Self::from_byte_array(ret))
- }
- }
-
/// Produces a hash from the current state of a given engine.
pub fn from_engine(e: HashEngine<T>) -> Self {
Hash::from_byte_array(sha256::Hash::from_engine(e.0).to_byte_array())
diff --git a/hashes/src/siphash24/mod.rs b/hashes/src/siphash24/mod.rs
index c5353629..664ee670 100644
--- a/hashes/src/siphash24/mod.rs
+++ b/hashes/src/siphash24/mod.rs
@@ -207,10 +207,6 @@ impl Hash {
state.v0 ^ state.v1 ^ state.v2 ^ state.v3
}
- /// Returns the (little endian) 64-bit integer representation of the hash value.
- #[deprecated(since = "0.15.0", note = "use `to_u64` instead")]
- pub fn as_u64(&self) -> u64 { self.to_u64() }
-
/// Returns the (little endian) 64-bit integer representation of the hash value.
pub fn to_u64(self) -> u64 { u64::from_le_bytes(self.0) }
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.