What changed, and why it matters
This commit is a test-only fix. The developers accidentally removed the lines that include separate test files for several hash modules (RIPEMD160, SHA1, SHA256, SHA512), meaning those tests were not being compiled or run. The commit re-adds those test modules and makes minor updates to the tests themselves so they compile with the current API. There is no change to production code and no security vulnerability is introduced or fixed.
No security action required. Ensure CI enforces that all `#[cfg(test)] mod tests;` declarations are present and that test coverage does not silently regress.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds #[cfg(test)] mod tests; declarations back into ripemd160/mod.rs, sha1/mod.rs, sha256/mod.rs, and sha512/mod.rs. It also updates tests.rs files to use Hash::from_byte_array(...) instead of the removed from_slice API, removes an unnecessary pub(crate) visibility on a test function, and deletes a duplicate/obsolete const_midstate test. No library logic is modified.
Changed components
hashes/src/ripemd160/mod.rshashes/src/ripemd160/tests.rshashes/src/sha1/mod.rshashes/src/sha1/tests.rshashes/src/sha256/mod.rshashes/src/sha256/tests.rshashes/src/sha512/mod.rshashes/src/sha512/tests.rsInspect captured patch +13 / −8
diff --git a/hashes/src/ripemd160/mod.rs b/hashes/src/ripemd160/mod.rs
index de98690c..4c63eac8 100644
--- a/hashes/src/ripemd160/mod.rs
+++ b/hashes/src/ripemd160/mod.rs
@@ -4,6 +4,8 @@
use internals::slice::SliceExt;
mod crypto;
+#[cfg(test)]
+mod tests;
use core::cmp;
diff --git a/hashes/src/ripemd160/tests.rs b/hashes/src/ripemd160/tests.rs
index 3b9a324b..8eb9061a 100644
--- a/hashes/src/ripemd160/tests.rs
+++ b/hashes/src/ripemd160/tests.rs
@@ -100,7 +100,7 @@ fn ripemd_serde() {
0xf1, 0x4a, 0xca, 0xd7,
];
- let hash = ripemd160::Hash::from_slice(&HASH_BYTES).expect("right number of bytes");
+ let hash = ripemd160::Hash::from_byte_array(HASH_BYTES);
assert_tokens(&hash.compact(), &[Token::BorrowedBytes(&HASH_BYTES[..])]);
assert_tokens(&hash.readable(), &[Token::Str("132072df690933835eb8b6ad0b77e7b6f14acad7")]);
}
diff --git a/hashes/src/sha1/mod.rs b/hashes/src/sha1/mod.rs
index 1451f0c3..700c4746 100644
--- a/hashes/src/sha1/mod.rs
+++ b/hashes/src/sha1/mod.rs
@@ -4,6 +4,8 @@
use internals::slice::SliceExt;
mod crypto;
+#[cfg(test)]
+mod tests;
use core::cmp;
diff --git a/hashes/src/sha1/tests.rs b/hashes/src/sha1/tests.rs
index ce30cd33..831457ac 100644
--- a/hashes/src/sha1/tests.rs
+++ b/hashes/src/sha1/tests.rs
@@ -85,7 +85,7 @@ fn sha1_serde() {
0xf1, 0x4a, 0xca, 0xd7,
];
- let hash = sha1::Hash::from_slice(&HASH_BYTES).expect("right number of bytes");
+ let hash = sha1::Hash::from_byte_array(HASH_BYTES);
assert_tokens(&hash.compact(), &[Token::BorrowedBytes(&HASH_BYTES[..])]);
assert_tokens(&hash.readable(), &[Token::Str("132072df690933835eb8b6ad0b77e7b6f14acad7")]);
}
diff --git a/hashes/src/sha256/mod.rs b/hashes/src/sha256/mod.rs
index 5234dcba..fe6da741 100644
--- a/hashes/src/sha256/mod.rs
+++ b/hashes/src/sha256/mod.rs
@@ -3,6 +3,8 @@
//! SHA256 implementation.
mod crypto;
+#[cfg(test)]
+mod tests;
use core::{cmp, convert, fmt};
diff --git a/hashes/src/sha256/tests.rs b/hashes/src/sha256/tests.rs
index 4e45ae65..faf0f520 100644
--- a/hashes/src/sha256/tests.rs
+++ b/hashes/src/sha256/tests.rs
@@ -83,7 +83,7 @@ fn fmt_roundtrips() {
#[test]
#[rustfmt::skip]
-pub(crate) fn midstate() {
+fn midstate() {
// Test vector obtained by doing an asset issuance on Elements
let mut engine = sha256::Hash::engine();
// sha256dhash of outpoint
@@ -186,9 +186,6 @@ const TAP_LEAF_MIDSTATE: Midstate = Midstate::new(
64,
);
-#[test]
-fn const_midstate() { assert_eq!(Midstate::hash_tag(b"TapLeaf"), TAP_LEAF_MIDSTATE,) }
-
#[test]
#[cfg(feature = "alloc")]
fn regression_midstate_debug_format() {
@@ -212,7 +209,7 @@ fn sha256_serde() {
0xb7, 0x65, 0x44, 0x8c, 0x86, 0x35, 0xfb, 0x6c,
];
- let hash = sha256::Hash::from_slice(&HASH_BYTES).expect("right number of bytes");
+ let hash = sha256::Hash::from_byte_array(HASH_BYTES);
assert_tokens(&hash.compact(), &[Token::BorrowedBytes(&HASH_BYTES[..])]);
assert_tokens(
&hash.readable(),
diff --git a/hashes/src/sha512/mod.rs b/hashes/src/sha512/mod.rs
index a2f72130..b71c5cac 100644
--- a/hashes/src/sha512/mod.rs
+++ b/hashes/src/sha512/mod.rs
@@ -5,6 +5,8 @@
use internals::slice::SliceExt;
mod crypto;
+#[cfg(test)]
+mod tests;
use core::cmp;
diff --git a/hashes/src/sha512/tests.rs b/hashes/src/sha512/tests.rs
index ecf78582..4d982fd9 100644
--- a/hashes/src/sha512/tests.rs
+++ b/hashes/src/sha512/tests.rs
@@ -97,7 +97,7 @@ fn sha512_serde() {
0x0b, 0x2d, 0x8a, 0x60, 0x0b, 0xdf, 0x4c, 0x0c,
];
- let hash = sha512::Hash::from_slice(&HASH_BYTES).expect("right number of bytes");
+ let hash = sha512::Hash::from_byte_array(HASH_BYTES);
assert_tokens(&hash.compact(), &[Token::BorrowedBytes(&HASH_BYTES[..])]);
assert_tokens(
&hash.readable(),
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.