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.
This commit is contained in:
Tobin C. Harding 2023-02-22 10:04:08 +11:00
parent 3f16b6bf9f
commit 52c4579057
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
10 changed files with 30 additions and 12 deletions

View File

@ -61,6 +61,7 @@ mod tests {
output_str: &'static str, output_str: &'static str,
} }
#[rustfmt::skip]
let tests = vec![ let tests = vec![
// Uncompressed pubkey obtained from Bitcoin key; data from validateaddress // Uncompressed pubkey obtained from Bitcoin key; data from validateaddress
Test { Test {
@ -107,6 +108,7 @@ mod tests {
use serde_test::{Configure, Token, assert_tokens}; use serde_test::{Configure, Token, assert_tokens};
use crate::{hash160, Hash}; use crate::{hash160, Hash};
#[rustfmt::skip]
static HASH_BYTES: [u8; 20] = [ static HASH_BYTES: [u8; 20] = [
0x13, 0x20, 0x72, 0xdf, 0x13, 0x20, 0x72, 0xdf,
0x69, 0x09, 0x33, 0x83, 0x69, 0x09, 0x33, 0x83,

View File

@ -256,6 +256,7 @@ mod tests {
output: Vec<u8>, output: Vec<u8>,
} }
#[rustfmt::skip]
let tests = vec![ let tests = vec![
// Test vectors copied from libsecp256k1 // Test vectors copied from libsecp256k1
// Sadly the RFC2104 test vectors all use MD5 as their underlying hash function, // 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 serde_test::{Configure, Token, assert_tokens};
use crate::{sha512, Hash, Hmac}; use crate::{sha512, Hash, Hmac};
#[rustfmt::skip]
static HASH_BYTES: [u8; 64] = [ static HASH_BYTES: [u8; 64] = [
0x8b, 0x41, 0xe1, 0xb7, 0x8a, 0xd1, 0x15, 0x21, 0x8b, 0x41, 0xe1, 0xb7, 0x8a, 0xd1, 0x15, 0x21,
0x11, 0x3c, 0x52, 0xff, 0x18, 0x2a, 0x1b, 0x8e, 0x11, 0x3c, 0x52, 0xff, 0x18, 0x2a, 0x1b, 0x8e,

View File

@ -416,6 +416,7 @@ mod tests {
output_str: &'static str, output_str: &'static str,
} }
#[rustfmt::skip]
let tests = vec![ let tests = vec![
// Test messages from FIPS 180-1 // Test messages from FIPS 180-1
Test { Test {
@ -490,6 +491,7 @@ mod tests {
use serde_test::{Configure, Token, assert_tokens}; use serde_test::{Configure, Token, assert_tokens};
use crate::{ripemd160, Hash}; use crate::{ripemd160, Hash};
#[rustfmt::skip]
static HASH_BYTES: [u8; 20] = [ static HASH_BYTES: [u8; 20] = [
0x13, 0x20, 0x72, 0xdf, 0x13, 0x20, 0x72, 0xdf,
0x69, 0x09, 0x33, 0x83, 0x69, 0x09, 0x33, 0x83,

View File

@ -154,7 +154,7 @@ mod tests {
output_str: &'static str, output_str: &'static str,
} }
#[rustfmt::skip]
let tests = vec![ let tests = vec![
// Examples from wikipedia // Examples from wikipedia
Test { Test {
@ -216,6 +216,7 @@ mod tests {
use serde_test::{Configure, Token, assert_tokens}; use serde_test::{Configure, Token, assert_tokens};
use crate::{sha1, Hash}; use crate::{sha1, Hash};
#[rustfmt::skip]
static HASH_BYTES: [u8; 20] = [ static HASH_BYTES: [u8; 20] = [
0x13, 0x20, 0x72, 0xdf, 0x13, 0x20, 0x72, 0xdf,
0x69, 0x09, 0x33, 0x83, 0x69, 0x09, 0x33, 0x83,

View File

@ -333,6 +333,7 @@ mod tests {
output_str: &'static str, output_str: &'static str,
} }
#[rustfmt::skip]
let tests = vec![ let tests = vec![
// Examples from wikipedia // Examples from wikipedia
Test { Test {
@ -386,6 +387,7 @@ mod tests {
} }
#[test] #[test]
#[rustfmt::skip]
fn midstate() { fn midstate() {
// Test vector obtained by doing an asset issuance on Elements // Test vector obtained by doing an asset issuance on Elements
let mut engine = sha256::Hash::engine(); let mut engine = sha256::Hash::engine();
@ -444,15 +446,19 @@ mod tests {
// Test that a specific midstate results in a specific hash. Midstate was // Test that a specific midstate results in a specific hash. Midstate was
// obtained by applying sha256 to sha256("MuSig coefficient")||sha256("MuSig // obtained by applying sha256 to sha256("MuSig coefficient")||sha256("MuSig
// coefficient"). // coefficient").
#[rustfmt::skip]
static MIDSTATE: [u8; 32] = [ static MIDSTATE: [u8; 32] = [
0x0f, 0xd0, 0x69, 0x0c, 0xfe, 0xfe, 0xae, 0x97, 0x99, 0x6e, 0xac, 0x7f, 0x5c, 0x30, 0x0f, 0xd0, 0x69, 0x0c, 0xfe, 0xfe, 0xae, 0x97,
0xd8, 0x64, 0x8c, 0x4a, 0x05, 0x73, 0xac, 0xa1, 0xa2, 0x2f, 0x6f, 0x43, 0xb8, 0x01, 0x99, 0x6e, 0xac, 0x7f, 0x5c, 0x30, 0xd8, 0x64,
0x85, 0xce, 0x27, 0xcd, 0x8c, 0x4a, 0x05, 0x73, 0xac, 0xa1, 0xa2, 0x2f,
0x6f, 0x43, 0xb8, 0x01, 0x85, 0xce, 0x27, 0xcd,
]; ];
#[rustfmt::skip]
static HASH_EXPECTED: [u8; 32] = [ static HASH_EXPECTED: [u8; 32] = [
0x18, 0x84, 0xe4, 0x72, 0x40, 0x4e, 0xf4, 0x5a, 0xb4, 0x9c, 0x4e, 0xa4, 0x9a, 0xe6, 0x18, 0x84, 0xe4, 0x72, 0x40, 0x4e, 0xf4, 0x5a,
0x23, 0xa8, 0x88, 0x52, 0x7f, 0x7d, 0x8a, 0x06, 0x94, 0x20, 0x8f, 0xf1, 0xf7, 0xa9, 0xb4, 0x9c, 0x4e, 0xa4, 0x9a, 0xe6, 0x23, 0xa8,
0xd5, 0x69, 0x09, 0x59, 0x88, 0x52, 0x7f, 0x7d, 0x8a, 0x06, 0x94, 0x20,
0x8f, 0xf1, 0xf7, 0xa9, 0xd5, 0x69, 0x09, 0x59,
]; ];
let midstate_engine = let midstate_engine =
sha256::HashEngine::from_midstate(sha256::Midstate::from_byte_array(MIDSTATE), 64); sha256::HashEngine::from_midstate(sha256::Midstate::from_byte_array(MIDSTATE), 64);
@ -465,6 +471,7 @@ mod tests {
fn sha256_serde() { fn sha256_serde() {
use serde_test::{Configure, Token, assert_tokens}; use serde_test::{Configure, Token, assert_tokens};
#[rustfmt::skip]
static HASH_BYTES: [u8; 32] = [ static HASH_BYTES: [u8; 32] = [
0xef, 0x53, 0x7f, 0x25, 0xc8, 0x95, 0xbf, 0xa7, 0xef, 0x53, 0x7f, 0x25, 0xc8, 0x95, 0xbf, 0xa7,
0x82, 0x52, 0x65, 0x29, 0xa9, 0xb6, 0x3d, 0x97, 0x82, 0x52, 0x65, 0x29, 0xa9, 0xb6, 0x3d, 0x97,

View File

@ -55,6 +55,7 @@ mod tests {
output_str: &'static str, output_str: &'static str,
} }
#[rustfmt::skip]
let tests = vec![ let tests = vec![
// Test vector copied out of rust-bitcoin // Test vector copied out of rust-bitcoin
Test { Test {
@ -99,6 +100,7 @@ mod tests {
use serde_test::{Configure, Token, assert_tokens}; use serde_test::{Configure, Token, assert_tokens};
use crate::{sha256d, Hash}; use crate::{sha256d, Hash};
#[rustfmt::skip]
static HASH_BYTES: [u8; 32] = [ static HASH_BYTES: [u8; 32] = [
0xef, 0x53, 0x7f, 0x25, 0xc8, 0x95, 0xbf, 0xa7, 0xef, 0x53, 0x7f, 0x25, 0xc8, 0x95, 0xbf, 0xa7,
0x82, 0x52, 0x65, 0x29, 0xa9, 0xb6, 0x3d, 0x97, 0x82, 0x52, 0x65, 0x29, 0xa9, 0xb6, 0x3d, 0x97,

View File

@ -40,6 +40,7 @@ pub struct HashEngine {
} }
impl Default for HashEngine { impl Default for HashEngine {
#[rustfmt::skip]
fn default() -> Self { fn default() -> Self {
HashEngine { HashEngine {
h: [ h: [
@ -319,6 +320,7 @@ mod tests {
output_str: &'static str, output_str: &'static str,
} }
#[rustfmt::skip]
let tests = vec![ let tests = vec![
// Test vectors computed with `sha512sum` // Test vectors computed with `sha512sum`
Test { Test {
@ -389,6 +391,7 @@ mod tests {
use serde_test::{Configure, Token, assert_tokens}; use serde_test::{Configure, Token, assert_tokens};
use crate::{sha512, Hash}; use crate::{sha512, Hash};
#[rustfmt::skip]
static HASH_BYTES: [u8; 64] = [ static HASH_BYTES: [u8; 64] = [
0x8b, 0x41, 0xe1, 0xb7, 0x8a, 0xd1, 0x15, 0x21, 0x8b, 0x41, 0xe1, 0xb7, 0x8a, 0xd1, 0x15, 0x21,
0x11, 0x3c, 0x52, 0xff, 0x18, 0x2a, 0x1b, 0x8e, 0x11, 0x3c, 0x52, 0xff, 0x18, 0x2a, 0x1b, 0x8e,

View File

@ -40,6 +40,7 @@ use crate::{sha512, sha512::BLOCK_SIZE, Error};
pub struct HashEngine(sha512::HashEngine); pub struct HashEngine(sha512::HashEngine);
impl Default for HashEngine { impl Default for HashEngine {
#[rustfmt::skip]
fn default() -> Self { fn default() -> Self {
HashEngine(sha512::HashEngine { HashEngine(sha512::HashEngine {
h: [ h: [
@ -97,6 +98,7 @@ mod tests {
output_str: &'static str, output_str: &'static str,
} }
#[rustfmt::skip]
let tests = vec![ let tests = vec![
// Examples from go sha512/256 tests. // Examples from go sha512/256 tests.
Test { Test {

View File

@ -286,6 +286,7 @@ mod tests {
#[test] #[test]
fn test_siphash_2_4() { fn test_siphash_2_4() {
#[rustfmt::skip]
let vecs: [[u8; 8]; 64] = [ let vecs: [[u8; 8]; 64] = [
[0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72], [0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72],
[0xfd, 0x67, 0xdc, 0x93, 0xc5, 0x39, 0xf8, 0x74], [0xfd, 0x67, 0xdc, 0x93, 0xc5, 0x39, 0xf8, 0x74],

View File

@ -1,8 +1,4 @@
# Eventually this shoud be: ignore = [] ignore = []
ignore = [
"hashes",
]
hard_tabs = false hard_tabs = false
tab_spaces = 4 tab_spaces = 4
newline_style = "Auto" newline_style = "Auto"