Skip to content

secret

Keeping secrets out of logs: a wrapper that never prints its value, redaction, masking and credential detection.

Secret hides a value from Debug and Display; redact and mask clean text you already have; detect and scan recognize well-known token formats (GitHub, AWS, Slack, Stripe, Google, npm, JWT, PEM keys). None of it wipes memory (that needs unsafe code, which this crate forbids).

Cargo feature secret (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features secret

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.6", default-features = false, features = ["secret"] }

Import path: helpers4::secret.

ItemWhat it does
detectRecognizes a well-known credential format: the whole of token must look like one.
maskHides a secret but for its last few characters, such as "****************7890".
REDACTEDThe text shown in place of a redacted secret.
redactReplaces every occurrence of each of secrets in text with [REDACTED].
FindingOne credential found by scan.
scanFinds the well-known credentials in text.
SecretA value that must not leak through logs, error messages or {:?}: printing it shows [REDACTED] instead of the content.
TokenKindA well-known kind of credential, as recognized by detect.