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
// Safe serialization helpers for secret-bearing structs.
//
// Re-exports the `redact` serializer function and the `RedactedField` marker type.
use Serializer;
/// Serializes any field as the literal string `"[REDACTED]"`.
///
/// Intended for use with `#[serde(serialize_with = "secure_data::serde::redact")]`.
///
/// # Examples
///
/// ```
/// #[derive(serde::Serialize)]
/// struct MyStruct {
/// #[serde(serialize_with = "secure_data::serde::redact")]
/// secret: String,
/// }
///
/// let s = MyStruct { secret: "hunter2".into() };
/// let json = serde_json::to_string(&s).unwrap();
/// assert!(json.contains("REDACTED"));
/// assert!(!json.contains("hunter2"));
/// ```
///
/// # Errors
/// Propagates serializer errors from the underlying format.
/// A zero-size marker type whose [`serde::Serialize`] impl always emits `"[REDACTED]"`.
///
/// Useful as a field type when the actual secret is stored elsewhere.
///
/// # Examples
///
/// ```
/// use secure_data::serde::RedactedField;
///
/// let field = RedactedField;
/// let json = serde_json::to_string(&field).unwrap();
/// assert_eq!(json, r#""[REDACTED]""#);
/// ```
;