Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 794751d

Browse filesBrowse files
Merge pull request theseus-rs#94 from theseus-rs/add-sha1-hash-support
feat: add SHA1 hash support for older Maven repositories
2 parents 7770b65 + b14091e commit 794751d
Copy full SHA for 794751d

File tree

Expand file treeCollapse file tree

7 files changed

+42
-2
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+42
-2
lines changed

‎Cargo.lock

Copy file name to clipboardExpand all lines: Cargo.lock
+1Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

Copy file name to clipboardExpand all lines: Cargo.toml
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ reqwest-tracing = "0.5.0"
4343
semver = "1.0.23"
4444
serde = "1.0.203"
4545
serde_json = "1.0.118"
46+
sha1 = "0.10.6"
4647
sha2 = "0.10.8"
4748
sha3 = "0.10.8"
4849
tar = "0.4.41"

‎postgresql_archive/Cargo.toml

Copy file name to clipboardExpand all lines: postgresql_archive/Cargo.toml
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ reqwest-tracing = { workspace = true }
2828
semver = { workspace = true }
2929
serde = { workspace = true, features = ["derive"] }
3030
serde_json = { workspace = true }
31+
sha1 = { workspace = true }
3132
sha2 = { workspace = true }
3233
sha3 = { workspace = true }
3334
tar = { workspace = true }

‎postgresql_archive/src/hasher/mod.rs

Copy file name to clipboardExpand all lines: postgresql_archive/src/hasher/mod.rs
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub mod blake2b_512;
22
pub mod blake2s_256;
33
pub mod registry;
4+
pub mod sha1;
45
pub mod sha2_256;
56
pub mod sha2_512;
67
pub mod sha3_256;

‎postgresql_archive/src/hasher/registry.rs

Copy file name to clipboardExpand all lines: postgresql_archive/src/hasher/registry.rs
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::configuration::theseus;
2-
use crate::hasher::{sha2_256, sha2_512};
2+
use crate::hasher::{sha1, sha2_256, sha2_512};
33
use crate::Error::{PoisonedLock, UnsupportedHasher};
44
use crate::Result;
55
use lazy_static::lazy_static;
@@ -70,6 +70,15 @@ impl Default for HasherRegistry {
7070
|url, extension| Ok(url.starts_with(theseus::URL) && extension == "sha256"),
7171
sha2_256::hash,
7272
);
73+
// The zonky maven central releases prior to version 13.2.0 only provide MD5/SHA-1 hashes.
74+
registry.register(
75+
|url, extension| {
76+
Ok(url.contains("zonky")
77+
&& url.contains("embedded-postgres-binaries")
78+
&& extension == "sha1")
79+
},
80+
sha1::hash,
81+
);
7382
registry.register(
7483
|url, extension| {
7584
Ok(url.contains("zonky")

‎postgresql_archive/src/hasher/sha1.rs

Copy file name to clipboard
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use crate::Result;
2+
use sha1::{Digest, Sha1};
3+
4+
/// Hashes the data using SHA1.
5+
///
6+
/// # Errors
7+
/// * If the data cannot be hashed.
8+
pub fn hash(data: &Vec<u8>) -> Result<String> {
9+
let mut hasher = Sha1::new();
10+
hasher.update(data);
11+
let hash = hex::encode(hasher.finalize());
12+
Ok(hash)
13+
}
14+
15+
#[cfg(test)]
16+
mod tests {
17+
use super::*;
18+
19+
#[test]
20+
fn test_hash() -> Result<()> {
21+
let data = vec![4, 2];
22+
let hash = hash(&data)?;
23+
assert_eq!("1f3e1678e699640dfa5173d3a52b004f5e164d87", hash);
24+
Ok(())
25+
}
26+
}

‎postgresql_archive/src/repository/maven/repository.rs

Copy file name to clipboardExpand all lines: postgresql_archive/src/repository/maven/repository.rs
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ impl Repository for Maven {
106106
let archive_url = format!("{url}/{version}/{artifact}-{version}.jar", url = self.url,);
107107

108108
let mut hasher_result = None;
109-
for extension in &["md5", "sha1", "sha256", "sha512"] {
109+
// Try to find a hasher for the archive; the extensions are ordered by preference.
110+
for extension in &["sha512", "sha256", "sha1", "md5"] {
110111
if let Ok(hasher_fn) = hasher::registry::get(&self.url, &(*extension).to_string()) {
111112
hasher_result = Some((extension, hasher_fn));
112113
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.