From 5bb327539a601fb454e22467dd386ec032f16234 Mon Sep 17 00:00:00 2001 From: Christoph Herzog Date: Wed, 27 Nov 2024 17:34:49 +0100 Subject: [PATCH 1/2] feat(config): Add (Named)PackageIdent::matches_id helpers --- lib/config/src/package/named_package_ident.rs | 37 +++++++++++++++++++ lib/config/src/package/package_ident.rs | 33 ++++++++++++++++- 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/lib/config/src/package/named_package_ident.rs b/lib/config/src/package/named_package_ident.rs index d1c9fa6e2d2..151ec1faa4a 100644 --- a/lib/config/src/package/named_package_ident.rs +++ b/lib/config/src/package/named_package_ident.rs @@ -172,6 +172,24 @@ impl NamedPackageIdent { out } + + /// Returns true if this ident matches the given package id. + /// + /// Semver constraints are matched against the package id's version. + pub fn matches_id(&self, id: &NamedPackageId) -> bool { + if self.full_name() == id.full_name { + if let Some(tag) = &self.tag { + match tag { + Tag::Named(n) => n == &id.version.to_string(), + Tag::VersionReq(v) => v.matches(&id.version), + } + } else { + true + } + } else { + false + } + } } impl From for NamedPackageIdent { @@ -443,4 +461,23 @@ mod tests { let ident2 = serde_json::from_str::(&raw).unwrap(); assert_eq!(ident, ident2); } + + #[test] + fn test_named_package_ident_matches_id() { + assert!(NamedPackageIdent::from_str("ns/name") + .unwrap() + .matches_id(&NamedPackageId::try_new("ns/name", "0.1.0").unwrap())); + + assert!(NamedPackageIdent::from_str("ns/name") + .unwrap() + .matches_id(&NamedPackageId::try_new("ns/name", "1.0.1").unwrap())); + + assert!(NamedPackageIdent::from_str("ns/name@1") + .unwrap() + .matches_id(&NamedPackageId::try_new("ns/name", "1.0.1").unwrap())); + + assert!(!NamedPackageIdent::from_str("ns/name@2") + .unwrap() + .matches_id(&NamedPackageId::try_new("ns/name", "1.0.1").unwrap())); + } } diff --git a/lib/config/src/package/package_ident.rs b/lib/config/src/package/package_ident.rs index 5b03d6ef812..0e6a5544a78 100644 --- a/lib/config/src/package/package_ident.rs +++ b/lib/config/src/package/package_ident.rs @@ -1,6 +1,6 @@ use std::str::FromStr; -use super::{NamedPackageIdent, PackageHash, PackageParseError}; +use super::{NamedPackageIdent, PackageHash, PackageId, PackageParseError}; #[derive(PartialEq, Eq, Clone, Debug, Hash)] pub enum PackageIdent { @@ -24,6 +24,17 @@ impl PackageIdent { None } } + + /// Returns true if this ident matches the given package id. + /// + /// Semver constraints are matched against the package id's version. + pub fn matches_id(&self, id: &PackageId) -> bool { + match (self, id) { + (Self::Named(a), PackageId::Named(b)) => a.matches_id(b), + (Self::Hash(a), PackageId::Hash(b)) => a == b, + _ => false, + } + } } impl From for PackageIdent { @@ -92,3 +103,23 @@ impl schemars::JsonSchema for PackageIdent { String::json_schema(gen) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_package_ident_matches_id() { + assert!(PackageIdent::from_str("ns/pkg") + .unwrap() + .matches_id(&PackageId::new_named("ns/pkg", "1.0.0".parse().unwrap()))); + + assert!(PackageIdent::from_str("ns/pkg@2") + .unwrap() + .matches_id(&PackageId::new_named("ns/pkg", "2.3.7".parse().unwrap()))); + + assert!(!PackageIdent::from_str("ns/pkg@3") + .unwrap() + .matches_id(&PackageId::new_named("ns/pkg", "2.3.7".parse().unwrap()))); + } +} From 4da27bfe22f087c77e7a243748732377fb6f4951 Mon Sep 17 00:00:00 2001 From: Christoph Herzog Date: Wed, 27 Nov 2024 17:41:47 +0100 Subject: [PATCH 2/2] deps: Update hyper and rustls deps due to advisory ID: RUSTSEC-2024-0399 Advisory: https://rustsec.org/advisories/RUSTSEC-2024-0399 --- Cargo.lock | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b65944096aa..41a1b7289f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2339,9 +2339,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbbff0a806a4728c99295b254c8838933b5b082d75e3cb70c8dab21fdfbcfa9a" +checksum = "97818827ef4f364230e16705d4706e2897df2bb60617d6ca15d598025a3c481f" dependencies = [ "bytes", "futures-channel", @@ -2367,7 +2367,7 @@ dependencies = [ "http", "hyper", "hyper-util", - "rustls 0.23.15", + "rustls 0.23.19", "rustls-pki-types", "tokio", "tokio-rustls 0.26.0", @@ -2768,7 +2768,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" dependencies = [ "cfg-if", - "windows-targets 0.52.6", + "windows-targets 0.48.5", ] [[package]] @@ -3839,7 +3839,7 @@ dependencies = [ "quinn-proto", "quinn-udp", "rustc-hash 2.0.0", - "rustls 0.23.15", + "rustls 0.23.19", "socket2", "thiserror", "tokio", @@ -3856,7 +3856,7 @@ dependencies = [ "rand", "ring", "rustc-hash 2.0.0", - "rustls 0.23.15", + "rustls 0.23.19", "slab", "thiserror", "tinyvec", @@ -4103,7 +4103,7 @@ dependencies = [ "percent-encoding", "pin-project-lite", "quinn", - "rustls 0.23.15", + "rustls 0.23.19", "rustls-pemfile", "rustls-pki-types", "serde", @@ -4275,9 +4275,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.15" +version = "0.23.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fbb44d7acc4e873d613422379f69f237a1b141928c02f6bc6ccfddddc2d7993" +checksum = "934b404430bb06b3fae2cba809eb45a1ab1aecd64491213d7c3301b88393f8d1" dependencies = [ "log", "once_cell", @@ -5211,7 +5211,7 @@ version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" dependencies = [ - "rustls 0.23.15", + "rustls 0.23.19", "rustls-pki-types", "tokio", ] @@ -5282,7 +5282,7 @@ checksum = "edc5f74e248dc973e0dbb7b74c7e0d6fcc301c694ff50049504004ef4d0cdcd9" dependencies = [ "futures-util", "log", - "rustls 0.23.15", + "rustls 0.23.19", "rustls-native-certs", "rustls-pki-types", "tokio", @@ -5567,7 +5567,7 @@ dependencies = [ "httparse", "log", "rand", - "rustls 0.23.15", + "rustls 0.23.19", "rustls-pki-types", "sha1", "thiserror", @@ -5815,7 +5815,7 @@ dependencies = [ "flate2", "log", "once_cell", - "rustls 0.23.15", + "rustls 0.23.19", "rustls-pki-types", "url", "webpki-roots",