Documentation
¶
Overview ¶
Package pii is the product-neutral half of personal-data masking: value detectors (email, phone, IBAN, card, national ids), mask modes, the multilingual name heuristics that propose mask rules, and the store of the clear values behind redacted references. Which value is personal (column provenance, JSON paths, headers) is the product's.
Index ¶
- Constants
- func CellText(v any) string
- func CutAt(s string, n int) string
- func Detect(v any, ds []Detector) any
- func Detects(s string, ds []Detector) bool
- func LooksPersonal(name string) bool
- func LooksPersonalColumn(name, typ string) bool
- func LooksQuasi(name string) bool
- func Mask(mode, value string) string
- func MaskText(s string) string
- func MaskValue(v any, mode string) any
- func RedactedRef(name string) string
- func Tokens(name string) []string
- func ValidMode(m string) bool
- type Detector
- type RefStore
Constants ¶
const ( // ModeRedact replaces the whole value: "<redacted>" (the default). ModeRedact = "redact" // ModePartial keeps the first character and the length: "j***(12)". ModePartial = "partial" // ModeEmail keeps the first character and the domain of an address: // "j***@example.com" (other values are masked as partial). ModeEmail = "email" )
Mask modes.
const ( MaxRefResults = 50 MaxRefBytes = 16 << 20 )
Bounds of the reference store: the oldest results are forgotten first.
const CutMark = "…"
CutMark ends a text value that was cut.
const DetectLimit = 64 << 10
DetectLimit is how much of a text value the detectors scan. A longer value is cut there, and ends with CutMark, before detection: nothing past the scanned part can reach the output. Renderers cut values much earlier, so the cut is normally invisible; it bounds the time a huge value can cost.
const Redacted = "<redacted>"
Redacted is a value masked in mode redact.
Variables ¶
This section is empty.
Functions ¶
func CutAt ¶
CutAt cuts s, which must be longer than n bytes, to at most n bytes followed by CutMark: at a rune boundary, then back over up to cutTail value-like characters, so that a value the cut splits (a partial e-mail address or number, which no detector would recognise) is dropped rather than shown in part.
func Detect ¶
Detect runs the detectors over a text or integer value (a national number or a card can be stored as one) and returns the masked text, or v itself, with its type, when nothing was found. Other values pass.
func LooksPersonal ¶
LooksPersonal reports a field name that looks like personal data.
func LooksPersonalColumn ¶
LooksPersonalColumn is LooksPersonal for a database column of type typ: a network address type is personal whatever its name, and a binary column whose name suggests a document is too.
func LooksQuasi ¶
LooksQuasi reports a field name that looks like a quasi-identifier (birth date, postal code, gender).
func MaskText ¶
MaskText is the partial mask format: first character + "***" + "(length in characters)". An invalid UTF-8 byte counts as one U+FFFD character.
func MaskValue ¶
MaskValue masks one non-nil value in mode. Bytes become "<masked bytes:N>" in modes partial and email; an unknown mode masks as partial.
func RedactedRef ¶
RedactedRef is a redacted value that carries a reference to it, which the console alone resolves (see RefStore).
Types ¶
type Detector ¶
type Detector interface {
Name() string
// Mask returns s with every value the detector recognises replaced by
// its masked form (first character + "***" + "(length)").
Mask(s string) string
}
Detector masks personal values found inside a text, in place.
type RefStore ¶
type RefStore struct {
// contains filtered or unexported fields
}
RefStore keeps the clear values behind the redacted references of the last results, so that an agent can name a value ('${rN.K}') without seeing it. It lives in the console's memory and dies with it. The zero value is ready; it is not safe for concurrent use.
A reference is "r<result>.<key>", where key is positive integers separated by dots chosen by the product: locksql uses "<row>.<column>", PutDistinct numbers the distinct values of a result. A key never holds the value.