candidate

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 9 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 candidate defines the stage envelopes: Chunk, which carries content from source through decode to detect, and Candidate, which detect hands on toward verify with a Finding, its secret.Secret key material and the precomputed suppression context.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	Finding  model.Finding `json:"finding"`
	Key      secret.Secret `json:"key"`
	Parts    []Part        `json:"parts,omitempty"`
	Unpaired bool          `json:"unpaired,omitempty"`
	Ctx      SuppressCtx   `json:"ctx"`
}

Candidate is what detect hands on toward verify: the Finding detect owns so far, the key material sealed in a secret.Secret, and the raw-key predicates that only detect can compute but only suppress decides on. It is internal and never part of the public API; verify drops Key when it turns a Candidate into a Finding.

For a multi-part credential, Key is the primary part and Parts holds every part in the registry's declared order (nil for a single-part key). Unpaired marks a primary part found without its partners: verify reports it not-verified/unpaired.

type Chunk

type Chunk struct {
	Location model.Location
	Data     []byte
	Origin   *Origin
}

Chunk is the stage envelope from source through decode to detect: one readable unit of content and the Location it came from (Line and Column unset; detect sets them per match on a copy). Data is content and must never be printed, logged or put into a warning, so every print, log and marshal method shows only the path and size.

Origin is nil for a chunk a source read. A chunk decode produced from another one carries its Origin, which maps every byte of Data back to the source chunk, so detect can report where the encoded form starts in the original content.

func (Chunk) Format

func (c Chunk) Format(f fmt.State, _ rune)

Format prints the location path and the data length, never the data.

func (Chunk) LogValue

func (c Chunk) LogValue() slog.Value

LogValue logs the location path and the data length, never the data.

func (Chunk) MarshalJSON

func (c Chunk) MarshalJSON() ([]byte, error)

MarshalJSON marshals the location and the data length, never the data.

type LocationAllow added in v0.2.0

type LocationAllow struct {
	Location model.Location `json:"location"`
	Bare     bool           `json:"bare,omitempty"`
	IDs      []string       `json:"ids,omitempty"`
}

LocationAllow is the inline allow fact of one location: Bare for a bare tokenhound:allow marker (any finding), IDs for the id form (only the named ids, sorted).

func (LocationAllow) Covers added in v0.2.0

func (a LocationAllow) Covers(ids ...string) bool

Covers reports whether the fact allows a finding known under any of ids.

type Origin

type Origin struct {
	// Root is the Data of the source chunk, shared, not copied.
	Root []byte
	// Offsets has one entry per byte of the decoded Data: byte i of Data comes from
	// Root[Offsets[i]].
	Offsets []int32
	// Depth is the number of decoding steps from Root (1 = decoded once).
	Depth int
	// Index is the newline index of Root, shared by every chunk decoded from one
	// source chunk; nil means the reader builds its own.
	Index *RootIndex
}

Origin maps a decoded chunk back to the source chunk it was decoded from. Root is content too: it is never printed, logged or marshalled.

func (Origin) Format

func (o Origin) Format(f fmt.State, _ rune)

Format prints the depth and the root length, never the root.

func (Origin) LogValue

func (o Origin) LogValue() slog.Value

LogValue logs the depth and the root length, never the root.

func (Origin) MarshalJSON

func (o Origin) MarshalJSON() ([]byte, error)

MarshalJSON marshals the depth and the root length, never the root.

type Part

type Part struct {
	Name string        `json:"name"`
	Key  secret.Secret `json:"key"`
}

Part is one named part of a multi-part credential. Key prints, logs and marshals only its redacted form.

type RootIndex

type RootIndex struct {
	// contains filtered or unexported fields
}

RootIndex lazily computes the byte offsets of every newline in a root, once, and is safe for concurrent use.

func NewRootIndex

func NewRootIndex(root []byte) *RootIndex

NewRootIndex returns an index of root; nothing is computed until Newlines.

func (*RootIndex) Newlines

func (x *RootIndex) Newlines() []int

Newlines returns the sorted byte offsets of every newline in the root. Callers must not modify the result.

type SuppressCtx

type SuppressCtx struct {
	// TestMarker is true when the key carries the TOKENHOUNDTEST marker.
	TestMarker bool `json:"test_marker"`
	// InlineAllow is true when an inline allow comment covers the candidate's first
	// location (a bare marker, or the id form naming the first-sight id).
	InlineAllow bool `json:"inline_allow"`
	// AllowlistHits lists the allowlist entries the key matched.
	AllowlistHits []string `json:"allowlist_hits"`
	// FirstID is the first-sight id of the credential, so an id rule or an inline
	// id-form marker naming it still applies when a better winner changes the id.
	FirstID string `json:"first_id,omitempty"`
	// Allows are the inline allow facts per location, merged over every sighting:
	// only locations with a marker on the match line or the line above are listed.
	// On an emitted candidate it covers the first location only; the merged context
	// detect returns after the barrier covers every location.
	Allows []LocationAllow `json:"allows,omitempty"`
}

SuppressCtx holds the suppression predicates detect precomputes from the raw key and its surroundings.

Jump to

Keyboard shortcuts

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