8 releases

0.2.0 Oct 30, 2024
0.1.7 Nov 20, 2023
0.1.6 May 4, 2023
0.1.5 Dec 22, 2022
0.1.0 Sep 14, 2022

#97 in Debugging

Download history 6014/week @ 2024-08-16 6422/week @ 2024-08-23 5445/week @ 2024-08-30 5685/week @ 2024-09-06 5660/week @ 2024-09-13 5102/week @ 2024-09-20 5498/week @ 2024-09-27 6865/week @ 2024-10-04 4822/week @ 2024-10-11 4180/week @ 2024-10-18 5778/week @ 2024-10-25 6066/week @ 2024-11-01 6665/week @ 2024-11-08 7214/week @ 2024-11-15 18423/week @ 2024-11-22 6545/week @ 2024-11-29

40,362 downloads per month
Used in 2 crates

MIT/Apache

40KB
496 lines

crates.io Documentation License CI status

A derive macro that implements std::fmt::Debug for a struct or enum variant, with certain fields redacted.

The purpose of this macro is to allow for easy, configurable and efficient redaction of sensitive data in structs and enum variants. This can be used to hide sensitive data in logs or anywhere where personal data should not be exposed or stored.

Usage

Add to your Cargo.toml:

[dependencies]
veil = "0.2.0"

Usage documentation can be found here.

Example

The example is explained in detail here.

#[derive(Redact)]
struct CreditCard {
    #[redact(partial)]
    number: String,

    #[redact]
    expiry: String,

    #[redact(fixed = 3)]
    cvv: String,

    #[redact(partial)]
    cardholder_name: String,
}

#[derive(Redact)]
#[redact(all, variant)]
enum CreditCardIssuer {
    MasterCard,
    Visa,
    AmericanExpress,
}

#[derive(Redact)]
#[redact(all, partial)]
struct Vehicle {
    license_plate: String,
    make: String,
    model: String,
    color: String,
}

#[derive(Debug)]
struct Policy {
    id: Uuid,
    name: String,
    description: String,
}

#[derive(Redact)]
enum InsuranceStatus {
    #[redact(all, partial)]
    Insured {
        #[redact(fixed = 12)]
        policy: Policy,

        policy_started: String,
        policy_expires: String,

        #[redact(skip)]
        payment_card: CreditCard,

        #[redact(skip)]
        vehicles: Vec<Vehicle>,
    },

    Uninsured {
        policies_available: Vec<Policy>,
    },
}

Environmental Awareness

In testing environments it may be useful to disable redaction entirely. You can globally disable Veil's redaction behavior at runtime by enabling the non-default feature flag toggle and:

  • Setting the VEIL_DISABLE_REDACTION environment variable to "1", "true" or "on" (case insensitive).

OR

These are only checked ONCE for security purposes.

Dependencies

~280–760KB
~17K SLoC