redactkit 0.0.2

Prevent accidental leakage of secrets in Debug, tracing, and serialized output
Documentation

redactkit

Keep secrets out of your logs.

redactkit helps prevent accidental leakage of passwords, tokens, API keys, and other sensitive data into debug output, logs, and serialized data.

Warning

This crate focuses on redaction of output.

It does not provide secure memory erasure.

For secure secret handling, consider using:

Status

This is an early preview.

Current status:

  • Core Redactor
  • Builder API
  • Exact field-name redaction
  • Custom mask support
  • Default redactor
  • Derive macro
  • Regex rules
  • tracing integration
  • serde helpers

Derive

use redactkit::RedactDebug;

#[derive(RedactDebug)]
struct Config {
    username: String,

    #[redact]
    password: String,
}

let config = Config {
    username: "anna".to_string(),
    password: "s3cr3t".to_string(),
};

let debug = format!("{config:?}");

assert!(debug.contains("anna"));
assert!(debug.contains("******"));
assert!(!debug.contains("s3cr3t"));

Builder

use redactkit::Redactor;

let redactor = Redactor::builder()
    .field("password")
    .field("token")
    .build();

assert!(redactor.should_redact_field("password"));
assert!(redactor.should_redact_field("token"));
assert!(!redactor.should_redact_field("username"));

assert_eq!(redactor.redact_field("password", "s3cr3t"), "******");
assert_eq!(redactor.redact_field("username", "anna"), "anna");

Custom mask

use redactkit::Redactor;

let redactor = Redactor::builder()
    .field("password")
    .mask("[REDACTED]")
    .build();

assert_eq!(redactor.redact_field("password", "s3cr3t"), "[REDACTED]");

Default redactor

use redactkit::default_redactor;

let redactor = default_redactor();

assert!(redactor.should_redact_field("password"));
assert!(redactor.should_redact_field("token"));
assert!(redactor.should_redact_field("api_key"));
assert!(!redactor.should_redact_field("username"));

License