Giter Club home page Giter Club logo

veil's Introduction

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.

veil's People

Contributors

cottinisimone avatar cpiemontese avatar danielefongo avatar dependabot[bot] avatar francesco995 avatar maeisbad avatar nick-schafhauser avatar oleksandr-gubchenko avatar williamvenner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

veil's Issues

extending #[redact(with = 'X')] to support Strings

currently the #[redact(with = 'X')] attribute is limited in that you can only specify one single character that the string will be redacted with.

What do we think about enhancing this attribute so that it can support Strings instead of just chars?

Here is an example of what I am proposing:

#[derive(Redact)]
struct Foo {
    #[redact(with = "[REDACTED]")]
    redact_me: String,
}

fn main() {
    println!(
        "{:#?}",
        Foo {
            redact_me: "Super Secret String".to_string(),
        }
    );
}

// Running main would print the following:
Foo {
    redact_me: "[REDACTED]",
}

Now I am not sure how this would play nicely with the partial or fixed attributes, so perhaps reusing the with attribute to support a String or Char isn't the way to go.
One thought I had was to add another attribute, perhaps #[redact(with_string = "[REDACTED]")] that would be mutually exclusive with partial or fixed

Would love to hear what others think about this sort of thing

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.