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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
//! Structured processors for format-aware sanitization.
//!
//! # Architecture
//!
//! ```text
//! ┌──────────────────┐ ┌───────────────────┐ ┌──────────────────┐
//! │ Input bytes │ ──▶ │ ProcessorRegistry │ ──▶ │ Output bytes │
//! │ (file content) │ │ (profile matching) │ │ (sanitized) │
//! └──────────────────┘ └────────┬───────────┘ └──────────────────┘
//! │
//! ┌────────▼────────┐
//! │ dyn Processor │
//! │ │
//! │ KeyValue │ ← gitlab.rb-style
//! │ JsonProcessor │ ← JSON files
//! │ YamlProcessor │ ← YAML files
//! │ XmlProcessor │ ← XML files
//! │ CsvProcessor │ ← CSV/TSV files
//! └────────┬────────┘
//! │
//! ┌────────▼────────┐
//! │ MappingStore │
//! │ (one-way dedup) │
//! └─────────────────┘
//! ```
//!
//! # File-Type Profiles
//!
//! A [`FileTypeProfile`] specifies which processor to use and what
//! fields/keys to sanitize. Users provide profiles to control which
//! parts of a structured file are replaced. If no profile matches,
//! the caller falls back to the streaming scanner.
//!
//! # Extensibility
//!
//! Implement the [`Processor`] trait and register it with the
//! [`ProcessorRegistry`]. The registry matches profiles to processors
//! by name and dispatches processing.
// Re-export core types.
pub use ;
pub use ProcessorRegistry;
use crateCategory;
use crateResult;
use crateMappingStore;
// ---------------------------------------------------------------------------
// Processor trait
// ---------------------------------------------------------------------------
/// A structured processor that can sanitize a specific file format while
/// preserving its structure and formatting as much as possible.
///
/// Processors are **stateless** — all mutable state lives in the
/// [`MappingStore`] they receive. This makes processors `Send + Sync`
/// and reusable across files.
///
/// # Contract
///
/// - `name()` must return a unique, lowercase identifier (e.g. `"json"`).
/// - `can_handle()` is a fast heuristic check; it may inspect a few
/// bytes or the file extension but should not fully parse.
/// - `process()` performs the full structured sanitization. It should
/// preserve formatting/whitespace where possible and only replace
/// values in fields matched by the profile's [`FieldRule`]s.
/// - Replacements are **one-way** via the `MappingStore` — no reverse
/// mapping is produced.
// ---------------------------------------------------------------------------
// Helpers shared across processors
// ---------------------------------------------------------------------------
/// Replace a value through the mapping store using a field rule's category.
pub
/// Build a dot-separated key path by appending `key` to `prefix`.
///
/// Returns `key` unchanged when `prefix` is empty.
pub
/// Check whether a single glob `pattern` matches `key_path`.
///
/// Supported patterns:
/// - `"*"` — matches anything.
/// - `"password"` — exact match.
/// - `"*.password"` — any key ending in `.password`.
/// - `"db.*"` — any key starting with `db.`.
pub
/// Check whether a dotted key path matches any of the rules in a profile.
///
/// Supports exact matches and simple glob patterns:
/// - `"password"` matches `"password"` exactly.
/// - `"*.password"` matches any key ending in `.password`.
/// - `"db.*"` matches any key starting with `db.`.
pub