Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Callback ¶
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 Option ¶ added in v0.45.0
type Option func(*Phrasestream)
Option configures a Phrasestream at construction. Options set matching behaviour only; Reset keeps them and swaps just the writer.
func WithASCIICaseFolding ¶ added in v0.45.0
func WithASCIICaseFolding() Option
WithASCIICaseFolding matches phrases ignoring ASCII letter case.
func WithFold ¶ added in v0.45.0
WithFold compares input bytes through fold; bytes that fold to the same value match. Output keeps the input bytes. fold must be a byte-to-byte map: the matcher relies on phrases and input having equal length after folding to replay abandoned partial matches and to compare a buffered match with its trie key.
type Phrasestream ¶
type Phrasestream struct {
// contains filtered or unexported fields
}
func New ¶
func New(w io.Writer, opts ...Option) *Phrasestream
New returns a new Phrasestream writing to w. Without options phrases match byte for byte.
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.