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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
use crateDataClass;
/// Represents a container that holds classified state.
///
/// Types that implement this trait are containers of classified data. They hide an
/// instance they are given to ensure it is handled carefully throughout the application.
/// Although instances are encapsulated, it's possible to extract the instances when
/// classification is no longer needed.
///
/// You rarely implement this trait by hand, instead use the [`classified`](data_privacy_macros::classified) macro to generate
/// classified types automatically.
///
/// # Ancillary Traits
///
/// Types that implement the [`Classified`] trait should generally also implement the [`RedactedDebug`](crate::RedactedDebug),
/// [`RedactedDisplay`](crate::RedactedDisplay), and [`RedactedToString`](crate::RedactedToString) traits. These traits ensure
/// that when classified data is logged or printed, the sensitive information is redacted according to the configured
/// redaction policies.
///
/// Types that implement the [`Classified`] trait should generally not implement the [`Display`](core::fmt::Display) trait, and if they implement
/// the [`Debug`] trait, the implementation should avoid exposing the classified payload.
///
/// # Example
///
/// ```rust
/// use data_privacy::{Classified, DataClass};
///
/// #[derive(Debug)]
/// struct Person {
/// name: String,
/// address: String,
/// }
///
/// impl Person {
/// fn new(name: String, address: String) -> Self {
/// Self { name, address }
/// }
/// }
///
/// // A classified wrapper is usually a newtype around the payload.
/// #[derive(Debug)]
/// struct ClassifiedPerson(Person);
///
/// impl ClassifiedPerson {
/// pub fn new(person: Person) -> Self {
/// Self(person)
/// }
/// }
///
/// impl Classified for ClassifiedPerson {
/// fn data_class(&self) -> &DataClass {
/// static DATA_CLASS: DataClass = DataClass::new("example_taxonomy", "classified_person");
/// &DATA_CLASS
/// }
/// }
///
/// let person = Person::new("John Doe".to_string(), "123 Main St".to_string());
/// let classified = ClassifiedPerson::new(person);
/// assert_eq!(classified.data_class().taxonomy(), "example_taxonomy");
/// assert_eq!(classified.data_class().name(), "classified_person");
/// ```