Skip to content

Commit 18c0c3f

Browse files
author
Andreas Hollmann
committed
Use sha2 to calculate SHA256
1 parent 2dcdf1e commit 18c0c3f

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

crates/cargo-util/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description = "Miscellaneous support code used by Cargo."
99

1010
[dependencies]
1111
anyhow = "1.0.34"
12-
crypto-hash = "0.3.1"
12+
sha2 = "0.10.6"
1313
filetime = "0.2.9"
1414
hex = "0.4.2"
1515
jobserver = "0.1.26"

crates/cargo-util/src/sha256.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
use super::paths;
22
use anyhow::{Context, Result};
3-
use crypto_hash::{Algorithm, Hasher};
3+
use sha2::{Digest, Sha256 as Sha2_sha256};
44
use std::fs::File;
5-
use std::io::{self, Read, Write};
5+
use std::io::{self, Read};
66
use std::path::Path;
77

8-
pub struct Sha256(Hasher);
8+
pub struct Sha256(Sha2_sha256);
99

1010
impl Sha256 {
1111
pub fn new() -> Sha256 {
12-
let hasher = Hasher::new(Algorithm::SHA256);
12+
let hasher = Sha2_sha256::new();
1313
Sha256(hasher)
1414
}
1515

1616
pub fn update(&mut self, bytes: &[u8]) -> &mut Sha256 {
17-
let _ = self.0.write_all(bytes);
17+
let _ = self.0.update(bytes);
1818
self
1919
}
2020

@@ -39,7 +39,7 @@ impl Sha256 {
3939

4040
pub fn finish(&mut self) -> [u8; 32] {
4141
let mut ret = [0u8; 32];
42-
let data = self.0.finish();
42+
let data = self.0.finalize_reset();
4343
ret.copy_from_slice(&data[..]);
4444
ret
4545
}

0 commit comments

Comments
 (0)