diff --git a/bitcoin/src/blockdata/block.rs b/bitcoin/src/blockdata/block.rs index 247e98419..a9096e9b8 100644 --- a/bitcoin/src/blockdata/block.rs +++ b/bitcoin/src/blockdata/block.rs @@ -141,7 +141,8 @@ impl Block { .iter() .rposition(|o| o.script_pubkey.len() >= 38 && o.script_pubkey.as_bytes()[0..6] == MAGIC) { - let bytes = <[u8; 32]>::try_from(&coinbase.output[pos].script_pubkey.as_bytes()[6..38]).unwrap(); + let bytes = <[u8; 32]>::try_from(&coinbase.output[pos].script_pubkey.as_bytes()[6..38]) + .unwrap(); let commitment = WitnessCommitment::from_byte_array(bytes); // Witness reserved value is in coinbase input witness. let witness_vec: Vec<_> = coinbase.input[0].witness.iter().collect(); diff --git a/bitcoin/src/blockdata/witness.rs b/bitcoin/src/blockdata/witness.rs index 0264f7fa7..08e39d483 100644 --- a/bitcoin/src/blockdata/witness.rs +++ b/bitcoin/src/blockdata/witness.rs @@ -140,7 +140,7 @@ crate::internal_macros::define_extension_trait! { fn push_ecdsa_signature(&mut self, signature: ecdsa::Signature) { self.push(signature.serialize()) } - + /// Get Tapscript following BIP341 rules regarding accounting for an annex. /// /// This does not guarantee that this represents a P2TR [`Witness`]. It diff --git a/bitcoin/src/psbt/macros.rs b/bitcoin/src/psbt/macros.rs index f5134946b..52fe7e725 100644 --- a/bitcoin/src/psbt/macros.rs +++ b/bitcoin/src/psbt/macros.rs @@ -174,7 +174,8 @@ macro_rules! impl_psbt_hash_deserialize { impl $crate::psbt::serialize::Deserialize for $hash_type { fn deserialize(bytes: &[u8]) -> core::result::Result { const LEN: usize = <$hash_type as hashes::Hash>::LEN; - let bytes = <[u8; LEN]>::try_from(bytes).map_err(|e| $crate::psbt::Error::from(e))?; + let bytes = + <[u8; LEN]>::try_from(bytes).map_err(|e| $crate::psbt::Error::from(e))?; Ok(<$hash_type>::from_byte_array(bytes)) } } diff --git a/bitcoin/src/psbt/raw.rs b/bitcoin/src/psbt/raw.rs index 539298013..906af3b63 100644 --- a/bitcoin/src/psbt/raw.rs +++ b/bitcoin/src/psbt/raw.rs @@ -7,12 +7,12 @@ use core::fmt; -use internals::{ToU64 as _}; +use internals::ToU64 as _; use io::{BufRead, Write}; use super::serialize::{Deserialize, Serialize}; use crate::consensus::encode::{ - self, deserialize, serialize, Decodable, Encodable, MAX_VEC_SIZE, ReadExt, WriteExt, + self, deserialize, serialize, Decodable, Encodable, ReadExt, WriteExt, MAX_VEC_SIZE, }; use crate::prelude::{DisplayHex, Vec}; use crate::psbt::Error; @@ -24,7 +24,7 @@ use crate::psbt::Error; #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Key { /// The type of this PSBT key. - pub type_value: u64, // Encoded as a compact size. + pub type_value: u64, // Encoded as a compact size. /// The key data itself in raw byte form. #[cfg_attr(feature = "serde", serde(with = "crate::serde_utils::hex_bytes"))] pub key_data: Vec, diff --git a/bitcoin/src/taproot/merkle_branch.rs b/bitcoin/src/taproot/merkle_branch.rs index 0be4772c1..1af04212b 100644 --- a/bitcoin/src/taproot/merkle_branch.rs +++ b/bitcoin/src/taproot/merkle_branch.rs @@ -53,7 +53,8 @@ impl TaprootMerkleBranch { let inner = sl .chunks_exact(TAPROOT_CONTROL_NODE_SIZE) .map(|chunk| { - let bytes = <[u8; 32]>::try_from(chunk).expect("chunks_exact always returns the correct size"); + let bytes = <[u8; 32]>::try_from(chunk) + .expect("chunks_exact always returns the correct size"); TapNodeHash::from_byte_array(bytes) }) .collect(); diff --git a/bitcoin/src/taproot/mod.rs b/bitcoin/src/taproot/mod.rs index 5be2d3073..b18d87a7e 100644 --- a/bitcoin/src/taproot/mod.rs +++ b/bitcoin/src/taproot/mod.rs @@ -1854,8 +1854,16 @@ mod test { #[test] #[cfg(feature = "serde")] fn test_merkle_branch_serde() { - let hash1 = TapNodeHash("03ba2a4dcd914fed29a1c630c7e811271b081a0e2f2f52cf1c197583dfd46c1b".parse::>().unwrap()); - let hash2 = TapNodeHash("8d79dedc2fa0b55167b5d28c61dbad9ce1191a433f3a1a6c8ee291631b2c94c9".parse::>().unwrap()); + let hash1 = TapNodeHash( + "03ba2a4dcd914fed29a1c630c7e811271b081a0e2f2f52cf1c197583dfd46c1b" + .parse::>() + .unwrap(), + ); + let hash2 = TapNodeHash( + "8d79dedc2fa0b55167b5d28c61dbad9ce1191a433f3a1a6c8ee291631b2c94c9" + .parse::>() + .unwrap(), + ); let merkle_branch = TaprootMerkleBranch::from([hash1, hash2]); // use serde_test to test serialization and deserialization serde_test::assert_tokens( diff --git a/chacha20_poly1305/src/chacha20.rs b/chacha20_poly1305/src/chacha20.rs index 5c64da40f..8f53e60c7 100644 --- a/chacha20_poly1305/src/chacha20.rs +++ b/chacha20_poly1305/src/chacha20.rs @@ -19,9 +19,7 @@ pub struct Key([u8; 32]); impl Key { /// Create a new key. - pub const fn new(key: [u8; 32]) -> Self { - Key(key) - } + pub const fn new(key: [u8; 32]) -> Self { Key(key) } } /// A 96-bit initialization vector (IV), or nonce. @@ -30,9 +28,7 @@ pub struct Nonce([u8; 12]); impl Nonce { /// Create a new nonce. - pub const fn new(nonce: [u8; 12]) -> Self { - Nonce(nonce) - } + pub const fn new(nonce: [u8; 12]) -> Self { Nonce(nonce) } } /// A SIMD-friendly structure which holds 25% of the cipher state. @@ -330,9 +326,10 @@ fn keystream_at_slice(key: Key, nonce: Nonce, count: u32, seek: usize) -> [u8; 6 #[cfg(test)] #[cfg(feature = "alloc")] mod tests { - use super::*; use hex::prelude::*; + use super::*; + #[test] fn test_chacha_block() { let mut state = State { diff --git a/chacha20_poly1305/src/lib.rs b/chacha20_poly1305/src/lib.rs index bc37ecdbc..b8aaba5cc 100644 --- a/chacha20_poly1305/src/lib.rs +++ b/chacha20_poly1305/src/lib.rs @@ -6,11 +6,11 @@ pub mod chacha20; pub mod poly1305; +use core::fmt; + use chacha20::ChaCha20; use poly1305::Poly1305; -use core::fmt; - pub use self::chacha20::{Key, Nonce}; /// Zero array for padding slices. @@ -48,9 +48,7 @@ pub struct ChaCha20Poly1305 { impl ChaCha20Poly1305 { /// Make a new instance of a ChaCha20Poly1305 AEAD. - pub const fn new(key: Key, nonce: Nonce) -> Self { - ChaCha20Poly1305 { key, nonce } - } + pub const fn new(key: Key, nonce: Nonce) -> Self { ChaCha20Poly1305 { key, nonce } } /// Encrypt content in place and return the Poly1305 16-byte authentication tag. /// @@ -145,9 +143,10 @@ fn encode_lengths(aad_len: u64, content_len: u64) -> [u8; 16] { #[cfg(test)] #[cfg(feature = "alloc")] mod tests { - use super::*; use hex::prelude::*; + use super::*; + #[test] fn test_rfc7539() { let mut message = *b"Ladies and Gentlemen of the class of '99: If I could offer you only one tip for the future, sunscreen would be it."; diff --git a/chacha20_poly1305/src/poly1305.rs b/chacha20_poly1305/src/poly1305.rs index 0de1f8ba4..72a16e45a 100644 --- a/chacha20_poly1305/src/poly1305.rs +++ b/chacha20_poly1305/src/poly1305.rs @@ -223,9 +223,10 @@ fn _print_acc(num: &[u32; 5]) { #[cfg(test)] #[cfg(feature = "alloc")] mod tests { - use super::*; use hex::prelude::*; + use super::*; + #[test] fn test_rfc7539() { let key = Vec::from_hex("85d6be7857556d337f4452fe42d506a80103808afb0db2fd4abff6af4149f51b") diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 2cef130e6..209fd3db9 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -46,12 +46,6 @@ pub mod witness; #[doc(inline)] pub use units::*; -#[doc(inline)] -#[cfg(feature = "alloc")] -pub use self::{ - locktime::{absolute, relative}, - witness::Witness, -}; #[doc(inline)] pub use self::{ block::{BlockHash, WitnessCommitment}, @@ -59,6 +53,12 @@ pub use self::{ sequence::Sequence, transaction::{Txid, Wtxid}, }; +#[doc(inline)] +#[cfg(feature = "alloc")] +pub use self::{ + locktime::{absolute, relative}, + witness::Witness, +}; #[rustfmt::skip] #[allow(unused_imports)] diff --git a/primitives/src/witness.rs b/primitives/src/witness.rs index 30c119be5..d5d8eb833 100644 --- a/primitives/src/witness.rs +++ b/primitives/src/witness.rs @@ -63,8 +63,12 @@ impl Witness { /// UNSTABLE: This function may change, break, or disappear in any release. #[inline] #[doc(hidden)] - #[allow(non_snake_case)] // Because of `__unstable`. - pub fn from_parts__unstable(content: Vec, witness_elements: usize, indices_start: usize) -> Self { + #[allow(non_snake_case)] // Because of `__unstable`. + pub fn from_parts__unstable( + content: Vec, + witness_elements: usize, + indices_start: usize, + ) -> Self { Witness { content, witness_elements, indices_start } } @@ -462,11 +466,7 @@ mod test { // The last four bytes represent start at index 0. let content = [0_u8; 5]; - Witness { - witness_elements: 1, - content: content.to_vec(), - indices_start: 1, - } + Witness { witness_elements: 1, content: content.to_vec(), indices_start: 1 } } #[test] @@ -568,7 +568,7 @@ mod test { #[test] fn exact_sized_iterator() { let arbitrary_element = [1_u8, 2, 3]; - let num_pushes = 5; // Somewhat arbitrary. + let num_pushes = 5; // Somewhat arbitrary. let mut witness = Witness::default(); @@ -623,7 +623,6 @@ mod test { let ser = serde_json::to_string(&original).unwrap(); let rinsed: Witness = serde_json::from_str(&ser).unwrap(); assert_eq!(rinsed, original); - } #[test]