masking

package
v0.1.5213 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package masking is Settings → Privacy's masking as the gateway's masker (gwmw.Masker): secrets, personal data and the user's own words go to a vendor as placeholders (internal/redact), and come back as they were. It reads the settings on each call. plugins/redact serves it.

Index

Constants

View Source
const SetKind = "magpie-masking"

SetKind marks a Set's JSON as magpie's masking settings.

Variables

View Source
var ErrNotASet = errors.New("this isn't magpie's masking settings as Copy writes them, so nothing was imported")

ErrNotASet is text that isn't a whole Set as Export writes it.

Functions

func ExportText

func ExportText(st settings.Settings) string

ExportText is st's Set as Copy puts it on the clipboard.

func Fingerprint

func Fingerprint(st settings.Settings) string

Fingerprint names what st has a request masked by: every setting that changes what is masked (the kinds, the user's words and rules, what each kind does, what is let through, the local model and its threshold), as a hash, so two magpies can tell they mask alike without either telling the other its words. "" when st masks nothing.

A magpie that passes a request on to another (a Remote magpie) after masking it says so with this; the other masks it again only when its own fingerprint differs: masked twice by the same settings, the second pass finds nothing the first left, and costs the request another run of the rules and of the local model (YeYaka88 on X). It starts no download.

func Import

func Import(text []byte) error

Import saves the masking settings text holds (ParseSet) in place of this magpie's, the rest of the settings kept, or nothing at all.

func ModelBusy added in v0.1.1566

func ModelBusy() string

ModelBusy says what the local model is doing that a request may wait on, for the error of one that waited too long: "" when nothing.

func ModelOn added in v0.1.1566

func ModelOn() bool

ModelOn says Settings → Privacy's local model masks requests, as the user turned it on: only then is a request held back for a model that fails, and waited for it strictWait (model's strict).

func ModelWanted added in v0.1.1858

func ModelWanted(st settings.Settings) bool

ModelWanted says st has masking ask the local model: the user turned it on, or left it as it is, on by default. One who had a model downloaded, or picked, with it off before it was on by default had turned it off.

func Preview added in v0.1.1317

func Preview(s string) (out string, hits []gwmw.Hit, off bool)

Preview is s as the settings would send it, and what was found in it, with nothing remembered: no placeholder is kept for the replies, and none of its values is masked again later as one seen before. With masking off it is as masking would be turned on (Off says so), so the user can try it first.

func Wanted

func Wanted(st settings.Settings) bool

Wanted says settings st ask for anything to be masked.

func WithForced

func WithForced(ctx context.Context) context.Context

WithForced is ctx for masking a request a gateway key holds to masking (access.RedactOn) whatever the settings say: where they mask nothing it is masked for secrets and personal data by the defaults.

func WithRoute added in v0.1.2125

func WithRoute(ctx context.Context, route string) context.Context

WithRoute is ctx for masking a request that may go only to route (the providers its model, the model's fallbacks or a routing group's members are served by): a text sent on it before goes as it went there (redact.Options.Route).

func WithUnread

func WithUnread(ctx context.Context) (context.Context, func() int)

WithUnread is ctx for masking a request whose texts the local model didn't read in time are counted, and what counts them: the texts the rules masked alone, which a request with the model on is told by (plugins#1749). Nothing about how it is masked changes.

Types

type Masker

type Masker struct{}

Masker masks as the settings say, read on each call.

func (Masker) JSON

func (Masker) JSON(body []byte) ([]byte, int)

func (Masker) JSONHits added in v0.1.1305

func (m Masker) JSONHits(body []byte) ([]byte, []gwmw.Hit)

JSONHits is JSON, with what it masked (gwmw.Teller).

func (Masker) JSONHitsContext added in v0.1.1566

func (Masker) JSONHitsContext(ctx context.Context, body []byte) ([]byte, []gwmw.Hit)

JSONHitsContext is JSONHits, its wait for the model ending with ctx (gwmw.ContextTeller).

func (Masker) Restore

func (Masker) Restore(s string, escaped bool) string

func (Masker) Text

func (Masker) Text(s string) (string, int)

func (Masker) TextHits added in v0.1.1305

func (m Masker) TextHits(s string) (string, []gwmw.Hit)

TextHits is Text, with what it masked.

func (Masker) TextHitsContext added in v0.1.1566

func (Masker) TextHitsContext(ctx context.Context, s string) (string, []gwmw.Hit)

TextHitsContext is TextHits, its wait for the model ending with ctx.

func (Masker) Value added in v0.1.1305

func (Masker) Value(p string) (string, bool)

func (Masker) Writer

func (Masker) Writer(w http.ResponseWriter) (http.ResponseWriter, func())

type Set

type Set struct {
	Kind     string            `json:"kind"`
	Version  int               `json:"version"`
	Secrets  bool              `json:"redact"`
	Shape    bool              `json:"shape"`
	Personal bool              `json:"personal"`
	Kinds    map[string]bool   `json:"kinds"`
	Words    []string          `json:"words"`
	AnyCase  bool              `json:"anyCase"`
	Whole    bool              `json:"whole"`
	Rules    []redact.Rule     `json:"rules"`
	Actions  map[string]string `json:"actions"`
	Allow    []string          `json:"allow"`
	Model    SetModel          `json:"model"`
}

Set is every setting Fingerprint covers, and nothing else: what Settings › Privacy's Copy writes and its Import takes (eachg0 on X: magpies on a LAN that forward through one magpie mask once only when their fingerprints match, and only the words could be copied over; a whole Sync & Backup import brought every other setting with it). Keys, accounts and the rest of the settings are never in it, nor the local models' folder or where masked requests are sent instead, which are this computer's.

func Export

func Export(st settings.Settings) Set

Export is st's masking settings as a Set. The model is the one masking asks under st (on by default counts as on), named as Fingerprint names it, so the magpie importing it asks the same one.

func ParseSet

func ParseSet(b []byte) (Set, error)

ParseSet reads b as a Set, all of it or nothing: every key Export writes must be there and no other, each of its own type, else ErrNotASet. A value magpie refuses (a rule that doesn't compile) is refused when it is saved.

func (Set) Apply

func (s Set) Apply(st *settings.Settings)

Apply puts s in place of st's masking settings and leaves every other setting as it was. The model on is the user's choice, as turning it on in Settings › Privacy is; one not downloaded here yet is downloaded when masking first asks it, as then.

type SetModel

type SetModel struct {
	On     bool               `json:"on"`
	Name   string             `json:"name"`
	Scores map[string]float64 `json:"scores"`
}

SetModel is the local model in a Set: whether masking asks it, which one, and the thresholds the user set.

Jump to

Keyboard shortcuts

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