From 52c457905762417b7b7d33bbaab976cc56d22e9c Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 22 Feb 2023 10:04:08 +1100 Subject: [PATCH] Enable formatting for hashes The `hashes` module contains a bunch of arrays, mostly formatted with 8 hex bytes on a line; add `rustfmt::skip` to keep the formatting of arrays as is. Remove the exclude for the `hashes` crate. Do not run the formatter, that will be done as a separate patch to aid review. --- hashes/src/hash160.rs | 2 ++ hashes/src/hmac.rs | 2 ++ hashes/src/ripemd160.rs | 2 ++ hashes/src/sha1.rs | 3 ++- hashes/src/sha256.rs | 19 +++++++++++++------ hashes/src/sha256d.rs | 2 ++ hashes/src/sha512.rs | 3 +++ hashes/src/sha512_256.rs | 2 ++ hashes/src/siphash24.rs | 1 + rustfmt.toml | 6 +----- 10 files changed, 30 insertions(+), 12 deletions(-) diff --git a/hashes/src/hash160.rs b/hashes/src/hash160.rs index 51462441..367832ee 100644 --- a/hashes/src/hash160.rs +++ b/hashes/src/hash160.rs @@ -61,6 +61,7 @@ mod tests { output_str: &'static str, } + #[rustfmt::skip] let tests = vec![ // Uncompressed pubkey obtained from Bitcoin key; data from validateaddress Test { @@ -107,6 +108,7 @@ mod tests { use serde_test::{Configure, Token, assert_tokens}; use crate::{hash160, Hash}; + #[rustfmt::skip] static HASH_BYTES: [u8; 20] = [ 0x13, 0x20, 0x72, 0xdf, 0x69, 0x09, 0x33, 0x83, diff --git a/hashes/src/hmac.rs b/hashes/src/hmac.rs index 22afd7d1..0dcfd6c2 100644 --- a/hashes/src/hmac.rs +++ b/hashes/src/hmac.rs @@ -256,6 +256,7 @@ mod tests { output: Vec, } + #[rustfmt::skip] let tests = vec![ // Test vectors copied from libsecp256k1 // Sadly the RFC2104 test vectors all use MD5 as their underlying hash function, @@ -375,6 +376,7 @@ mod tests { use serde_test::{Configure, Token, assert_tokens}; use crate::{sha512, Hash, Hmac}; + #[rustfmt::skip] static HASH_BYTES: [u8; 64] = [ 0x8b, 0x41, 0xe1, 0xb7, 0x8a, 0xd1, 0x15, 0x21, 0x11, 0x3c, 0x52, 0xff, 0x18, 0x2a, 0x1b, 0x8e, diff --git a/hashes/src/ripemd160.rs b/hashes/src/ripemd160.rs index 591706b8..a450340d 100644 --- a/hashes/src/ripemd160.rs +++ b/hashes/src/ripemd160.rs @@ -416,6 +416,7 @@ mod tests { output_str: &'static str, } + #[rustfmt::skip] let tests = vec![ // Test messages from FIPS 180-1 Test { @@ -490,6 +491,7 @@ mod tests { use serde_test::{Configure, Token, assert_tokens}; use crate::{ripemd160, Hash}; + #[rustfmt::skip] static HASH_BYTES: [u8; 20] = [ 0x13, 0x20, 0x72, 0xdf, 0x69, 0x09, 0x33, 0x83, diff --git a/hashes/src/sha1.rs b/hashes/src/sha1.rs index 7fae399e..fe940b44 100644 --- a/hashes/src/sha1.rs +++ b/hashes/src/sha1.rs @@ -154,7 +154,7 @@ mod tests { output_str: &'static str, } - + #[rustfmt::skip] let tests = vec![ // Examples from wikipedia Test { @@ -216,6 +216,7 @@ mod tests { use serde_test::{Configure, Token, assert_tokens}; use crate::{sha1, Hash}; + #[rustfmt::skip] static HASH_BYTES: [u8; 20] = [ 0x13, 0x20, 0x72, 0xdf, 0x69, 0x09, 0x33, 0x83, diff --git a/hashes/src/sha256.rs b/hashes/src/sha256.rs index 5155615b..5cdde996 100644 --- a/hashes/src/sha256.rs +++ b/hashes/src/sha256.rs @@ -333,6 +333,7 @@ mod tests { output_str: &'static str, } + #[rustfmt::skip] let tests = vec![ // Examples from wikipedia Test { @@ -386,6 +387,7 @@ mod tests { } #[test] + #[rustfmt::skip] fn midstate() { // Test vector obtained by doing an asset issuance on Elements let mut engine = sha256::Hash::engine(); @@ -444,15 +446,19 @@ mod tests { // Test that a specific midstate results in a specific hash. Midstate was // obtained by applying sha256 to sha256("MuSig coefficient")||sha256("MuSig // coefficient"). + #[rustfmt::skip] static MIDSTATE: [u8; 32] = [ - 0x0f, 0xd0, 0x69, 0x0c, 0xfe, 0xfe, 0xae, 0x97, 0x99, 0x6e, 0xac, 0x7f, 0x5c, 0x30, - 0xd8, 0x64, 0x8c, 0x4a, 0x05, 0x73, 0xac, 0xa1, 0xa2, 0x2f, 0x6f, 0x43, 0xb8, 0x01, - 0x85, 0xce, 0x27, 0xcd, + 0x0f, 0xd0, 0x69, 0x0c, 0xfe, 0xfe, 0xae, 0x97, + 0x99, 0x6e, 0xac, 0x7f, 0x5c, 0x30, 0xd8, 0x64, + 0x8c, 0x4a, 0x05, 0x73, 0xac, 0xa1, 0xa2, 0x2f, + 0x6f, 0x43, 0xb8, 0x01, 0x85, 0xce, 0x27, 0xcd, ]; + #[rustfmt::skip] static HASH_EXPECTED: [u8; 32] = [ - 0x18, 0x84, 0xe4, 0x72, 0x40, 0x4e, 0xf4, 0x5a, 0xb4, 0x9c, 0x4e, 0xa4, 0x9a, 0xe6, - 0x23, 0xa8, 0x88, 0x52, 0x7f, 0x7d, 0x8a, 0x06, 0x94, 0x20, 0x8f, 0xf1, 0xf7, 0xa9, - 0xd5, 0x69, 0x09, 0x59, + 0x18, 0x84, 0xe4, 0x72, 0x40, 0x4e, 0xf4, 0x5a, + 0xb4, 0x9c, 0x4e, 0xa4, 0x9a, 0xe6, 0x23, 0xa8, + 0x88, 0x52, 0x7f, 0x7d, 0x8a, 0x06, 0x94, 0x20, + 0x8f, 0xf1, 0xf7, 0xa9, 0xd5, 0x69, 0x09, 0x59, ]; let midstate_engine = sha256::HashEngine::from_midstate(sha256::Midstate::from_byte_array(MIDSTATE), 64); @@ -465,6 +471,7 @@ mod tests { fn sha256_serde() { use serde_test::{Configure, Token, assert_tokens}; + #[rustfmt::skip] static HASH_BYTES: [u8; 32] = [ 0xef, 0x53, 0x7f, 0x25, 0xc8, 0x95, 0xbf, 0xa7, 0x82, 0x52, 0x65, 0x29, 0xa9, 0xb6, 0x3d, 0x97, diff --git a/hashes/src/sha256d.rs b/hashes/src/sha256d.rs index ec227a9f..0b01710c 100644 --- a/hashes/src/sha256d.rs +++ b/hashes/src/sha256d.rs @@ -55,6 +55,7 @@ mod tests { output_str: &'static str, } + #[rustfmt::skip] let tests = vec![ // Test vector copied out of rust-bitcoin Test { @@ -99,6 +100,7 @@ mod tests { use serde_test::{Configure, Token, assert_tokens}; use crate::{sha256d, Hash}; + #[rustfmt::skip] static HASH_BYTES: [u8; 32] = [ 0xef, 0x53, 0x7f, 0x25, 0xc8, 0x95, 0xbf, 0xa7, 0x82, 0x52, 0x65, 0x29, 0xa9, 0xb6, 0x3d, 0x97, diff --git a/hashes/src/sha512.rs b/hashes/src/sha512.rs index 9feaa3a5..67858592 100644 --- a/hashes/src/sha512.rs +++ b/hashes/src/sha512.rs @@ -40,6 +40,7 @@ pub struct HashEngine { } impl Default for HashEngine { + #[rustfmt::skip] fn default() -> Self { HashEngine { h: [ @@ -319,6 +320,7 @@ mod tests { output_str: &'static str, } + #[rustfmt::skip] let tests = vec![ // Test vectors computed with `sha512sum` Test { @@ -389,6 +391,7 @@ mod tests { use serde_test::{Configure, Token, assert_tokens}; use crate::{sha512, Hash}; + #[rustfmt::skip] static HASH_BYTES: [u8; 64] = [ 0x8b, 0x41, 0xe1, 0xb7, 0x8a, 0xd1, 0x15, 0x21, 0x11, 0x3c, 0x52, 0xff, 0x18, 0x2a, 0x1b, 0x8e, diff --git a/hashes/src/sha512_256.rs b/hashes/src/sha512_256.rs index ad146146..c967069e 100644 --- a/hashes/src/sha512_256.rs +++ b/hashes/src/sha512_256.rs @@ -40,6 +40,7 @@ use crate::{sha512, sha512::BLOCK_SIZE, Error}; pub struct HashEngine(sha512::HashEngine); impl Default for HashEngine { + #[rustfmt::skip] fn default() -> Self { HashEngine(sha512::HashEngine { h: [ @@ -97,6 +98,7 @@ mod tests { output_str: &'static str, } + #[rustfmt::skip] let tests = vec![ // Examples from go sha512/256 tests. Test { diff --git a/hashes/src/siphash24.rs b/hashes/src/siphash24.rs index 2729665a..85569485 100644 --- a/hashes/src/siphash24.rs +++ b/hashes/src/siphash24.rs @@ -286,6 +286,7 @@ mod tests { #[test] fn test_siphash_2_4() { + #[rustfmt::skip] let vecs: [[u8; 8]; 64] = [ [0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72], [0xfd, 0x67, 0xdc, 0x93, 0xc5, 0x39, 0xf8, 0x74], diff --git a/rustfmt.toml b/rustfmt.toml index bae46e28..2c104735 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,8 +1,4 @@ -# Eventually this shoud be: ignore = [] -ignore = [ - "hashes", -] - +ignore = [] hard_tabs = false tab_spaces = 4 newline_style = "Auto"