#[non_exhaustive]pub struct ScanTarget {
pub key: VulnKey,
pub osv_name: OsvQueryName,
pub version: OsvVersion,
pub display_version: ConcreteVersion,
/* private fields */
}Expand description
One dependency to query against OSV.
Four distinct strings, deliberately: key is this project’s internal
lookup key (EcosystemFormatter::normalize_package_name), osv_name is
OSV’s canonical spelling (EcosystemFormatter::osv_package_name). The
transform from key to osv_name is not round-trippable (Swift
owner/repo -> github.com/owner/repo; NuGet raw vs Composer lowercased),
so the client cannot reconstruct the map key from what it sends on the
wire — both must be carried alongside each other.
version and display_version are the same split, one level down: version
is what gets sent on the wire (EcosystemFormatter::osv_version), while
display_version is the ecosystem-native spelling a caller should surface
back to the user (e.g. in crate::osv::UpgradeStatus). They coincide for
every ecosystem except Go, where osv_version strips the mandatory v
prefix — a caller that echoed version in an upgrade suggestion would show
1.2.3 instead of the go.mod-native v1.2.3.
§Examples
use deps_core::ConcreteVersion;
use deps_core::osv::{OsvPackageName, OsvQueryName, OsvVersion, ScanTarget};
use deps_core::test_util::vuln_key;
let target = ScanTarget::new(
vuln_key("time"),
OsvQueryName::Confirmed(OsvPackageName::new("time").unwrap()),
OsvVersion::new("0.1.43"),
ConcreteVersion::new("0.1.43"),
);
assert!(*target.osv_name.name() == target.key.as_str());Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.key: VulnKeyThis project’s internal lookup key — used to key VulnerabilityMap.
osv_name: OsvQueryNameThe package name to send on the wire, with the trust its negative answer deserves.
version: OsvVersionConcrete version to query, resolved per the version-selection policy
and rewritten to OSV’s wire spelling via
EcosystemFormatter::osv_version. Never surface this to the user —
use Self::display_version instead.
display_version: ConcreteVersionThe same version in the ecosystem’s native spelling (pre-osv_version
rewrite), for callers that need to display it back to the user rather
than send it to OSV.
Implementations§
Source§impl ScanTarget
impl ScanTarget
Sourcepub fn new(
key: VulnKey,
osv_name: OsvQueryName,
version: OsvVersion,
display_version: ConcreteVersion,
) -> Self
pub fn new( key: VulnKey, osv_name: OsvQueryName, version: OsvVersion, display_version: ConcreteVersion, ) -> Self
Constructs a ScanTarget from its four fields.
Needed because Self is #[non_exhaustive]: a struct literal only works inside
this crate, so every other crate must go through this constructor instead.
Prefer Self::from_native when version is simply display_version rewritten via
crate::lsp_helpers::OsvNaming::osv_version — the common production shape — so the
pair is derived rather than hand-rolled at every call site.
§Arguments
key- This project’s internal lookup key — used to keyVulnerabilityMap, not what gets sent to OSVosv_name- OSV’s package name for this ecosystem — sent on the wire, distinct fromkeybecause the two do not always round-trip (seeSelf::key’s docs) — with its trust levelversion- Concrete version rewritten to OSV’s wire spelling (EcosystemFormatter::osv_version) — sent to OSV, never shown to the userdisplay_version- The same version in the ecosystem’s native spelling, for surfacing back to the user instead ofversion
Sourcepub fn with_siblings(
self,
versions: &InUseVersions,
naming: &dyn OsvNaming,
) -> Self
pub fn with_siblings( self, versions: &InUseVersions, naming: &dyn OsvNaming, ) -> Self
Attaches the sibling release tags of versions, deriving each wire version via
naming.osv_version.
Taking crate::lsp_helpers::InUseVersions (which only
crate::lsp_helpers::resolve_in_use_versions produces) keeps arbitrary tags from being
attached. Only crate::osv::OsvClient’s local-matching path evaluates siblings; a
server-side matched target carrying any is skipped fail-closed.
Sourcepub fn siblings(&self) -> &[ScanVersion]
pub fn siblings(&self) -> &[ScanVersion]
The sibling release tags attached via Self::with_siblings.
Sourcepub fn from_native(
key: VulnKey,
osv_name: OsvQueryName,
native: ConcreteVersion,
naming: &dyn OsvNaming,
) -> Self
pub fn from_native( key: VulnKey, osv_name: OsvQueryName, native: ConcreteVersion, naming: &dyn OsvNaming, ) -> Self
Constructs a ScanTarget from a native (ecosystem-spelled) version, deriving the wire
version field via naming.osv_version(&native) — so a caller no longer hand-rolls the
(formatter.osv_version(&v), v) pair Self::new would otherwise require.
§Examples
use deps_core::ConcreteVersion;
use deps_core::lsp_helpers::OsvNaming;
use deps_core::osv::{OsvPackageName, OsvQueryName, ScanTarget};
use deps_core::test_util::vuln_key;
struct DefaultFormatter;
impl OsvNaming for DefaultFormatter {}
let target = ScanTarget::from_native(
vuln_key("time"),
OsvQueryName::Confirmed(OsvPackageName::new("time").unwrap()),
ConcreteVersion::new("0.1.43"),
&DefaultFormatter,
);
assert_eq!(target.version, "0.1.43");
assert_eq!(target.display_version, "0.1.43");Trait Implementations§
Source§impl Clone for ScanTarget
impl Clone for ScanTarget
Source§impl Debug for ScanTarget
impl Debug for ScanTarget
impl Eq for ScanTarget
Source§impl PartialEq for ScanTarget
impl PartialEq for ScanTarget
impl StructuralPartialEq for ScanTarget
Auto Trait Implementations§
impl Freeze for ScanTarget
impl RefUnwindSafe for ScanTarget
impl Send for ScanTarget
impl Sync for ScanTarget
impl Unpin for ScanTarget
impl UnsafeUnpin for ScanTarget
impl UnwindSafe for ScanTarget
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.