Skip to main content

Module redact

Module redact 

Source
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§

SecretMatch
A secret find found: its kind, and where it is in the text, in bytes.

Enums§

Kind
What kind of secret a SecretMatch is.

Constants§

REDACTED
What text and json put in place of a secret.

Functions§

find
Every secret in input, in order and not overlapping.
has_secret
Whether input holds a secret.
json
Every string in value redacted as text redacts it. Object keys are left as they are.
json_text
json, serialized JSON such as a JSON line, with every string in it redacted as json redacts 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
input with every secret replaced by REDACTED; borrowed when it has none.
tool_result
result with every secret in what its model sees (its text and JSON blocks) redacted as text and json redact them; None when it has none, so a clean result is never copied. A redacted text block is plain text.