Skip to main content

NativeContext

Struct NativeContext 

Source
pub struct NativeContext<'a> {
    pub started_at: String,
    pub ended_at: String,
    pub analyzer_version: Option<String>,
    pub exit_status: i32,
    pub source: &'a SourceIdentity,
    pub rules_digest: Option<String>,
    pub advisory_db: Option<AdvisoryDb>,
    pub worktree: Option<&'a Path>,
    pub snippets: &'a dyn SnippetSource,
}
Expand description

Everything an adapter may need that is not in the analyzer’s own output.

Native analyzer output is missing things the evidence chain requires — no mainstream analyzer stamps its report with the wall-clock window it ran in, and cargo audit does not even record its own version. Rather than let an adapter invent them, the caller supplies what it actually knows, and an adapter that has nothing better says so (UNKNOWN_VERSION).

Fields§

§started_at: String

When the run started, RFC 3339 UTC. A subprocess run measures it; an ingest of a report file uses the file’s modification time, which is the only timestamp evidence a bare report carries.

§ended_at: String

When the run ended, RFC 3339 UTC.

§analyzer_version: Option<String>

The analyzer’s version, where the caller learned it out of band (a subprocess run asks the binary). None leaves the adapter to use whatever the report itself carries.

§exit_status: i32

The analyzer’s process exit status, where the caller observed it.

§source: &'a SourceIdentity

The source identity the run was against. Some identity recipes need it — cargo-audit keys findings by lockfile blob, so a finding stays distinct when the lockfile changes underneath the same advisory.

§rules_digest: Option<String>

Digest of the rule set the analyzer ran with, where one applies.

§advisory_db: Option<AdvisoryDb>

The pinned advisory database the caller provisioned, where one applies.

A fallback, not an override: an adapter prefers what the analyzer’s own report says about the database it consulted, and uses this only when the report says nothing. cargo audit says nothing whenever it is pointed at a database with --db, which is every pinned run — so without this, the reproducible configuration would be the one with no staleness evidence.

§worktree: Option<&'a Path>

The checkout the report describes, where the caller knows it.

Only an adapter whose analyzer reports absolute paths needs this, and osv-scanner is that adapter: it returns a full filesystem path for every manifest even when it is told to scan .. Without the worktree there is nothing to relativise against, so an absolute path would be stored verbatim — user-identifying data in a persisted finding key, and a key that differs between two machines running the identical scan.

None is the honest answer for a report about a tree this checkout does not have; an adapter must then say the location is unknown rather than guess at one.

§snippets: &'a dyn SnippetSource

Where to read the source a finding points at, for identity recipes that include a snippet hash.

It is here rather than inside an adapter because the caller knows which checkout the report describes, and because both execution paths must read the same one — that is what makes a subprocess run and an ingest of its output produce identical finding keys.

Implementations§

Source§

impl NativeContext<'_>

Source

pub fn version_or(&self, from_report: Option<&str>) -> String

The version to record: what the caller learned, else what the report carried, else UNKNOWN_VERSION.

Never empty — crate::IngestRunner refuses a report that cannot say what version produced it, and “unknown” is a truthful answer where an empty string is a missing one.

Trait Implementations§

Source§

impl<'a> Clone for NativeContext<'a>

Source§

fn clone(&self) -> NativeContext<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NativeContext<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for NativeContext<'a>

§

impl<'a> !Send for NativeContext<'a>

§

impl<'a> !Sync for NativeContext<'a>

§

impl<'a> !UnwindSafe for NativeContext<'a>

§

impl<'a> Freeze for NativeContext<'a>

§

impl<'a> Unpin for NativeContext<'a>

§

impl<'a> UnsafeUnpin for NativeContext<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.