Documentation
¶
Overview ¶
Package detect is the third pipeline stage: it matches registry patterns, entropy and keyword context, computes the fingerprint id and confidence, and emits candidate.Candidate envelopes.
Index ¶
Constants ¶
const Patterns = "registry"
Patterns is the name of the registry pattern adapter.
Variables ¶
var ErrNoRegistry = errors.New("detect: no registry")
ErrNoRegistry is returned when Options.Registry is nil.
Functions ¶
func Fingerprint ¶
Fingerprint returns the stable finding id of a credential:
"th_" + hex(sha256(provider + "\x00" + part1 + "\x00" + part2 ...))[:16]
parts are the credential's ordered parts as the registry declares them (one part for a single key). The id depends only on the provider and the parts, never on a path, line or commit, so the same key has the same id everywhere and on every OS.
func HasTestMarker ¶
HasTestMarker reports whether raw carries the test key marker, plain or hex encoded (either case).
Types ¶
type Batch ¶
type Batch interface {
Detect(ctx context.Context, c candidate.Chunk, emit func(candidate.Candidate) bool, event func(model.Event))
End(ctx context.Context, emit func(candidate.Candidate) bool, event func(model.Event))
}
Batch detects in the chunks of one source chunk. Detect handles one chunk (the source chunk or a chunk decoded from it) and records single-part credentials at once; parts of multi-part credentials are buffered until End pairs them and records the result. End must be called once, after the last Detect, with the same emit; it stops early when ctx is done.
type Detector ¶
type Detector interface {
Detect(ctx context.Context, c candidate.Chunk, emit func(candidate.Candidate) bool, event func(model.Event))
Begin() Batch
Merged(id string) (model.Finding, bool)
}
Detector is the detect stage interface. Detect finds credentials in one chunk. The first sighting of a credential is emitted as a Candidate (emit returns false when the scan is stopping) with a finding-detected event; later sightings only add locations to the dedupe record, with a location-added event each. After the engine barrier, Merged(first-sight id) returns the detect-owned fields of a finding with every location, computed from the best winner over every sighting.
Begin starts a Batch: one source chunk plus every chunk decoded from it. Parts of a multi-part credential are paired only within one Batch, at End; Detect equals Begin, Batch.Detect and Batch.End on one chunk. Detect, Begin and Merged are safe for concurrent use; one Batch is used by one goroutine. event is called with an internal lock held and must not block.
func NewPatterns ¶
NewPatterns returns a detector running every pattern of opts.Registry.
type Pattern ¶
type Pattern struct {
// contains filtered or unexported fields
}
Pattern is the registry pattern detector.
func (*Pattern) Detect ¶
func (p *Pattern) Detect(ctx context.Context, c candidate.Chunk, emit func(candidate.Candidate) bool, event func(model.Event))
Detect runs every pattern and the generic detector over c alone: it is Begin, Batch.Detect and Batch.End on one chunk.
func (*Pattern) Merged ¶
Merged returns the detect-owned fields of the finding forwarded under the first-sight id, with every location sorted. Its ID, Provider, Detector, Confidence and AlsoMatchedBy come from the best winner over every sighting, so they do not depend on the order chunks arrived in; the ID may differ from the first-sight id.