Skip to content

Commit 74629b2

Browse files
committed
Port #878: route Gradle digests through utils::digest
main fails socket-patch-core's lib guard test production_digests_go_through_the_helpers because three Gradle files still hash inline, which turns coverage, test and test-release red on this PR. This is the same change as #878 and becomes a no-op once that lands on main. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 236f196 commit 74629b2

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
@@ -432,8 +431,6 @@ impl DerivedIndex {
432431
/// The [`DerivedCopies`] of the jar `jar_leaf` whose pristine bytes
433432
/// hash to `pristine_sha1`.
434433
pub fn query(&self, jar_leaf: &str, pristine_sha1: &str) -> DerivedCopies {
435-
use sha1::{Digest, Sha1};
436-
437434
let instrumented = format!("instrumented-{jar_leaf}");
438435
let mut out = DerivedCopies {
439436
incomplete: self.incomplete,
@@ -460,7 +457,9 @@ impl DerivedIndex {
460457
out.stale.push(path.clone());
461458
} else if name == jar_leaf || name == instrumented {
462459
match crate::utils::fs::read_regular_to_bytes_sync(path) {
463-
Ok(bytes) if hash_eq(&hex::encode(Sha1::digest(&bytes)), pristine_sha1) => {
460+
Ok(bytes)
461+
if hash_eq(&crate::utils::digest::sha1_hex_of(&bytes), pristine_sha1) =>
462+
{
464463
out.stale.push(path.clone())
465464
}
466465
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)