importkit

package
v2.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package importkit holds the text, reference and package helpers shared by the importers of package importer and the interoperability adapters (v2/interop/<format>, nested modules of this repository). It is internal: the helpers are not part of the module's API and change with the importers.

Index

Constants

View Source
const (
	CapTitle       = 500
	CapCategory    = 255
	CapDescription = 32 << 10
	CapEvidence    = 64 << 10
	CapRemediation = 16 << 10
	CapReference   = 2 << 10
	MaxReferences  = 100
	CapTag         = 100
	MaxTags        = 50
	CapShort       = 255
)

Text caps, the same as the CTIS receiver caps (spec section 7), so a report never carries more than a receiver keeps.

View Source
const CodeAssetID = "asset-1"

CodeAssetID is the id of the one asset of a code report.

View Source
const MaxDepProperties = 32

MaxDepProperties bounds the properties of one dependency.

View Source
const MaxDependsOn = 1000

MaxDependsOn bounds the depends_on list of one dependency.

View Source
const ProbeID = "0192f0a0-0000-7000-8000-000000000001"

ProbeID is a UUIDv7: Validate requires metadata.id.

View Source
const TruncMarker = "…[truncated]"

Variables

View Source
var ProbeTime = time.Unix(1, 0).UTC()

ProbeTime is any non-zero time: Validate requires metadata.generated_at.

View Source
var PurlTypes = map[string]string{
	"npm": "npm", "pypi": "pypi", "pip": "pypi", "maven": "maven", "gradle": "maven",
	"nuget": "nuget", "cargo": "cargo", "crates.io": "cargo", "golang": "golang", "go": "golang",
	"composer": "composer", "packagist": "composer", "gem": "gem", "rubygems": "gem",
	"hex": "hex", "pub": "pub", "swift": "swift", "swifturl": "swift", "cocoapods": "cocoapods",
}

PurlTypes maps OSV ecosystem names and language words to the package URL type.

Functions

func AddDepProperty

func AddDepProperty(d *ctis.Dependency, key, value string)

AddDepProperty sets a bounded dependency property.

func AddRefs

func AddRefs(dst []string, refs ...string) []string

AddRefs appends bounded, distinct references.

func AddScore

func AddScore(f *ctis.Finding, s ctis.Score)

AddScore appends a score if there is room and it is valid on its own.

func AddTags

func AddTags(dst []string, tags ...string) []string

AddTags appends bounded, distinct tags.

func AddVendorID

func AddVendorID(v *ctis.VulnerabilityDetails, raw, source string)

AddVendorID adds an id the vendor named source issued (an advisory number, a plugin id the source treats as the vulnerability's) to v.

func AddVulnID

func AddVulnID(v *ctis.VulnerabilityDetails, raw string)

AddVulnID adds a CVE, GHSA or OSV id to v once (canonical form); an id of another shape is dropped. Use addVendorID for a vendor's own id.

func AddWebRefs

func AddWebRefs(dst []string, refs ...string) []string

AddWebRefs appends the http(s) URLs among refs (bounded, distinct).

func AppendUnique

func AppendUnique(dst []string, s string) []string

func CleanPURL

func CleanPURL(purl string) string

CleanPURL bounds a package URL and drops one with control characters or whitespace (a hostile value must not reach a receiver's match keys).

func CvssOrder

func CvssOrder(version string) int

CvssOrder ranks CVSS versions: the newest version wins.

func CvssVectorScore

func CvssVectorScore(vector, source string) (ctis.Score, bool)

CvssVectorScore returns a CVSS score of a vector string with no value.

func DocRef

func DocRef(prefix, s string) string

DocRef builds a document-local reference "<prefix>-<s>" (ctis.IsDocumentRef: never UUID-shaped, at most 255 characters of the reference alphabet). When s does not fit the alphabet or the length, the reference is the prefix and a hash of s, so it is stable and still unique per s.

func Extra

func Extra(f *ctis.Finding, key, value string)

Extra stores an unmapped source value on f (bounded by ctis.SetSourceExtra).

func Extras

func Extras(f *ctis.Finding, kv ...string)

Extras stores key/value pairs in order (see extra).

func FirstNonEmpty

func FirstNonEmpty(vals ...string) string

func FloatString

func FloatString(v float64) string

FloatString formats a score for a native value.

func GoodPURL

func GoodPURL(purl string) string

GoodPURL returns a package URL that has a canonical form, else "".

func Line

func Line(s string, limit int) string

Line cleans a one-line value: like text, and newlines and tabs become spaces.

func NameVersion

func NameVersion(name, version string) string

NameVersion returns "name@version", or the name alone.

func ParseTime

func ParseTime(s string) *time.Time

ParseTime reads an RFC 3339 time (with or without fractional seconds), or a date.

func Probe

func Probe() ctis.Report

Probe is the smallest valid report, for checking one value with Validate.

func PurlName

func PurlName(purl string) string

PurlName returns the name of a package URL with its namespace ("@scope/name", "group:artifact"), unescaped, or "".

func PurlOf

func PurlOf(ecosystem, name, version string) string

PurlOf builds a package URL from an OSV ecosystem, a name and a version; "" when the ecosystem has no package URL type or the result is not a canonical package URL.

func PurlType

func PurlType(purl string) string

PurlType returns the type of a package URL ("npm", "golang", "maven"), or "" when s is not a package URL.

func RawTextEvidence

func RawTextEvidence(f *ctis.Finding, label, body, protocol string)

RawTextEvidence adds source text as a raw_text evidence item. The text is bounded; an empty text adds nothing. Callers pass text that holds no credential (ctis.RedactSecretFinding masks what the builder sees).

func RefOr

func RefOr(prefix, s string) string

RefOr returns s when it already is a document reference, else a reference derived from it (docRef with the prefix).

func RepoAsset

func RepoAsset(value, branch, commit, source string) ctis.Asset

RepoAsset is a repository asset with the branch and commit it was scanned at, and where the importer learned it (properties.source). It carries no criticality: that is the receiver's call (CTIS spec 4.1).

func SeverityFromCVSS

func SeverityFromCVSS(score float64) ctis.Severity

SeverityFromCVSS bands a CVSS base score (the CVSS v3/v4 qualitative scale).

func SeverityWord

func SeverityWord(s string) (ctis.Severity, bool)

SeverityWord maps a qualitative severity word of an advisory database (CRITICAL, HIGH, MODERATE, MEDIUM, LOW, NONE, INFO).

func SourceRef

func SourceRef(system, id string) ctis.SourceRef

SourceRef is a bounded source reference.

func StripUserinfo

func StripUserinfo(s string) string

StripUserinfo removes credentials from a URL (https://user:pass@host/).

func SubjectAssetOf

func SubjectAssetOf(kind, purl, name, version, fallback string) (ctis.AssetType, string)

SubjectAssetOf chooses the asset type and value of an SBOM subject (a CycloneDX metadata component, an SPDX root package): a container is an image when its name and version make an image reference, a component with a package URL is that package, anything else is unclassified, named by name and version (or fallback).

func Text

func Text(s string, limit int) string

Text cleans a source text: control characters other than tab, newline and carriage return are removed, the ends are trimmed, and a value longer than limit characters is cut with a marker.

func TokenOf

func TokenOf(s string) string

TokenOf lowercases the name of an advisory source into an open token (a-z, 0-9, '.', '_', '-'); anything else becomes '-'. It may be empty.

func VexOf

func VexOf(nativeStatus, nativeJustification, statement, source string, asOf *time.Time) (ctis.VEX, error)

VexOf builds a CTIS VEX statement from a document's native status and justification. It returns an error for a status no table knows, and for a not_affected statement with neither a known justification nor an impact statement (CTIS requires one of them, and a receiver must not suppress a finding on a bare claim).

func WebURL

func WebURL(s string) string

WebURL returns s when it is an http or https URL, else "".

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL