Skip to content
This repository was archived by the owner on Apr 10, 2024. It is now read-only.

Commit 76f9b2c

Browse files
committed
Set use_small_heuristics to Max in rustfmt.toml
I set the `use_small_heuristics` rustfmt config option to `Max` since it was formatting code to waste too much vertical space.
1 parent 3fa839d commit 76f9b2c

18 files changed

+54
-182
lines changed

rustfmt.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
edition = "2021"
2+
use_small_heuristics = "Max"

src/keccak.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ fn keccak_f1600(state: &mut Vec<u8>) {
6767
(0..5)
6868
.map(|y| {
6969
u64::from_le_bytes(
70-
state[8 * (x + 5 * y)..8 * (x + 5 * y) + 8]
71-
.try_into()
72-
.unwrap(),
70+
state[8 * (x + 5 * y)..8 * (x + 5 * y) + 8].try_into().unwrap(),
7371
)
7472
})
7573
.collect::<Vec<u64>>()
@@ -95,9 +93,8 @@ fn keccak_f1600_permutate(lanes: &mut Vec<Vec<u64>>) {
9593
let c = (0..5)
9694
.map(|x| lanes[x][0] ^ lanes[x][1] ^ lanes[x][2] ^ lanes[x][3] ^ lanes[x][4])
9795
.collect::<Vec<u64>>();
98-
let d = (0..5)
99-
.map(|x| c[(x + 4) % 5] ^ c[(x + 1) % 5].rotate_left(1))
100-
.collect::<Vec<u64>>();
96+
let d =
97+
(0..5).map(|x| c[(x + 4) % 5] ^ c[(x + 1) % 5].rotate_left(1)).collect::<Vec<u64>>();
10198

10299
for x in 0..5 {
103100
for y in 0..5 {

src/lib.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ pub trait FixedLengthHasher<const DIGEST_BYTE_LENGTH: usize> {
4242
fn digest(&self) -> [u8; DIGEST_BYTE_LENGTH];
4343

4444
fn hexdigest(&self) -> String {
45-
self.digest()
46-
.iter()
47-
.map(|byte| format!("{:0>2x}", byte))
48-
.collect::<String>()
45+
self.digest().iter().map(|byte| format!("{:0>2x}", byte)).collect::<String>()
4946
}
5047
}
5148

@@ -57,10 +54,7 @@ pub trait VariableLengthHasher {
5754
fn digest(&self, length_in_bytes: usize) -> Vec<u8>;
5855

5956
fn hexdigest(&self, length_in_bytes: usize) -> String {
60-
self.digest(length_in_bytes)
61-
.iter()
62-
.map(|byte| format!("{:0>2x}", byte))
63-
.collect::<String>()
57+
self.digest(length_in_bytes).iter().map(|byte| format!("{:0>2x}", byte)).collect::<String>()
6458
}
6559

6660
fn digest_const<const DIGEST_BYTE_LENGTH: usize>(&self) -> [u8; DIGEST_BYTE_LENGTH];

src/md5.rs

+4-15
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ pub struct MD5 {
1919

2020
impl FixedLengthHasher<16> for MD5 {
2121
fn new() -> MD5 {
22-
MD5 {
23-
data: Vec::<u8>::new(),
24-
}
22+
MD5 { data: Vec::<u8>::new() }
2523
}
2624

2725
fn update(&mut self, data: &[u8]) {
@@ -111,23 +109,14 @@ mod tests {
111109
fn md5_test() {
112110
let mut hasher = MD5::new();
113111

114-
assert_eq!(
115-
"d41d8cd98f00b204e9800998ecf8427e".to_string(),
116-
hasher.hexdigest(),
117-
);
112+
assert_eq!("d41d8cd98f00b204e9800998ecf8427e".to_string(), hasher.hexdigest(),);
118113

119114
hasher.update(b"The quick brown fox jumps over the lazy dog");
120115

121-
assert_eq!(
122-
"9e107d9d372bb6826bd81d3542a419d6".to_string(),
123-
hasher.hexdigest(),
124-
);
116+
assert_eq!("9e107d9d372bb6826bd81d3542a419d6".to_string(), hasher.hexdigest(),);
125117

126118
hasher.update(b".");
127119

128-
assert_eq!(
129-
"e4d909c290d0fb1ca068ffaddf22cbd0".to_string(),
130-
hasher.hexdigest(),
131-
);
120+
assert_eq!("e4d909c290d0fb1ca068ffaddf22cbd0".to_string(), hasher.hexdigest(),);
132121
}
133122
}

src/sha1.rs

+4-15
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ pub struct SHA1 {
88

99
impl FixedLengthHasher<20> for SHA1 {
1010
fn new() -> SHA1 {
11-
SHA1 {
12-
data: Vec::<u8>::new(),
13-
}
11+
SHA1 { data: Vec::<u8>::new() }
1412
}
1513

1614
fn update(&mut self, data: &[u8]) {
@@ -102,23 +100,14 @@ mod tests {
102100
fn sha1_test() {
103101
let mut hasher = SHA1::new();
104102

105-
assert_eq!(
106-
"da39a3ee5e6b4b0d3255bfef95601890afd80709".to_string(),
107-
hasher.hexdigest(),
108-
);
103+
assert_eq!("da39a3ee5e6b4b0d3255bfef95601890afd80709".to_string(), hasher.hexdigest(),);
109104

110105
hasher.update(b"The quick brown fox jumps over the lazy dog");
111106

112-
assert_eq!(
113-
"2fd4e1c67a2d28fced849ee1bb76e7391b93eb12".to_string(),
114-
hasher.hexdigest(),
115-
);
107+
assert_eq!("2fd4e1c67a2d28fced849ee1bb76e7391b93eb12".to_string(), hasher.hexdigest(),);
116108

117109
hasher.update(b".");
118110

119-
assert_eq!(
120-
"408d94384216f890ff7a0c3528e8bed1e0b01621".to_string(),
121-
hasher.hexdigest(),
122-
);
111+
assert_eq!("408d94384216f890ff7a0c3528e8bed1e0b01621".to_string(), hasher.hexdigest(),);
123112
}
124113
}

src/sha224.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ pub struct SHA224 {
1919

2020
impl FixedLengthHasher<28> for SHA224 {
2121
fn new() -> SHA224 {
22-
SHA224 {
23-
data: Vec::<u8>::new(),
24-
}
22+
SHA224 { data: Vec::<u8>::new() }
2523
}
2624

2725
fn update(&mut self, data: &[u8]) {
@@ -60,12 +58,7 @@ impl FixedLengthHasher<28> for SHA224 {
6058
for i in 16..64 {
6159
let s0 = w[i - 15].rotate_right(7) ^ w[i - 15].rotate_right(18) ^ w[i - 15] >> 3;
6260
let s1 = w[i - 2].rotate_right(17) ^ w[i - 2].rotate_right(19) ^ w[i - 2] >> 10;
63-
w.push(
64-
w[i - 16]
65-
.wrapping_add(s0)
66-
.wrapping_add(w[i - 7])
67-
.wrapping_add(s1),
68-
);
61+
w.push(w[i - 16].wrapping_add(s0).wrapping_add(w[i - 7]).wrapping_add(s1));
6962
}
7063

7164
let (mut a, mut b, mut c, mut d, mut e, mut f, mut g, mut h) =
@@ -74,11 +67,8 @@ impl FixedLengthHasher<28> for SHA224 {
7467
for i in 0..64 {
7568
let S1 = e.rotate_right(6) ^ e.rotate_right(11) ^ e.rotate_right(25);
7669
let ch = (e & f) ^ (!e & g);
77-
let temp1 = h
78-
.wrapping_add(S1)
79-
.wrapping_add(ch)
80-
.wrapping_add(K[i])
81-
.wrapping_add(w[i]);
70+
let temp1 =
71+
h.wrapping_add(S1).wrapping_add(ch).wrapping_add(K[i]).wrapping_add(w[i]);
8272
let S0 = a.rotate_right(2) ^ a.rotate_right(13) ^ a.rotate_right(22);
8373
let maj = (a & b) ^ (a & c) ^ (b & c);
8474
let temp2 = S0.wrapping_add(maj);

src/sha256.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ pub struct SHA256 {
1919

2020
impl FixedLengthHasher<32> for SHA256 {
2121
fn new() -> SHA256 {
22-
SHA256 {
23-
data: Vec::<u8>::new(),
24-
}
22+
SHA256 { data: Vec::<u8>::new() }
2523
}
2624

2725
fn update(&mut self, data: &[u8]) {
@@ -60,12 +58,7 @@ impl FixedLengthHasher<32> for SHA256 {
6058
for i in 16..64 {
6159
let s0 = w[i - 15].rotate_right(7) ^ w[i - 15].rotate_right(18) ^ w[i - 15] >> 3;
6260
let s1 = w[i - 2].rotate_right(17) ^ w[i - 2].rotate_right(19) ^ w[i - 2] >> 10;
63-
w.push(
64-
w[i - 16]
65-
.wrapping_add(s0)
66-
.wrapping_add(w[i - 7])
67-
.wrapping_add(s1),
68-
);
61+
w.push(w[i - 16].wrapping_add(s0).wrapping_add(w[i - 7]).wrapping_add(s1));
6962
}
7063

7164
let (mut a, mut b, mut c, mut d, mut e, mut f, mut g, mut h) =
@@ -74,11 +67,8 @@ impl FixedLengthHasher<32> for SHA256 {
7467
for i in 0..64 {
7568
let S1 = e.rotate_right(6) ^ e.rotate_right(11) ^ e.rotate_right(25);
7669
let ch = (e & f) ^ (!e & g);
77-
let temp1 = h
78-
.wrapping_add(S1)
79-
.wrapping_add(ch)
80-
.wrapping_add(K[i])
81-
.wrapping_add(w[i]);
70+
let temp1 =
71+
h.wrapping_add(S1).wrapping_add(ch).wrapping_add(K[i]).wrapping_add(w[i]);
8272
let S0 = a.rotate_right(2) ^ a.rotate_right(13) ^ a.rotate_right(22);
8373
let maj = (a & b) ^ (a & c) ^ (b & c);
8474
let temp2 = S0.wrapping_add(maj);

src/sha384.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ pub struct SHA384 {
9191

9292
impl FixedLengthHasher<48> for SHA384 {
9393
fn new() -> SHA384 {
94-
SHA384 {
95-
data: Vec::<u8>::new(),
96-
}
94+
SHA384 { data: Vec::<u8>::new() }
9795
}
9896

9997
fn update(&mut self, data: &[u8]) {
@@ -132,12 +130,7 @@ impl FixedLengthHasher<48> for SHA384 {
132130
for i in 16..80 {
133131
let s0 = w[i - 15].rotate_right(1) ^ w[i - 15].rotate_right(8) ^ w[i - 15] >> 7;
134132
let s1 = w[i - 2].rotate_right(19) ^ w[i - 2].rotate_right(61) ^ w[i - 2] >> 6;
135-
w.push(
136-
w[i - 16]
137-
.wrapping_add(s0)
138-
.wrapping_add(w[i - 7])
139-
.wrapping_add(s1),
140-
);
133+
w.push(w[i - 16].wrapping_add(s0).wrapping_add(w[i - 7]).wrapping_add(s1));
141134
}
142135

143136
let (mut a, mut b, mut c, mut d, mut e, mut f, mut g, mut h) =
@@ -146,11 +139,8 @@ impl FixedLengthHasher<48> for SHA384 {
146139
for i in 0..80 {
147140
let S1 = e.rotate_right(14) ^ e.rotate_right(18) ^ e.rotate_right(41);
148141
let ch = (e & f) ^ (!e & g);
149-
let temp1 = h
150-
.wrapping_add(S1)
151-
.wrapping_add(ch)
152-
.wrapping_add(K[i])
153-
.wrapping_add(w[i]);
142+
let temp1 =
143+
h.wrapping_add(S1).wrapping_add(ch).wrapping_add(K[i]).wrapping_add(w[i]);
154144
let S0 = a.rotate_right(28) ^ a.rotate_right(34) ^ a.rotate_right(39);
155145
let maj = (a & b) ^ (a & c) ^ (b & c);
156146
let temp2 = S0.wrapping_add(maj);

src/sha3_224.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,15 @@ pub struct SHA3_224 {
88

99
impl FixedLengthHasher<28> for SHA3_224 {
1010
fn new() -> SHA3_224 {
11-
SHA3_224 {
12-
data: Vec::<u8>::new(),
13-
}
11+
SHA3_224 { data: Vec::<u8>::new() }
1412
}
1513

1614
fn update(&mut self, data: &[u8]) {
1715
self.data.extend(data);
1816
}
1917

2018
fn digest(&self) -> [u8; 28] {
21-
keccak(1152, 448, &self.data, 0x06, 28)
22-
.unwrap()
23-
.try_into()
24-
.unwrap()
19+
keccak(1152, 448, &self.data, 0x06, 28).unwrap().try_into().unwrap()
2520
}
2621
}
2722

src/sha3_256.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,15 @@ pub struct SHA3_256 {
88

99
impl FixedLengthHasher<32> for SHA3_256 {
1010
fn new() -> SHA3_256 {
11-
SHA3_256 {
12-
data: Vec::<u8>::new(),
13-
}
11+
SHA3_256 { data: Vec::<u8>::new() }
1412
}
1513

1614
fn update(&mut self, data: &[u8]) {
1715
self.data.extend(data);
1816
}
1917

2018
fn digest(&self) -> [u8; 32] {
21-
keccak(1088, 512, &self.data, 0x06, 32)
22-
.unwrap()
23-
.try_into()
24-
.unwrap()
19+
keccak(1088, 512, &self.data, 0x06, 32).unwrap().try_into().unwrap()
2520
}
2621
}
2722

src/sha3_384.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,15 @@ pub struct SHA3_384 {
88

99
impl FixedLengthHasher<48> for SHA3_384 {
1010
fn new() -> SHA3_384 {
11-
SHA3_384 {
12-
data: Vec::<u8>::new(),
13-
}
11+
SHA3_384 { data: Vec::<u8>::new() }
1412
}
1513

1614
fn update(&mut self, data: &[u8]) {
1715
self.data.extend(data);
1816
}
1917

2018
fn digest(&self) -> [u8; 48] {
21-
keccak(832, 768, &self.data, 0x06, 48)
22-
.unwrap()
23-
.try_into()
24-
.unwrap()
19+
keccak(832, 768, &self.data, 0x06, 48).unwrap().try_into().unwrap()
2520
}
2621
}
2722

src/sha3_512.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,15 @@ pub struct SHA3_512 {
88

99
impl FixedLengthHasher<64> for SHA3_512 {
1010
fn new() -> SHA3_512 {
11-
SHA3_512 {
12-
data: Vec::<u8>::new(),
13-
}
11+
SHA3_512 { data: Vec::<u8>::new() }
1412
}
1513

1614
fn update(&mut self, data: &[u8]) {
1715
self.data.extend(data);
1816
}
1917

2018
fn digest(&self) -> [u8; 64] {
21-
keccak(576, 1024, &self.data, 0x06, 64)
22-
.unwrap()
23-
.try_into()
24-
.unwrap()
19+
keccak(576, 1024, &self.data, 0x06, 64).unwrap().try_into().unwrap()
2520
}
2621
}
2722

src/sha512.rs

+6-15
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ pub struct SHA512 {
9191

9292
impl FixedLengthHasher<64> for SHA512 {
9393
fn new() -> SHA512 {
94-
SHA512 {
95-
data: Vec::<u8>::new(),
96-
}
94+
SHA512 { data: Vec::<u8>::new() }
9795
}
9896

9997
fn update(&mut self, data: &[u8]) {
@@ -132,12 +130,7 @@ impl FixedLengthHasher<64> for SHA512 {
132130
for i in 16..80 {
133131
let s0 = w[i - 15].rotate_right(1) ^ w[i - 15].rotate_right(8) ^ w[i - 15] >> 7;
134132
let s1 = w[i - 2].rotate_right(19) ^ w[i - 2].rotate_right(61) ^ w[i - 2] >> 6;
135-
w.push(
136-
w[i - 16]
137-
.wrapping_add(s0)
138-
.wrapping_add(w[i - 7])
139-
.wrapping_add(s1),
140-
);
133+
w.push(w[i - 16].wrapping_add(s0).wrapping_add(w[i - 7]).wrapping_add(s1));
141134
}
142135

143136
let (mut a, mut b, mut c, mut d, mut e, mut f, mut g, mut h) =
@@ -146,11 +139,8 @@ impl FixedLengthHasher<64> for SHA512 {
146139
for i in 0..80 {
147140
let S1 = e.rotate_right(14) ^ e.rotate_right(18) ^ e.rotate_right(41);
148141
let ch = (e & f) ^ (!e & g);
149-
let temp1 = h
150-
.wrapping_add(S1)
151-
.wrapping_add(ch)
152-
.wrapping_add(K[i])
153-
.wrapping_add(w[i]);
142+
let temp1 =
143+
h.wrapping_add(S1).wrapping_add(ch).wrapping_add(K[i]).wrapping_add(w[i]);
154144
let S0 = a.rotate_right(28) ^ a.rotate_right(34) ^ a.rotate_right(39);
155145
let maj = (a & b) ^ (a & c) ^ (b & c);
156146
let temp2 = S0.wrapping_add(maj);
@@ -209,7 +199,8 @@ mod tests {
209199
hasher.update(b".");
210200

211201
assert_eq!(
212-
"91ea1245f20d46ae9a037a989f54f1f790f0a47607eeb8a14d12890cea77a1bbc6c7ed9cf205e67b7f2b8fd4c7dfd3a7a8617e45f3c463d481c7e586c39ac1ed".to_string(),
202+
"91ea1245f20d46ae9a037a989f54f1f790f0a47607eeb8a14d12890cea77a1bbc6c7ed9cf205e67b7f2b8f\
203+
d4c7dfd3a7a8617e45f3c463d481c7e586c39ac1ed".to_string(),
213204
hasher.hexdigest(),
214205
);
215206
}

0 commit comments

Comments
 (0)