7 releases

0.1.7 Nov 20, 2023
0.1.6 May 4, 2023
0.1.5 Dec 22, 2022
0.1.4 Nov 16, 2022
0.1.0 Sep 28, 2022

#1501 in Procedural macros

Download history 4192/week @ 2024-01-03 2419/week @ 2024-01-10 2888/week @ 2024-01-17 3508/week @ 2024-01-24 4270/week @ 2024-01-31 3992/week @ 2024-02-07 4467/week @ 2024-02-14 4186/week @ 2024-02-21 4249/week @ 2024-02-28 5388/week @ 2024-03-06 5445/week @ 2024-03-13 5022/week @ 2024-03-20 4621/week @ 2024-03-27 3588/week @ 2024-04-03 5537/week @ 2024-04-10 3721/week @ 2024-04-17

18,262 downloads per month
Used in 2 crates (via veil)

MIT/Apache

40KB
773 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.1.7"

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

~330–780KB
~19K SLoC