phrasestream

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Mask

func Mask(w io.Writer, _ string, _ []byte) error

Mask writes [MASKED] to the provided writer.

func StopCRLF

func StopCRLF(b byte) bool

StopCRLF returns true on a line feed (LF) or carriage return (CR).

Types

type Callback

type Callback func(w io.Writer, phrase string, buf []byte) error

Callback provides the underlying writer, the phrase that triggered the callback, and any data after the phrase was matched based on the stop function provided.

type Phrasestream

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

func New

func New(w io.Writer) *Phrasestream

New returns a new Phrasestream.

func (*Phrasestream) Add

func (ps *Phrasestream) Add(phrase string, fn Callback, stop Stop)

Add adds a new phrase with callback and optional stop.

Add can be called mid-Write, and is in fact expected to be: a callback (e.g. the ::add-mask:: directive handler) registers a freshly-discovered secret as a phrase, and the bytes immediately following the directive in the same Write must already see the new phrase as a mask target. Queuing the insert until the next Write would let a directive and the secret it declares leak when emitted in one write call, which defeats the directive's purpose.

Because Add runs while a trie walk is in progress, the new phrase can split the trie node the cursor (ps.n) is on. When that happens we re-walk the trie from root using ps.buf — the bytes captured since the last confirmed match — to put the cursor back on the correct node and matching position. ps.last is deliberately not reset: a phrase registered at byte N matches bytes >= N, never retroactively against bytes buffered before the phrase existed.

func (*Phrasestream) Close

func (ps *Phrasestream) Close() error

Close flushes any data in internal buffers.

func (*Phrasestream) Reset

func (ps *Phrasestream) Reset(w io.Writer)

Reset resets the Phrasestream.

func (*Phrasestream) Write

func (ps *Phrasestream) Write(p []byte) (int, error)

Write processes p and writes it to the underlying writer.

type Stop

type Stop func(byte) bool

Stop is a function provided with a phrase callback that collects any data after a phrase is matched until the stop function returns true.

Jump to

Keyboard shortcuts

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