#zeroize

macro expunge_derive

A simple crate to expunge, redact and transform struct fields declaratively

6 releases

0.3.4 Jul 3, 2024
0.3.3 Jun 22, 2024
0.3.1 May 5, 2024
0.2.0 Feb 5, 2024
0.1.0 Jan 28, 2024

#8 in #zeroize

Download history 5350/week @ 2024-07-07 5151/week @ 2024-07-14 7251/week @ 2024-07-21 7458/week @ 2024-07-28 6346/week @ 2024-08-04 6315/week @ 2024-08-11 5742/week @ 2024-08-18 7279/week @ 2024-08-25 7109/week @ 2024-09-01 6844/week @ 2024-09-08 6686/week @ 2024-09-15 5800/week @ 2024-09-22 5378/week @ 2024-09-29 1789/week @ 2024-10-06 6099/week @ 2024-10-13 7346/week @ 2024-10-20

20,667 downloads per month
Used in expunge

MIT license

22KB
445 lines

Expunge

A crate for expunging/redacting and transforming sensitive fields.

In action

use expunge::Expunge;
use serde::{Serialize, Deserialize};

#[derive(Clone, Serialize, Deserialize, Expunge)]
struct User {
  #[expunge(skip)] // skipped fields are not transformed
  id: i64,
  #[expunge(as = "Randy".to_string())]
  first_name: String,
  #[expunge(as = "Lahey".to_string())]
  last_name: String,
  #[expunge(with = sha256::digest)]
  date_of_birth: String,
  latitude: f64,
  longitude: f64,
  #[expunge(as = "<expunged>".to_string(), zeroize)]
  password_hash: String,
}

let user = User{
  id: 101,
  first_name: "Ricky".to_string(),
  last_name: "LaFleur".to_string(),
  date_of_birth: "02/02/1960".to_string(),
  latitude: 45.0778,
  longitude: 63.546,
  password_hash: "2f089e52def4cec8b911883fecdd6d8febe9c9f362d15e3e33feb2c12f07ccc1".to_string(),
};

let expunged_user = user.expunge();

let output = serde_json::to_string_pretty(&expunged_user).expect("should serialize");

assert_eq!(r#"{
  "id": 101,
  "first_name": "Randy",
  "last_name": "Lahey",
  "date_of_birth": "eeb98c815ae11240b563892c52c8735472bb8259e9a6477e179a9ea26e7a695a",
  "latitude": 0.0,
  "longitude": 0.0,
  "password_hash": "<expunged>"
}"#,
  output,
)

Contributing

  • Ensure that all tests are passing
    cargo test --all-features
    
  • Open a PR/issue

Dependencies

~0.2–0.8MB
~19K SLoC