Skip to content

Commit 06af669

Browse files
committed
Switch from sha256 to sha2.
Brings in fewer dependencies.
1 parent d41d41d commit 06af669

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ log = {version = "0.4", default-features = false, optional = true}
2121
env_logger = "0.9"
2222
hex-literal = "0.3"
2323
flate2 = "1.0"
24-
sha256 = "1.4"
24+
sha2 = "0.10"
2525
chrono = "0.4"
2626

2727
[features]

tests/read_file.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
//! Reading related tests
22
3+
use sha2::Digest;
4+
35
mod utils;
46

5-
static TEST_DAT_SHA256_SUM: &str =
6-
"59e3468e3bef8bfe37e60a8221a1896e105b80a61a23637612ac8cd24ca04a75";
7+
static TEST_DAT_SHA256_SUM: &[u8] =
8+
b"\x59\xe3\x46\x8e\x3b\xef\x8b\xfe\x37\xe6\x0a\x82\x21\xa1\x89\x6e\x10\x5b\x80\xa6\x1a\x23\x63\x76\x12\xac\x8c\xd2\x4c\xa0\x4a\x75";
79

810
#[test]
911
fn read_file_512_blocks() {
@@ -41,8 +43,10 @@ fn read_file_512_blocks() {
4143
contents.extend(&buffer[0..len]);
4244
}
4345

44-
let hash = sha256::digest(contents);
45-
assert_eq!(&hash, TEST_DAT_SHA256_SUM);
46+
let mut hasher = sha2::Sha256::new();
47+
hasher.update(contents);
48+
let hash = hasher.finalize();
49+
assert_eq!(&hash[..], TEST_DAT_SHA256_SUM);
4650
}
4751

4852
#[test]
@@ -73,8 +77,10 @@ fn read_file_all() {
7377
panic!("Failed to read all of TEST.DAT");
7478
}
7579

76-
let hash = sha256::digest(&contents[0..3500]);
77-
assert_eq!(&hash, TEST_DAT_SHA256_SUM);
80+
let mut hasher = sha2::Sha256::new();
81+
hasher.update(&contents[0..3500]);
82+
let hash = hasher.finalize();
83+
assert_eq!(&hash[..], TEST_DAT_SHA256_SUM);
7884
}
7985

8086
#[test]
@@ -114,8 +120,10 @@ fn read_file_prime_blocks() {
114120
contents.extend(&buffer[0..len]);
115121
}
116122

117-
let hash = sha256::digest(contents);
118-
assert_eq!(&hash, TEST_DAT_SHA256_SUM);
123+
let mut hasher = sha2::Sha256::new();
124+
hasher.update(&contents[0..3500]);
125+
let hash = hasher.finalize();
126+
assert_eq!(&hash[..], TEST_DAT_SHA256_SUM);
119127
}
120128

121129
#[test]
@@ -166,8 +174,10 @@ fn read_file_backwards() {
166174

167175
let flat: Vec<u8> = contents.iter().flatten().copied().collect();
168176

169-
let hash = sha256::digest(flat);
170-
assert_eq!(&hash, TEST_DAT_SHA256_SUM);
177+
let mut hasher = sha2::Sha256::new();
178+
hasher.update(flat);
179+
let hash = hasher.finalize();
180+
assert_eq!(&hash[..], TEST_DAT_SHA256_SUM);
171181
}
172182

173183
// ****************************************************************************

0 commit comments

Comments
 (0)