Crate redactrs

Source
Expand description

Wrapper for sensitive data that you want to avoid being leaked by accidentally printing/logging/etc. them.

How the data is redacted is defined by the Redactor. A Redactor is a struct that implements the Redactor-trait.

§Usage

In it’s most basic form, Redacted is used like this:

let x: Redacted<&str> = "sensitive".into();

assert_eq!(x.to_string(), "<redacted>");

This will by default use the Simple-Redactor. If desired, it can be swapped with the Custom-Redactor.

let x: Redacted<&str, Custom<'X', 5>> = "sensitive".into();

assert_eq!(x.to_string(), "XXXXX");

To get back the wrapped type use:

  • .into_inner() which consumes the Redacted and returns the wrapped type.
  • .inner() to get a reference of the wrapped type.
  • .inner_mut() to get a mutable reference of the wrapped tyepe.

NOTE: a Redacted is always constructed via the From/Into trait.

§Serde support

By default Redacted types will serialize into their redacted representation. If you don’t want this, and rather serialize normally you can annotate the redacted field with this attribute: #[serde(serialize_with = "no_redact")]

use redactrs::Redacted;
use serde::Serialize;
use redactrs::serde::no_redact;
#[derive(Serialize)]
struct MyData {
    #[serde(serialize_with = "no_redact" )]
    a: Redacted<i32>,
}
let data = MyData {
    a: 42.into(),
};
let json = serde_json::to_string(&data).expect("Test case");
assert_eq!(json, r#"{"a":42}"#);

§Feature flags

  • serde: Enables serde support.
  • zeroize: Enables zeroize support.

Modules§

redactors
Contains ready to use Redactors
serde
Module with serde related functionality.
zeroize
Module with zeroize Trait impls.

Structs§

Redacted
Struct used to wrap sensitive content that should not be printed/logged. The redaction behaviour is defined by Redactor.

Traits§

Redactor
A Trait to define how a value should be redacted.