licence_audit/osv
OSV.dev REST client.
Two endpoints are used:
POST /v1/querybatch— given a list of purls, returns the vulnerability IDs that affect each one.GET /v1/vulns/{id}— returns the full advisory record for an ID so we can extract a severity bucket and a human summary.
All public functions accept an injected HTTP client (mirroring
licence_audit/hex) so callers can drive the decoder/dispatch logic
from tests without performing real network I/O.
Types
pub opaque type AffectedPackage
A single per-purl result from /v1/querybatch.
pub type BatchEntry {
BatchEntry(purl: String, vuln_ids: List(String))
}
Constructors
-
BatchEntry(purl: String, vuln_ids: List(String))
pub type Error {
InvalidJson(String)
InvalidResponse(String)
RateLimited
NotFound
UnexpectedResponse(status: Int)
NetworkFailure(reason: String)
}
Constructors
-
InvalidJson(String) -
InvalidResponse(String) -
RateLimited -
NotFound -
UnexpectedResponse(status: Int) -
NetworkFailure(reason: String)
A single CVSS score as reported by OSV’s severity[] array. kind is the
OSV score type (e.g. “CVSS_V3”); vector is the raw CVSS vector string
(e.g. “CVSS:3.1/AV:N/…”). Retained so callers can surface the full vector
rather than only the coarse Severity bucket derived from it.
pub type Score {
Score(kind: String, vector: String)
}
Constructors
-
Score(kind: String, vector: String)
pub type Severity {
NoSeverity
Low
Medium
High
Critical
UnknownSeverity
}
Constructors
-
NoSeverity -
Low -
Medium -
High -
Critical -
UnknownSeverity
pub type Vulnerability {
Vulnerability(
id: String,
aliases: List(String),
summary: String,
severity: Severity,
scores: List(Score),
affected: List(AffectedPackage),
)
}
Constructors
-
Vulnerability( id: String, aliases: List(String), summary: String, severity: Severity, scores: List(Score), affected: List(AffectedPackage), )
Values
pub fn decode_vuln_body(
body: String,
fallback_id: String,
) -> Result(Vulnerability, Error)
pub fn encode_batch_body(purls: List(String)) -> String
pub fn fetch_vulnerability_from_osv(
id: String,
) -> Result(Vulnerability, Error)
pub fn for_package(
vuln: Vulnerability,
purl: String,
) -> Vulnerability
Batch results establish advisory membership. Scope only the scores here; never transfer scores from another affected package or version.
pub fn from_http_error(
req: request.Request(String),
error: httpc_adaptive.Error,
) -> Error
pub fn parse_severity_label(raw: String) -> Severity
Parse a textual severity label (e.g. “LOW”, “moderate”, “HIGH”).
Treats “moderate” as Medium to match GHSA terminology.
pub fn query_batch(
purls: List(String),
client: fn(request.Request(String)) -> Result(
response.Response(String),
Error,
),
) -> Result(List(BatchEntry), Error)
Query OSV for vulnerabilities affecting each of purls. Returns one
BatchEntry per input purl, preserving input order. Empty vuln_ids
means OSV reports no known vulnerabilities for that purl.
GitHub purls use commit queries; Hex purls use package queries.
Initial requests contain at most 1,000 queries; any chunk or pagination
failure returns an error instead of partial coverage.
pub fn query_batch_from_osv(
purls: List(String),
) -> Result(List(BatchEntry), Error)
Default OSV client with bounded retries and a command-scoped host cutoff.
pub fn severity_from_cvss_vector(vector: String) -> Severity
Calculate a severity bucket from a complete CVSS v2, v3, or v4 vector.
pub fn severity_rank(severity: Severity) -> Int
pub fn severity_to_string(severity: Severity) -> String