Skip to main content

redaction/
lib.rs

1//! Type-directed redaction for structured data.
2//!
3//! This crate separates:
4//! - **Classification**: what kind of sensitive data this is.
5//! - **Policy**: how that data should be redacted.
6//!
7//! The derive macro walks your data and applies the policy at the boundary when
8//! you call `redact()` or `Redactable::redact()`.
9//!
10//! What this crate does:
11//! - defines classification marker types and the [`Classification`] trait
12//! - defines redaction policies and the `redact` entrypoint
13//! - provides integrations behind feature flags (e.g. `slog`)
14//!
15//! What it does not do:
16//! - perform I/O or logging
17//! - validate your policy choices
18//!
19//! The `Sensitive` derive macro lives in `redaction-derive` and is re-exported when
20//! the `derive` feature is enabled.
21
22// <https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html>
23#![warn(
24    anonymous_parameters,
25    bare_trait_objects,
26    elided_lifetimes_in_paths,
27    missing_copy_implementations,
28    rust_2018_idioms,
29    trivial_casts,
30    trivial_numeric_casts,
31    unreachable_pub,
32    unsafe_code,
33    unused_extern_crates,
34    unused_import_braces
35)]
36// <https://rust-lang.github.io/rust-clippy/stable>
37#![warn(
38    clippy::all,
39    clippy::cargo,
40    clippy::dbg_macro,
41    clippy::float_cmp_const,
42    clippy::get_unwrap,
43    clippy::mem_forget,
44    clippy::nursery,
45    clippy::pedantic,
46    clippy::todo,
47    clippy::unwrap_used,
48    clippy::uninlined_format_args
49)]
50// Allow some clippy lints
51#![allow(
52    clippy::default_trait_access,
53    clippy::doc_markdown,
54    clippy::if_not_else,
55    clippy::module_name_repetitions,
56    clippy::multiple_crate_versions,
57    clippy::must_use_candidate,
58    clippy::needless_pass_by_value,
59    clippy::needless_ifs,
60    clippy::use_self,
61    clippy::cargo_common_metadata,
62    clippy::missing_errors_doc,
63    clippy::enum_glob_use,
64    clippy::struct_excessive_bools,
65    clippy::missing_const_for_fn,
66    clippy::redundant_pub_crate,
67    clippy::result_large_err,
68    clippy::future_not_send,
69    clippy::option_if_let_else,
70    clippy::from_over_into,
71    clippy::manual_inspect
72)]
73// Allow some lints while testing
74#![cfg_attr(test, allow(clippy::non_ascii_literal, clippy::unwrap_used))]
75
76pub use redaction_derive::{Sensitive, SensitiveError};
77
78#[allow(unused_extern_crates)]
79extern crate self as redact;
80
81// Module declarations
82#[cfg(feature = "classification")]
83mod classification;
84#[cfg(feature = "policy")]
85mod redaction;
86#[cfg(feature = "slog")]
87pub mod slog;
88
89// Re-exports
90#[cfg(feature = "classification")]
91pub use classification::{
92    AccountId, BlockchainAddress, Classification, CreditCard, DateOfBirth, Email, IpAddress,
93    NationalId, PhoneNumber, Pii, Secret, SessionId, Token,
94};
95#[cfg(feature = "policy")]
96pub use redaction::{
97    apply_classification, redact, KeepConfig, MaskConfig, Redactable, RedactionPolicy,
98    ScalarRedaction, SensitiveValue, TextRedactionPolicy, REDACTED_PLACEHOLDER,
99};
100#[doc(hidden)]
101#[cfg(feature = "policy")]
102pub use redaction::{Classifiable, RedactionMapper, SensitiveType};