What changed, and why it matters
This commit is an automated code-formatting run by rustfmt. It only changes whitespace, line breaks, and the order of some module declarations and import lists. No program logic, algorithms, or security behavior were changed.
No security action needed; this is a routine formatting commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff shows pure formatting changes produced by rustfmt nightly: rewrapping long string literals and import lines, collapsing single-line const/fn bodies, and alphabetically reordering pub mod/pub use declarations (sha3_256 moved before sha512). The Keccak/SHA3-256 implementation is unchanged in behavior; only brace style and blank lines differ.
Changed components
bitcoin/examples/taproot-psbt.rshashes/src/lib.rshashes/src/sha3_256/mod.rshashes/tests/api.rshashes/tests/regression.rsInspect captured patch +19 / −29
diff --git a/bitcoin/examples/taproot-psbt.rs b/bitcoin/examples/taproot-psbt.rs
index 6dc8d980..d47d75ec 100644
--- a/bitcoin/examples/taproot-psbt.rs
+++ b/bitcoin/examples/taproot-psbt.rs
@@ -386,7 +386,9 @@ impl BenefactorWallet {
) -> Result<(Transaction, Psbt), Box<dyn std::error::Error>> {
if let ChildNumber::Normal { index } = self.next {
if index > 0 && self.current_spend_info.is_some() {
- return Err("transaction already exists, use refresh_tx to refresh the timelock".into());
+ return Err(
+ "transaction already exists, use refresh_tx to refresh the timelock".into()
+ );
}
}
// We use some other derivation path in this example for our inheritance protocol. The important thing is to ensure
diff --git a/hashes/src/lib.rs b/hashes/src/lib.rs
index 1d2c2b4e..de518bf9 100644
--- a/hashes/src/lib.rs
+++ b/hashes/src/lib.rs
@@ -113,10 +113,10 @@ pub mod sha256;
pub mod sha256d;
pub mod sha256t;
pub mod sha384;
+pub mod sha3_256;
pub mod sha512;
pub mod sha512_256;
pub mod siphash24;
-pub mod sha3_256;
use core::fmt::{self, Write as _};
use core::{convert, hash};
@@ -145,6 +145,8 @@ pub use sha256d::Hash as Sha256d;
/// SHA-384: Alias for the [`sha384::Hash`] hash type.
#[doc(inline)]
pub use sha384::Hash as Sha384;
+/// SHA3-256: Alias for the [`sha3_256::Hash`] hash type.
+pub use sha3_256::Hash as Sha3_256;
/// SHA-512: Alias for the [`sha512::Hash`] hash type.
#[doc(inline)]
pub use sha512::Hash as Sha512;
@@ -154,8 +156,6 @@ pub use sha512_256::Hash as Sha512_256;
/// SipHash-2-4: Alias for the [`siphash24::Hash`] hash type.
#[doc(inline)]
pub use siphash24::Hash as Siphash24;
-/// SHA3-256: Alias for the [`sha3_256::Hash`] hash type.
-pub use sha3_256::Hash as Sha3_256;
/// Attempted to create a hash from an invalid length slice.
#[deprecated(since = "TBD", note = "unused now that `Hash::from_slice` is deprecated")]
diff --git a/hashes/src/sha3_256/mod.rs b/hashes/src/sha3_256/mod.rs
index ee150beb..85091dd6 100644
--- a/hashes/src/sha3_256/mod.rs
+++ b/hashes/src/sha3_256/mod.rs
@@ -75,9 +75,7 @@ const ROTATION_OFFSETS: [[u32; 5]; 5] = [
// A `x` and `y` index into a flattened matrix.
#[inline(always)]
-const fn ind(x: usize, y: usize) -> usize {
- x + B * y
-}
+const fn ind(x: usize, y: usize) -> usize { x + B * y }
// A flattened 5x5 matrix of little-endian `u64`.
#[derive(Clone, Default)]
@@ -96,19 +94,13 @@ impl fmt::Debug for KeccakState {
}
impl KeccakState {
- const fn new() -> Self {
- Self([0u64; NUM_LANES])
- }
+ const fn new() -> Self { Self([0u64; NUM_LANES]) }
#[inline(always)]
- fn assign(&mut self, x: usize, y: usize, val: u64) {
- self.0[ind(x, y)] = val;
- }
+ fn assign(&mut self, x: usize, y: usize, val: u64) { self.0[ind(x, y)] = val; }
#[inline(always)]
- const fn lane(&self, x: usize, y: usize) -> u64 {
- self.0[ind(x, y)]
- }
+ const fn lane(&self, x: usize, y: usize) -> u64 { self.0[ind(x, y)] }
#[inline(always)]
const fn column_xor(&self, x: usize) -> u64 {
@@ -120,9 +112,7 @@ impl KeccakState {
}
#[inline(always)]
- fn xor_assign(&mut self, x: usize, y: usize, val: u64) {
- self.0[ind(x, y)] ^= val
- }
+ fn xor_assign(&mut self, x: usize, y: usize, val: u64) { self.0[ind(x, y)] ^= val }
#[inline(always)]
const fn chi(&self, x: usize, y: usize) -> u64 {
@@ -184,9 +174,7 @@ pub struct HashEngine {
impl HashEngine {
/// Construct a new Sha3-256 hash engine.
- pub const fn new() -> Self {
- Self { state: KeccakState::new(), bytes_hashed: 0 }
- }
+ pub const fn new() -> Self { Self { state: KeccakState::new(), bytes_hashed: 0 } }
fn absorb(&mut self, block: [u8; RATE]) {
for lane in 0..RATE_LANES {
@@ -223,9 +211,7 @@ impl crate::HashEngine for HashEngine {
keccakf1600(&mut self.state);
}
- fn n_bytes_hashed(&self) -> u64 {
- self.bytes_hashed
- }
+ fn n_bytes_hashed(&self) -> u64 { self.bytes_hashed }
fn finalize(self) -> Self::Hash {
let mut out = [0u8; 32];
@@ -243,7 +229,9 @@ impl crate::HashEngine for HashEngine {
mod tests {
use alloc::string::ToString;
use alloc::vec::Vec;
+
use hex::prelude::*;
+
use crate::HashEngine;
struct TestCase {
diff --git a/hashes/tests/api.rs b/hashes/tests/api.rs
index db0a99a3..7f60ad45 100644
--- a/hashes/tests/api.rs
+++ b/hashes/tests/api.rs
@@ -18,8 +18,8 @@ use bitcoin_hashes::{
};
// Import using type alias style e.g., `Sha256`.
use bitcoin_hashes::{
- Hash160, Hkdf, Hmac, HmacEngine, Ripemd160, Sha1, Sha256, Sha256d, Sha256t, Sha384, Sha3_256, Sha512,
- Sha512_256, Siphash24,
+ Hash160, Hkdf, Hmac, HmacEngine, Ripemd160, Sha1, Sha256, Sha256d, Sha256t, Sha384, Sha3_256,
+ Sha512, Sha512_256, Siphash24,
};
// Arbitrary midstate value; taken from as sha256t unit tests.
diff --git a/hashes/tests/regression.rs b/hashes/tests/regression.rs
index 219ce55a..eb511e31 100644
--- a/hashes/tests/regression.rs
+++ b/hashes/tests/regression.rs
@@ -9,8 +9,8 @@
#![allow(clippy::uninlined_format_args)] // Allow `format!("{}", x)`instead of enforcing `format!("{x}")`
use bitcoin_hashes::{
- hash160, ripemd160, sha1, sha256, sha256d, sha256t, sha384, sha3_256, sha512, sha512_256, siphash24,
- HashEngine as _, HmacEngine,
+ hash160, ripemd160, sha1, sha256, sha256d, sha256t, sha384, sha3_256, sha512, sha512_256,
+ siphash24, HashEngine as _, HmacEngine,
};
const DATA: &str = "arbitrary data to hash as a regression test";
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.