markers

package
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Start       = '‹'
	StartS      = string(Start)
	StartLen    = len(StartS)
	End         = '›'
	EndS        = string(End)
	EndLen      = len(EndS)
	EscapeMark  = '?'
	EscapeMarkS = string(EscapeMark)
	RedactedS   = StartS + "×" + EndS
	HashPrefix  = '†'
	HashPrefixS = string(HashPrefix)
)

Internal constants.

Variables

View Source
var (
	StartBytes      = []byte(StartS)
	EndBytes        = []byte(EndS)
	EscapeMarkBytes = []byte(EscapeMarkS)
	RedactedBytes   = []byte(RedactedS)
	HashPrefixBytes = []byte(HashPrefixS)
)

Internal variables.

Functions

func DisableHashing added in v1.1.7

func DisableHashing()

DisableHashing disables hash-based redaction. The pool and salt are intentionally left intact so that in-flight hashers (which captured the pool pointer) can finish safely.

func EnableHashing added in v1.1.7

func EnableHashing(salt []byte)

EnableHashing enables hash-based redaction with an optional salt. When salt is nil, hash markers use plain SHA-256. When salt is provided, hash markers use HMAC-SHA256 for better security.

A sync.Pool of hasherState instances is created here with the correct hasher type, so hash functions just Get/Reset/Put without checking salt.

func EndMarker

func EndMarker() []byte

EndMarker returns the end delimiter for an unsafe string.

func EscapeMarkers

func EscapeMarkers(s []byte) []byte

EscapeMarkers escapes the special delimiters from the provided byte slice.

func IsHashingEnabled added in v1.1.7

func IsHashingEnabled() bool

IsHashingEnabled returns true if hash-based redaction is enabled.

func RedactedMarker

func RedactedMarker() []byte

RedactedMarker returns the special string used by Redact.

func StartMarker

func StartMarker() []byte

StartMarker returns the start delimiter for an unsafe string.

Types

type RedactableBytes

type RedactableBytes []byte

RedactableBytes is like RedactableString but is a byte slice.

Instances of RedactableBytes should not be constructed directly; instead use the facilities from print.go (Sprint, Sprintf) or the methods below.

func (RedactableBytes) Redact

func (s RedactableBytes) Redact() RedactableBytes

Redact replaces all occurrences of unsafe substrings by the "Redacted" marker, ‹×›. Hash markers (‹†value›) are replaced with hashed values (‹hash›) if hashing is enabled, otherwise they are redacted like regular markers.

func (RedactableBytes) SafeFormat

func (s RedactableBytes) SafeFormat(sp i.SafePrinter, _ rune)

SafeFormat formats the redactable safely.

func (RedactableBytes) StripMarkers

func (s RedactableBytes) StripMarkers() []byte

StripMarkers removes the redaction markers from the RedactableBytes. This returns an unsafe string where all safe and unsafe bits are mixed together.

func (RedactableBytes) ToString

func (s RedactableBytes) ToString() RedactableString

ToString converts the byte slice to a string.

type RedactableString

type RedactableString string

RedactableString is a string that contains a mix of safe and unsafe bits of data, but where it is known that unsafe bits are enclosed by redaction markers ‹ and ›, and occurrences of the markers inside the original data items have been escaped.

Instances of RedactableString should not be constructed directly; instead use the facilities from print.go (Sprint, Sprintf) or the methods below.

func (RedactableString) Redact

Redact replaces all occurrences of unsafe substrings by the "Redacted" marker, ‹×›. Hash markers (‹†value›) are replaced with hashed values (‹hash›) if hashing is enabled, otherwise they are redacted like regular markers. The result string is still safe.

func (RedactableString) SafeFormat

func (s RedactableString) SafeFormat(sp i.SafePrinter, _ rune)

SafeFormat formats the redactable safely.

func (RedactableString) StripMarkers

func (s RedactableString) StripMarkers() string

StripMarkers removes the redaction markers from the RedactableString. This returns an unsafe string where all safe and unsafe bits are mixed together.

func (RedactableString) ToBytes

func (s RedactableString) ToBytes() RedactableBytes

ToBytes converts the string to a byte slice.

Jump to

Keyboard shortcuts

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