Skip to content

Commit a45d663

Browse files
committed
remove support for md5 and sha1, add support for xxhash
1 parent 075f79f commit a45d663

File tree

4 files changed

+19
-39
lines changed

4 files changed

+19
-39
lines changed

Cargo.lock

Lines changed: 7 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ url = "2.5.2"
110110
varisat = "0.2.2"
111111
walkdir = "2.5.0"
112112
windows-sys = "0.59"
113+
xxhash-rust = { version = "0.8.10", features = ["xxh3"] }
113114

114115
[workspace.lints.rust]
115116
rust_2018_idioms = "warn" # TODO: could this be removed?
@@ -206,8 +207,8 @@ unicase.workspace = true
206207
unicode-width.workspace = true
207208
url.workspace = true
208209
walkdir.workspace = true
210+
xxhash-rust.workspace = true
209211
supports-unicode = "3.0.0"
210-
md-5 = "0.10.6"
211212

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

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

Lines changed: 9 additions & 26 deletions
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;
@@ -2495,16 +2494,14 @@ pub fn parse_rustc_dep_info(rustc_dep_info: &Path) -> CargoResult<RustcDepInfo>
24952494
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
24962495
pub enum ChecksumAlgo {
24972496
Sha256,
2498-
Sha1,
2499-
Md5,
2497+
XxHash,
25002498
}
25012499

25022500
impl ChecksumAlgo {
25032501
fn hash_len(&self) -> usize {
25042502
match self {
25052503
ChecksumAlgo::Sha256 => 32,
2506-
ChecksumAlgo::Sha1 => 20,
2507-
ChecksumAlgo::Md5 => 16,
2504+
ChecksumAlgo::XxHash => 16,
25082505
}
25092506
}
25102507
}
@@ -2515,8 +2512,7 @@ impl FromStr for ChecksumAlgo {
25152512
fn from_str(s: &str) -> Result<Self, Self::Err> {
25162513
match s {
25172514
"sha256" => Ok(Self::Sha256),
2518-
"sha1" => Ok(Self::Sha1),
2519-
"md5" => Ok(Self::Md5),
2515+
"xxhash" => Ok(Self::XxHash),
25202516
_ => Err(InvalidChecksumAlgo {}),
25212517
}
25222518
}
@@ -2526,8 +2522,7 @@ impl Display for ChecksumAlgo {
25262522
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25272523
f.write_str(match self {
25282524
ChecksumAlgo::Sha256 => "sha256",
2529-
ChecksumAlgo::Sha1 => "sha1",
2530-
ChecksumAlgo::Md5 => "md5",
2525+
ChecksumAlgo::XxHash => "xxhash",
25312526
})
25322527
}
25332528
}
@@ -2537,7 +2532,7 @@ pub struct InvalidChecksumAlgo {}
25372532

25382533
impl Display for InvalidChecksumAlgo {
25392534
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result {
2540-
write!(f, "expected `sha256`, `sha1`, or `md5`")
2535+
write!(f, "expected `sha256`, or `xxhash`")
25412536
}
25422537
}
25432538

@@ -2600,25 +2595,13 @@ impl Checksum {
26002595
value,
26012596
)?;
26022597
}
2603-
ChecksumAlgo::Sha1 => {
2598+
ChecksumAlgo::XxHash => {
26042599
digest(
2605-
Sha1::new(),
2600+
xxh3::Xxh3::new(),
26062601
|h, b| {
26072602
h.update(b);
26082603
},
2609-
|h, out| out.copy_from_slice(&h.finalize()),
2610-
contents,
2611-
&mut buf,
2612-
value,
2613-
)?;
2614-
}
2615-
ChecksumAlgo::Md5 => {
2616-
digest(
2617-
Md5::new(),
2618-
|h, b| {
2619-
h.update(b);
2620-
},
2621-
|h, out| out.copy_from_slice(&h.finalize()),
2604+
|h, out| out.copy_from_slice(&h.digest128().to_be_bytes()),
26222605
contents,
26232606
&mut buf,
26242607
value,

src/cargo/core/compiler/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ fn prepare_rustc(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResult
705705
base.arg("-Z").arg("binary-dep-depinfo");
706706
}
707707
if build_runner.bcx.gctx.cli_unstable().checksum_freshness {
708-
base.arg("-Z").arg("checksum-hash-algorithm=sha256");
708+
base.arg("-Z").arg("checksum-hash-algorithm=xxhash");
709709
}
710710

711711
if is_primary {

0 commit comments

Comments
 (0)