Skip to content

Commit

Permalink
Auto merge of #11795 - ahollmann:master, r=arlosi
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
bors committed Mar 4, 2023
2 parents e5e5d21 + 2f0ecf5 commit 137c2e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
4 changes: 2 additions & 2 deletions crates/cargo-util/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-util"
version = "0.2.3"
version = "0.2.4"
edition = "2021"
license = "MIT OR Apache-2.0"
homepage = "https://github.com/rust-lang/cargo"
Expand All @@ -9,7 +9,7 @@ description = "Miscellaneous support code used by Cargo."

[dependencies]
anyhow = "1.0.34"
crypto-hash = "0.3.1"
sha2 = "0.10.6"
filetime = "0.2.9"
hex = "0.4.2"
jobserver = "0.1.26"
Expand Down
15 changes: 6 additions & 9 deletions crates/cargo-util/src/sha256.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use super::paths;
use anyhow::{Context, Result};
use crypto_hash::{Algorithm, Hasher};
use sha2::{Digest, Sha256 as Sha2_sha256};
use std::fs::File;
use std::io::{self, Read, Write};
use std::io::{self, Read};
use std::path::Path;

pub struct Sha256(Hasher);
pub struct Sha256(Sha2_sha256);

impl Sha256 {
pub fn new() -> Sha256 {
let hasher = Hasher::new(Algorithm::SHA256);
let hasher = Sha2_sha256::new();
Sha256(hasher)
}

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

Expand All @@ -38,10 +38,7 @@ impl Sha256 {
}

pub fn finish(&mut self) -> [u8; 32] {
let mut ret = [0u8; 32];
let data = self.0.finish();
ret.copy_from_slice(&data[..]);
ret
self.0.finalize_reset().into()
}

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

0 comments on commit 137c2e1

Please sign in to comment.