redact

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 3 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 redact masks secrets in text before it leaves the server.

Redaction is a safety net, not a guarantee: providers must still avoid reading secret material in the first place.

Index

Constants

View Source
const Mask = "[REDACTED]"

Mask is the replacement for a redacted value.

Variables

This section is empty.

Functions

func Fragment

func Fragment(s string, ranges []Range, start, end int) string

Fragment renders s[start:end] using ranges computed over the full s. Each visible part of an intersecting secret is masked, even at page boundaries. CR and LF bytes are preserved, masking each nonempty part of a secret line separately so line numbers and line endings remain stable. Bounds must satisfy 0 <= start <= end <= len(s); ranges must come from Ranges(s).

func SensitiveFlag

func SensitiveFlag(flag string) bool

SensitiveFlag reports whether a standalone long flag takes a secret value. Short flags are deliberately excluded because their meanings vary by program.

func SensitiveKey

func SensitiveKey(k string) bool

SensitiveKey reports whether a key's value is masked by Value.

func String

func String(s string) string

String returns s with known secret patterns replaced by Mask.

func Value

func Value(v any) any

Value walks maps, slices and strings (as produced by encoding/json into any) and redacts string values, plus the whole value of sensitive keys. Containers are copied so the caller's data is not modified.

Types

type Range

type Range struct {
	Start int
	End   int
}

Range is a sensitive byte interval [Start, End) in the original text.

func Ranges

func Ranges(s string) []Range

Ranges returns sorted, non-overlapping sensitive ranges in s. Incomplete private-key PEM blocks extend to the source boundary. Quoted assignments left open on their line extend to the line boundary.

Jump to

Keyboard shortcuts

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