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 Phrasestream ¶
type Phrasestream struct {
// contains filtered or unexported fields
}
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.