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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/// Derives the [`RedactedDebug`](crate::RedactedDebug) trait for a struct.
///
/// This macro generates an implementation that formats the struct similarly to the standard
/// library's [`Debug`](std::fmt::Debug) trait, but produces redacted output based on the provided [`RedactionEngine`](crate::RedactionEngine).
/// All fields implementing [`Classified`](crate::Classified) will be automatically redacted according to the engine's policy.
///
/// Fields can be marked with `#[unredacted]` to exclude them from redaction.
///
/// # Example
///
/// ```
/// use data_privacy::{RedactedDebug, classified, taxonomy};
///
/// #[taxonomy(example)]
/// enum ExampleTaxonomy {
/// Sensitive,
/// }
///
/// #[classified(ExampleTaxonomy::Sensitive)]
/// struct UserId(String);
///
/// #[derive(RedactedDebug)]
/// struct User {
/// id: UserId,
/// #[unredacted]
/// age: u32,
/// }
/// ```
pub use RedactedDebug;
/// Derives the [`RedactedDisplay`](crate::RedactedDisplay) trait for a struct.
///
/// This macro generates an implementation that formats the struct similarly to the standard
/// library's [`Display`](std::fmt::Display) trait, but produces redacted output based on the provided [`RedactionEngine`](crate::RedactionEngine).
/// All fields implementing [`Classified`](crate::Classified) will be automatically redacted according to the engine's policy.
///
/// Fields can be marked with `#[unredacted]` to exclude them from redaction.
///
/// # Example
///
/// ```
/// use data_privacy::{RedactedDisplay, classified, taxonomy};
///
/// #[taxonomy(example)]
/// enum ExampleTaxonomy {
/// Sensitive,
/// }
///
/// #[classified(ExampleTaxonomy::Sensitive)]
/// struct UserId(String);
///
/// #[derive(RedactedDisplay)]
/// struct User {
/// id: UserId,
/// #[unredacted]
/// age: u32,
/// }
/// ```
pub use RedactedDisplay;
/// Implements the [`Classified`](crate::Classified) trait on a newtype or single-field struct.
///
/// This macro is applied to a newtype struct or single-field struct declaration. The struct
/// wraps an inner type that holds sensitive data. The macro generates
/// an implementation of the [`Classified`](crate::Classified), [`Debug`], [`Deref`](core::ops::Deref),
/// [`DerefMut`](core::ops::DerefMut), [`RedactedDebug`](crate::RedactedDebug),
/// and [`RedactedDisplay`](crate::RedactedDisplay) traits.
///
/// # Example
///
/// ```
/// use data_privacy::{classified, taxonomy};
///
/// // Declare a taxonomy
/// #[taxonomy(contoso)]
/// enum ContosoTaxonomy {
/// CustomerContent,
/// CustomerIdentifier,
/// }
///
/// // Declare a classified container
/// #[classified(ContosoTaxonomy::CustomerIdentifier)]
/// struct CustomerId(String);
pub use classified;
/// Generates implementation logic and types to expose a data taxonomy.
///
/// This macro is applied to an enum declaration. Each variant of the enum
/// represents a data class within the taxonomy.
///
/// You provide a taxonomy name as first argument, followed by an optional `serde = false` or `serde = true`
/// argument to control whether serde support is included in the generated taxonomy code.
/// The default value for `serde` is `true`, meaning that serde support is included by default.
///
/// This attribute produces an implementation block for the enum which includes one method for
/// each variant of the enum. These methods each return a [`DataClass`](crate::DataClass) instance representing that data class.
/// In addition, classified data container types are generated for each data class.
///
/// ## Example
///
/// ```ignore
/// use data_privacy::taxonomy;
///
/// #[taxonomy(contoso, serde = false)]
/// enum ContosoTaxonomy {
/// CustomerContent,
/// CustomerIdentifier,
/// OrganizationIdentifier,
/// }
/// ```
pub use taxonomy;