Help us shape the future of Go! Take the 2026 Go Developer Survey

pii

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

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

View Source
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.

View Source
const (
	MaxRefResults = 50
	MaxRefBytes   = 16 << 20
)

Bounds of the reference store: the oldest results are forgotten first.

View Source
const CutMark = "…"

CutMark ends a text value that was cut.

View Source
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.

View Source
const Redacted = "<redacted>"

Redacted is a value masked in mode redact.

Variables

This section is empty.

Functions

func CellText

func CellText(v any) string

CellText is the text of a value, as compared and substituted.

func CutAt

func CutAt(s string, n int) string

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

func Detect(v any, ds []Detector) any

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 Detects

func Detects(s string, ds []Detector) bool

Detects reports whether a detector would mask something in s.

func LooksPersonal

func LooksPersonal(name string) bool

LooksPersonal reports a field name that looks like personal data.

func LooksPersonalColumn

func LooksPersonalColumn(name, typ string) bool

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

func LooksQuasi(name string) bool

LooksQuasi reports a field name that looks like a quasi-identifier (birth date, postal code, gender).

func Mask

func Mask(mode, value string) string

Mask masks the text value in mode.

func MaskText

func MaskText(s string) string

MaskText is the partial mask format: first character + "***" + "(length in characters)". An invalid UTF-8 byte counts as one U+FFFD character.

func MaskValue

func MaskValue(v any, mode string) any

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

func RedactedRef(name string) string

RedactedRef is a redacted value that carries a reference to it, which the console alone resolves (see RefStore).

func Tokens

func Tokens(name string) []string

Tokens splits a name on non-alphanumerics and camelCase, lowered, with accents removed from common Latin letters ("prénom" → "prenom").

func ValidMode

func ValidMode(m string) bool

ValidMode reports whether m is a mask mode.

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.

func Detectors

func Detectors(names []string) ([]Detector, error)

Detectors returns the named detectors, de-duplicated, in their fixed run order. Names: email, phone, iban, card, be_niss, fr_nir, nl_bsn, us_ssn.

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.

func (*RefStore) Begin

func (r *RefStore) Begin() int

Begin opens the next result and returns its number.

func (*RefStore) Evict

func (r *RefStore) Evict()

Evict forgets the oldest result.

func (*RefStore) Get

func (r *RefStore) Get(ref string) (string, bool)

Get resolves a reference.

func (*RefStore) Put

func (r *RefStore) Put(n int, key, value string) string

Put stores value under key in result n and returns its reference, or "" when the key is malformed, the result unknown or the store cannot hold the value.

func (*RefStore) PutDistinct

func (r *RefStore) PutDistinct(n int, value string) string

PutDistinct stores value in result n under the next number, or returns the reference it already has in that result: the same value gets the same reference across the records of one result.

Jump to

Keyboard shortcuts

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