Expand description
Finding and redacting secrets in text a host logs, shows or shares: API keys and tokens by their known shapes, private key blocks, and values assigned to secret-named variables.
A shape matches only where a token starts, so the same letters inside a word or a base64 blob are not a key. A secret with neither a known shape nor a telling name, such as a password in prose, is not found.
use rig_core::redact;
let line = "export ANTHROPIC_API_KEY=sk-ant-api03-abcdefghijklmnopqrstuvwxyz";
assert!(redact::has_secret(line));
assert_eq!(redact::text(line), "export ANTHROPIC_API_KEY=[REDACTED]");
assert_eq!(redact::text("nothing to hide"), "nothing to hide");Structs§
- Secret
Match - A secret
findfound: its kind, and where it is in the text, in bytes.
Enums§
- Kind
- What kind of secret a
SecretMatchis.
Constants§
Functions§
- find
- Every secret in
input, in order and not overlapping. - has_
secret - Whether
inputholds a secret. - json
- Every string in
valueredacted astextredacts it. Object keys are left as they are. - json_
text json, serialized JSON such as a JSON line, with every string in it redacted asjsonredacts a value: object keys are left as they are. Borrowed when it has none, and only a string with an escape in it is decoded to be searched. A string never closed is left as it is.- text
inputwith every secret replaced byREDACTED; borrowed when it has none.- tool_
result resultwith every secret in what its model sees (its text and JSON blocks) redacted astextandjsonredact them;Nonewhen it has none, so a clean result is never copied. A redacted text block is plain text.