scan

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: GPL-2.0, GPL-2.0-only Imports: 25 Imported by: 0

Documentation

Overview

Package scan contains reusable scan utilities shared by CLI commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildAnnotateExport added in v0.8.0

func BuildAnnotateExport(report *entities.InterimReport, fragment graphfrag.Fragment) graphfrag.GraphFragmentExport

BuildAnnotateExport produces a graph-fragment export carrying ONLY scan_metadata + crypto_annotations, mapping each crypto finding in report to its containing function using the imported (cached) structural fragment.

This is the annotate-only path: it runs after a detection-only scan (no callgraph build, the expensive ~95% of a scan) so a rules refresh can re-annotate a component against its already-cached structure.

Invariant: for the SAME source + rules, the crypto_annotations here are byte-identical to what a full `scan --export-graph-fragment` emits. This holds because:

  • the detection-derived fields (finding_id, rule_id, expression, file_path, line range, oid, source, metadata, matched_operation) come from the SAME builder the full exporter uses (buildBaseGraphFragmentCryptoAnnotation);
  • function_key is recovered from the imported fragment's function line ranges, which were produced by the same scan that the full export read its containing function from;
  • crypto_call and the call-resolved Symbol override are carried verbatim from the imported fragment's matching CryptoOperation (joined by finding_id) — the full export already computed those from the live graph, so reusing them avoids both rebuilding the callgraph and any drift.

Functions, internal_edges, and external_calls are intentionally left empty: the structure lives in the imported fragment and is not rebuilt here.

func BuildGraphFragmentExport added in v0.6.0

func BuildGraphFragmentExport(result *engine.DepScanResult) graphfrag.GraphFragmentExport

BuildGraphFragmentExport projects a dependency scan result onto the public graph-fragment export schema.

func CountFindings

func CountFindings(report *entities.InterimReport) int

CountFindings counts total cryptographic assets across all findings.

func DetectEcosystem

func DetectEcosystem(target string) string

DetectEcosystem checks the target directory for known manifest files and returns the corresponding ecosystem name ("go", "python", "java", "rust"). Returns empty string if no ecosystem is detected.

Polyglot resolution: when a pyproject.toml declares a Python package (via [project] / [tool.*] / PEP 517 build backend), it wins over Cargo.toml — this captures Python packages that embed Rust via PyO3, maturin or setuptools-rust (pyca/cryptography, pydantic-core, orjson, polars, ...). Polyglot conflicts outside the Python↔Rust pair are not disambiguated here; they keep the original precedence (Go → Java → Rust → Python fallback).

func DetectRootModule

func DetectRootModule(targetDir, ecosystem string) string

DetectRootModule returns a best-effort root module/package name for callgraph export. It is manifest-based when possible and falls back to the target directory name.

func ExportCallGraph

func ExportCallGraph(path, format string, result *engine.DepScanResult) error

ExportCallGraph writes a finding-centric call graph export (schema v4.3).

func ExportGraphFragment added in v0.6.0

func ExportGraphFragment(path, format string, result *engine.DepScanResult) error

ExportGraphFragment writes the dependency scan result's call graph as a graph-fragment export in the requested format.

func MarshalAnnotateExport added in v0.8.0

func MarshalAnnotateExport(payload *graphfrag.GraphFragmentExport) ([]byte, error)

MarshalAnnotateExport serializes an annotate-only graph-fragment export as indented JSON, matching the formatting of ExportGraphFragment.

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

ParseDuration parses a duration string supporting standard Go formats plus: - "d" for days (e.g., "30d" = 720 hours) - "w" for weeks (e.g., "2w" = 336 hours)

Standard formats (ns, us, ms, s, m, h) are parsed by time.ParseDuration.

func PrintSummary

func PrintSummary(outputPath string, filesCount, findingsCount int) error

PrintSummary displays scan summary in a user-friendly format.

func ValidateFlags

func ValidateFlags(target string, opts ValidationOptions) ([]string, error)

ValidateFlags validates scan inputs and returns normalized language hints.

func WriteAnnotateExport added in v0.8.0

func WriteAnnotateExport(path string, payload *graphfrag.GraphFragmentExport) error

WriteAnnotateExport writes an annotate-only graph-fragment export to path as indented JSON, matching the formatting of ExportGraphFragment.

Types

type ValidationOptions

type ValidationOptions struct {
	RuleFiles        []string
	RuleDirs         []string
	NoRemoteRules    bool
	Scanner          string
	AllowedScanners  []string
	Interfile        bool
	InterfileScanner string
	Format           string
	SupportedFormats []string
	Languages        []string
	ScanDependencies bool
	ExportCallgraph  string
}

ValidationOptions contains scan flag values required for validation.

Jump to

Keyboard shortcuts

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