Skip to content

Commit cf6d7b0

Browse files
committed
remove support for md5 and sha1, add support for xxhash
1 parent 310cd79 commit cf6d7b0

File tree

4 files changed

+20
-39
lines changed

4 files changed

+20
-39
lines changed

Cargo.lock

+7-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ url = "2.5.0"
108108
varisat = "0.2.2"
109109
walkdir = "2.5.0"
110110
windows-sys = "0.52"
111+
xxhash-rust = { version = "0.8.10", features = ["xxh3"] }
111112

112113
[workspace.lints.rust]
113114
rust_2018_idioms = "warn" # TODO: could this be removed?
@@ -203,8 +204,8 @@ unicase.workspace = true
203204
unicode-width.workspace = true
204205
url.workspace = true
205206
walkdir.workspace = true
207+
xxhash-rust.workspace = true
206208
supports-unicode = "3.0.0"
207-
md-5 = "0.10.6"
208209

209210
[target.'cfg(target_has_atomic = "64")'.dependencies]
210211
tracing-chrome.workspace = true

src/cargo/core/compiler/fingerprint/mod.rs

+10-26
Original file line numberDiff line numberDiff line change
@@ -377,12 +377,11 @@ use anyhow::{bail, format_err, Context as _};
377377
use cargo_util::{paths, ProcessBuilder, Sha256};
378378
use filetime::FileTime;
379379
use itertools::Either;
380-
use md5::Md5;
381380
use serde::de;
382381
use serde::ser;
383382
use serde::{Deserialize, Serialize};
384-
use sha1::{Digest, Sha1};
385383
use tracing::{debug, info};
384+
use xxhash_rust::xxh3;
386385

387386
use crate::core::compiler::unit_graph::UnitDep;
388387
use crate::core::Package;
@@ -2517,16 +2516,14 @@ pub fn parse_rustc_dep_info(rustc_dep_info: &Path) -> CargoResult<RustcDepInfo>
25172516
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
25182517
pub enum ChecksumAlgo {
25192518
Sha256,
2520-
Sha1,
2521-
Md5,
2519+
XxHash,
25222520
}
25232521

25242522
impl ChecksumAlgo {
25252523
fn hash_len(&self) -> usize {
25262524
match self {
25272525
ChecksumAlgo::Sha256 => 32,
2528-
ChecksumAlgo::Sha1 => 20,
2529-
ChecksumAlgo::Md5 => 16,
2526+
ChecksumAlgo::XxHash => 16,
25302527
}
25312528
}
25322529
}
@@ -2537,8 +2534,7 @@ impl FromStr for ChecksumAlgo {
25372534
fn from_str(s: &str) -> Result<Self, Self::Err> {
25382535
match s {
25392536
"sha256" => Ok(Self::Sha256),
2540-
"sha1" => Ok(Self::Sha1),
2541-
"md5" => Ok(Self::Md5),
2537+
"xxhash" => Ok(Self::XxHash),
25422538
_ => Err(InvalidChecksumAlgo {}),
25432539
}
25442540
}
@@ -2548,8 +2544,7 @@ impl Display for ChecksumAlgo {
25482544
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25492545
f.write_str(match self {
25502546
ChecksumAlgo::Sha256 => "sha256",
2551-
ChecksumAlgo::Sha1 => "sha1",
2552-
ChecksumAlgo::Md5 => "md5",
2547+
ChecksumAlgo::XxHash => "xxhash",
25532548
})
25542549
}
25552550
}
@@ -2559,7 +2554,7 @@ pub struct InvalidChecksumAlgo {}
25592554

25602555
impl Display for InvalidChecksumAlgo {
25612556
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result {
2562-
write!(f, "expected `sha256`, `sha1`, or `md5`")
2557+
write!(f, "expected `sha256`, or `xxhash`")
25632558
}
25642559
}
25652560

@@ -2622,30 +2617,19 @@ impl Checksum {
26222617
value,
26232618
)?;
26242619
}
2625-
ChecksumAlgo::Sha1 => {
2620+
ChecksumAlgo::XxHash => {
26262621
digest(
2627-
Sha1::new(),
2622+
xxh3::Xxh3::new(),
26282623
|h, b| {
26292624
h.update(b);
26302625
},
2631-
|h, out| out.copy_from_slice(&h.finalize()),
2632-
contents,
2633-
&mut buf,
2634-
value,
2635-
)?;
2636-
}
2637-
ChecksumAlgo::Md5 => {
2638-
digest(
2639-
Md5::new(),
2640-
|h, b| {
2641-
h.update(b);
2642-
},
2643-
|h, out| out.copy_from_slice(&h.finalize()),
2626+
|h, out| out.copy_from_slice(&h.digest128().to_be_bytes()),
26442627
contents,
26452628
&mut buf,
26462629
value,
26472630
)?;
26482631
}
2632+
26492633
}
26502634
Ok(ret)
26512635
}

src/cargo/core/compiler/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ fn prepare_rustc(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResult
688688
base.arg("-Z").arg("binary-dep-depinfo");
689689
}
690690
if build_runner.bcx.gctx.cli_unstable().checksum_freshness {
691-
base.arg("-Z").arg("checksum-hash-algorithm=sha256");
691+
base.arg("-Z").arg("checksum-hash-algorithm=xxhash");
692692
}
693693

694694
if is_primary {

0 commit comments

Comments
 (0)