Skip to content

Commit 137c2e1

Browse files
committed
Auto merge of #11795 - ahollmann:master, r=arlosi
Use sha2 to calculate SHA256 crypto-hash seems to be unmaintained (last real commit on Feb 27, 2020) and forces duplicate crates due to outdated dependencies. Minimal change to replace crypto-hash by sha2. This was already attempted in #4545 (back in 2017).
2 parents e5e5d21 + 2f0ecf5 commit 137c2e1

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

crates/cargo-util/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo-util"
3-
version = "0.2.3"
3+
version = "0.2.4"
44
edition = "2021"
55
license = "MIT OR Apache-2.0"
66
homepage = "https://github.com/rust-lang/cargo"
@@ -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 & 9 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

@@ -38,10 +38,7 @@ impl Sha256 {
3838
}
3939

4040
pub fn finish(&mut self) -> [u8; 32] {
41-
let mut ret = [0u8; 32];
42-
let data = self.0.finish();
43-
ret.copy_from_slice(&data[..]);
44-
ret
41+
self.0.finalize_reset().into()
4542
}
4643

4744
pub fn finish_hex(&mut self) -> String {

0 commit comments

Comments
 (0)