1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//! # redactkit
//!
//! Small toolkit for redacting sensitive data in debug output and tracing logs.
//!
//! > **Warning:** `redactkit` redacts formatted output only.
//! > It does not modify or erase original field values in memory.
//!
//! ## Features
//!
//! | Feature | Default | Description |
//! | --- | --- | --- |
//! | `std` | yes | Standard library support. |
//! | `derive` | yes | Enables the `RedactDebug` derive macro. |
//! | `regex` | no | Enables regex-based field and value rules. |
//! | `tracing` | no | Enables `tracing-subscriber` field redaction. |
//!
//! ## Derive example
//!
//! ```
//! # #[cfg(feature = "derive")]
//! # {
//! use redactkit::RedactDebug;
//!
//! #[derive(RedactDebug)]
//! struct User {
//! username: String,
//! #[redact]
//! password: String,
//! }
//!
//! let user = User {
//! username: "anna".to_string(),
//! password: "s3cr3t".to_string(),
//! };
//!
//! assert_eq!(
//! format!("{user:?}"),
//! "User { username: \"anna\", password: \"******\" }"
//! );
//! # }
//! ```
//!
//! ## Builder example
//!
//! ```
//! use redactkit::Redactor;
//!
//! let redactor = Redactor::builder()
//! .field("password")
//! .field("token")
//! .mask("[hidden]")
//! .build();
//!
//! assert_eq!(redactor.redact_field("password", "secret"), "[hidden]");
//! assert_eq!(redactor.redact_field("username", "anna"), "anna");
//! ```
//!
//! ## Default redactor
//!
//! ```
//! let redactor = redactkit::default_redactor();
//!
//! assert_eq!(redactor.redact_field("password", "secret"), "******");
//! assert_eq!(redactor.redact_field("api_key", "abc123"), "******");
//! ```
//!
//! ## Regex rules
//!
//! ```
//! # #[cfg(feature = "regex")]
//! # {
//! use redactkit::Redactor;
//!
//! let redactor = Redactor::builder()
//! .field_pattern("(?i)token|secret")
//! .unwrap()
//! .value_pattern(r"\d{4}", "****")
//! .unwrap()
//! .build();
//!
//! assert_eq!(redactor.redact_field("api_token", "abcd"), "******");
//! assert_eq!(redactor.redact_field("note", "card 1234"), "card ****");
//! # }
//! ```
//!
//! ## Tracing integration
//!
//! ```
//! # #[cfg(feature = "tracing")]
//! # {
//! use tracing_subscriber::fmt;
//!
//! fmt()
//! .fmt_fields(redactkit::tracing::redact_fields())
//! .init();
//! # }
//! ```
/// Derives `Serialize` for structs, redacting fields marked with `#[redact]`.
///
/// This derive generates a `serde::Serialize` implementation that replaces
/// redacted fields with a mask string during serialization.
///
/// The original values in memory are not modified.
///
/// # Examples
///
/// ```
/// use redactkit::RedactSerialize;
///
/// #[derive(RedactSerialize)]
/// struct Config {
/// username: String,
/// #[redact]
/// password: String,
/// }
///
/// let config = Config {
/// username: "anna".to_string(),
/// password: "s3cr3t".to_string(),
/// };
///
/// let json = serde_json::to_string(&config).expect("serialization should succeed");
///
/// assert_eq!(json, r#"{"username":"anna","password":"******"}"#);
/// ```
pub use RedactSerialize;
pub use RedactorBuilder;
pub use Error;
pub use ;
pub use RedactDebug;