secretmask

package
v1.5.13 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 15 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 secretmask masks known secret values in text before it is written to a log, audit row or stored build output.

Index

Constants

View Source
const (
	// Marker replaces a known secret.
	Marker = "[redacted]"
	// MinLength skips short values: masking "true" or "1234" would shred ordinary text.
	MinLength = 8
)

Variables

This section is empty.

Functions

func Add

func Add(v string)

Add registers v in the process-wide registry.

func Handler

func Handler(next slog.Handler) slog.Handler

Handler wraps next so every string attribute and message is masked.

func Mask

func Mask(s string) string

Mask masks s with the process-wide registry.

Types

type Line

type Line struct {
	Stream string
	Text   string
}

Line is one log line with the stream it came from.

type LineCarry

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

LineCarry masks a sequence of log lines while catching a secret that spans a line break. It holds back raw trailing lines covering the last n-1 bytes, n being the longest multi-line secret (nothing is held without one), so the caller must Flush after a short idle interval and at stream end.

func NewLineCarry

func NewLineCarry() *LineCarry

NewLineCarry masks with the process-wide registry.

func NewLineCarryFor

func NewLineCarryFor(reg *Registry) *LineCarry

NewLineCarryFor masks with reg.

func (*LineCarry) Flush

func (c *LineCarry) Flush() []Line

Flush emits everything held, masked.

func (*LineCarry) Pending

func (c *LineCarry) Pending() bool

Pending reports whether raw lines are still held back.

func (*LineCarry) Push

func (c *LineCarry) Push(stream, text string) []Line

Push adds a raw line and returns the masked lines that are now safe to emit.

type Registry

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

Registry holds secret values and rewrites text that contains them.

func New

func New() *Registry

New returns an empty registry.

func (*Registry) Add

func (r *Registry) Add(v string)

Add registers a secret value; short values are ignored. The cap counts primary values only, encoded forms ride along, and a primary is never evicted.

func (*Registry) Len

func (r *Registry) Len() int

Len reports how many values are registered.

func (*Registry) Mask

func (r *Registry) Mask(s string) string

Mask replaces every registered value in s. Overlapping and prefix matches are merged into one span so no tail of a longer secret survives a shorter hit.

type Writer

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

Writer masks a byte stream. It holds back the last maxLen-1 bytes of each write so a secret split across two writes is still seen whole.

func NewWriter

func NewWriter(dst io.Writer) *Writer

NewWriter masks with the process-wide registry.

func NewWriterFor

func NewWriterFor(dst io.Writer, reg *Registry) *Writer

NewWriterFor masks with reg.

func (*Writer) Close

func (w *Writer) Close() error

Close flushes; it does not close dst.

func (*Writer) Flush

func (w *Writer) Flush() error

Flush emits the held-back tail. Call it when the stream ends.

func (*Writer) Write

func (w *Writer) Write(p []byte) (int, error)

Write always reports len(p) so io.Copy keeps draining even when dst fails late. The carry stays raw: masking it early would hide a longer secret that a shorter one sits inside.

Jump to

Keyboard shortcuts

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