Skip to content

Commit 27c74e6

Browse files
committed
Route Gradle digests through utils::digest (port of #878)
main is red on production_digests_go_through_the_helpers since the Gradle squash-merge left inline digests in gradle_cache, jvm_jar and the Maven sidecar. Port #878's change so this PR's CI can go green; it no-ops once #878 lands on main. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c3f12c6 commit 27c74e6

3 files changed

Lines changed: 7 additions & 13 deletions

File tree

‎crates/socket-patch-core/src/crawlers/gradle_cache.rs‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ pub fn hash_eq(dir_name: &str, sha1_hex: &str) -> bool {
7070
/// Whether `bytes` are the pristine download Gradle stored in the hash
7171
/// directory `dir_name` (their sha1 names it).
7272
pub fn pristine(dir_name: &str, bytes: &[u8]) -> bool {
73-
use sha1::{Digest, Sha1};
74-
hash_eq(dir_name, &hex::encode(Sha1::digest(bytes)))
73+
hash_eq(dir_name, &crate::utils::digest::sha1_hex_of(bytes))
7574
}
7675

7776
/// Whether `path` is a version directory of a `files-2.1` tree
@@ -467,8 +466,6 @@ impl DerivedIndex {
467466
/// The [`DerivedCopies`] of the jar `jar_leaf` whose pristine bytes
468467
/// hash to `pristine_sha1`.
469468
pub fn query(&self, jar_leaf: &str, pristine_sha1: &str) -> DerivedCopies {
470-
use sha1::{Digest, Sha1};
471-
472469
let instrumented = format!("instrumented-{jar_leaf}");
473470
let mut out = DerivedCopies {
474471
incomplete: self.incomplete,
@@ -495,7 +492,9 @@ impl DerivedIndex {
495492
out.stale.push(path.clone());
496493
} else if name == jar_leaf || name == instrumented {
497494
match crate::utils::fs::read_regular_to_bytes_sync(path) {
498-
Ok(bytes) if hash_eq(&hex::encode(Sha1::digest(&bytes)), pristine_sha1) => {
495+
Ok(bytes)
496+
if hash_eq(&crate::utils::digest::sha1_hex_of(&bytes), pristine_sha1) =>
497+
{
499498
out.stale.push(path.clone())
500499
}
501500
Ok(_) => out.unknown.push(path.clone()),

‎crates/socket-patch-core/src/patch/jvm_jar.rs‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
use std::collections::HashMap;
2626
use std::path::{Path, PathBuf};
2727

28-
use sha1::Digest as _;
29-
3028
use crate::crawlers::gradle_cache;
3129
use crate::hash::git_sha256::compute_git_sha256_from_bytes;
3230
use crate::manifest::schema::PatchFileInfo;
@@ -353,12 +351,11 @@ fn unpatched_members(
353351
}
354352

355353
fn sha256_hex(bytes: &[u8]) -> String {
356-
use sha2::Digest as _;
357-
hex::encode(sha2::Sha256::digest(bytes))
354+
crate::utils::digest::sha256_hex_of(bytes)
358355
}
359356

360357
fn sha1_hex(bytes: &[u8]) -> String {
361-
hex::encode(sha1::Sha1::digest(bytes))
358+
crate::utils::digest::sha1_hex_of(bytes)
362359
}
363360

364361
/// `<socket_dir>/jvm-originals/<sha256>.jar`.

‎crates/socket-patch-core/src/patch/sidecars/maven.rs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
1818
use std::path::{Path, PathBuf};
1919

20-
use sha1::Digest as _;
21-
2220
use super::{
2321
SidecarAdvisory, SidecarAdvisoryCode, SidecarError, SidecarFile, SidecarFileAction,
2422
SidecarPayload, SidecarSeverity,
@@ -44,7 +42,7 @@ impl Algo {
4442

4543
fn digest(self, bytes: &[u8]) -> String {
4644
match self {
47-
Algo::Sha1 => hex::encode(sha1::Sha1::digest(bytes)),
45+
Algo::Sha1 => crate::utils::digest::sha1_hex_of(bytes),
4846
Algo::Md5 => hex::encode(md5(bytes)),
4947
}
5048
}

0 commit comments

Comments
 (0)