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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//! # CleanSH Core Library
//!
//! `cleansh-core` provides the fundamental, platform-independent logic for data sanitization
//! and redaction. It defines the core data structures for redaction rules, provides mechanisms
//! for compiling these rules, and implements a pluggable `SanitizationEngine` trait for
//! applying redaction logic.
//!
//! The library is designed to be pure and stateless, focusing solely on the transformation
//! of input data based on defined rules, without concerns for I/O or application-specific
//! state management.
//!
//! ## Modules
//!
//! * `config`: Defines `RedactionRule`s and `RedactionConfig` for specifying sensitive patterns.
//! * `sanitizers`: Contains engine-specific logic for compiling rules, such as `regex_sanitizer`.
//! * `validators`: Provides programmatic validation for specific data types.
//! * `redaction_match`: Defines data structures for detailed reporting of redaction events.
//! * `engine`: Defines the `SanitizationEngine` trait, enabling a modular design.
//! * `profiles`: Defines data structures for user-specified profiles and post-processing.
//! * `audit_log`: Defines the structure and logic for writing redaction events to a log file.
//! * `engines`: Contains concrete implementations of the `SanitizationEngine` trait.
//! * `headless`: Convenience wrappers for using core engines in a non-interactive mode.
//!
//! ## Public API
//!
//! The public API provides a cohesive set of types and functions for configuring and running
//! a sanitization engine. Key components are organized by functionality:
//!
//! **Configuration & Rules**
//!
//! * [`RedactionConfig`]: Manages collections of `RedactionRule`s, including loading, merging, and filtering.
//! * [`RedactionRule`]: Defines a single rule for identifying and replacing sensitive patterns.
//! * [`merge_rules`]: Merges default and user-defined configurations.
//! * [`RedactionConfig::load_from_file`]: Loads rules from a YAML file.
//! * [`RedactionConfig::load_default_rules`]: Loads the built-in set of default rules.
//!
//! **Sanitization Engine**
//!
//! * [`SanitizationEngine`]: A trait for pluggable sanitization methods.
//! * [`RegexEngine`]: The concrete implementation of `SanitizationEngine` that uses regular expressions.
//!
//! **Headless Mode**
//!
//! * [`headless_sanitize_string`]: A convenience function for a full, one-shot sanitization.
//!
//! **Redaction Reporting**
//!
//! * [`RedactionMatch`]: A detailed record of a single matched and redacted item, including its location.
//! * [`RedactionSummaryItem`]: A summary of all matches for a specific rule.
//!
//! **Audit Logging**
//!
//! * [`AuditLog`]: Provides a high-level API for creating and writing structured redaction logs.
//!
//! ## Usage Example
//!
//! ```rust
//! use cleansh_core::{RedactionConfig, headless_sanitize_string, EngineOptions};
//! use anyhow::Result;
//!
//! fn main() -> Result<()> {
//! // 1. Load default redaction rules.
//! let default_config = RedactionConfig::load_default_rules()?;
//!
//! // 2. Prepare some content to sanitize.
//! let input = "My email is test@example.com and my SSN is 123-45-6789. Another email: user@domain.org.";
//! println!("\nOriginal Input:\n{}", input);
//!
//! // 3. Configure engine options.
//! let options = EngineOptions::default();
//! let source_id = "test_document.txt";
//!
//! // 4. Sanitize the content in a single, headless function call.
//! let sanitized_output = headless_sanitize_string(
//! default_config,
//! options,
//! input,
//! source_id,
//! )?;
//! println!("\nSanitized Output:\n{}", sanitized_output);
//!
//! Ok(())
//! }
//! ```
//!
//! ## Error Handling
//!
//! The library uses `anyhow::Error` for fallible operations and defines specific error
//! types like `RuleConfigNotFoundError` for clearer error reporting.
//!
//! ## Design Principles
//!
//! * **Pluggable Architecture:** The `SanitizationEngine` trait allows for different
//! sanitization methods (e.g., regex, entropy) to be swapped out seamlessly.
//! * **Stateless:** The core library does not maintain application state.
//! * **Testable:** Logic is easily unit-testable in isolation.
//! * **Extensible:** The design supports adding new rule types or engines with minimal
//! changes to the core application logic.
//!
//! ---
//! License: BUSL-1.1
// All modules must be declared before they can be used.
// Correctly re-exporting modules and types from their canonical locations.
// This ensures the public API is clean and well-defined.
/// Re-exports the public configuration types and functions for managing redaction rules.
pub use ;
/// Re-exports the custom error type for clear error reporting.
pub use CleanshError;
/// Re-exports types related to the core sanitization engine trait.
pub use SanitizationEngine;
/// Re-exports the concrete `RegexEngine` and `EntropyEngine` implementations from their respective locations.
pub use RegexEngine;
pub use EntropyEngine;
/// Re-exports types for detailed redaction matches and sensitive data reporting.
pub use ;
/// Re-exports types related to profile configuration, which allows for custom
/// redaction behavior and reporting.
pub use ;
/// Re-exports the AuditLog type for handling redaction event logging.
pub use AuditLog;
/// Re-exports types and functions for one-shot, non-interactive use.
pub use headless_sanitize_string;
// Re-export key types from the sanitizers::compiler module for advanced usage.
// This is the correct path for `CompiledRule` and `CompiledRules`.
pub use ;