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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
//! Deterministic secret detection and redaction core.
//!
//! This crate is the canonical implementation that every language binding
//! translates to (`decision-adopt-rust-core-monorepo`). It uses `std` but is
//! side-effect free by policy:
//!
//! - no runtime network access,
//! - no filesystem access,
//! - no process-environment lookup,
//! - no telemetry or logging sinks,
//! - no secret storage,
//! - no user interface.
//!
//! The crate-level lints below make the policy visible at compile time, and
//! `scripts/check-rust-workspace.py` rejects dependencies that would breach it.
//! Ranges reported by this crate use UTF-8 byte offsets; each binding converts
//! them to its documented native unit (`decision-define-runtime-bindings`).
//!
//! # Pipeline contract
//!
//! [`run_detector_pipeline`] runs every detector in a [`DetectorRegistry`]
//! in registration order, validates each [`Candidate`], resolves overlapping
//! candidates with the documented precedence (resolved-action severity,
//! specificity, confidence, narrower span, registration order, emission
//! order), and numbers the
//! disjoint survivors by input offset. [`scan`] then evaluates a [`Policy`]
//! once per finding. Identical input and configuration always produce
//! identical findings and ids.
//!
//! Every failure is a [`SecretScanError`] with a fixed code and message and
//! no payload; no public value carries an input fragment or a matched value.
//!
//! [`redact`] then applies [`Finding`] actions to the input in one ordered
//! pass, replacing `redact`/`block` ranges with placeholders from a
//! [`PlaceholderFormatter`] and validating that formatter's output.
//! [`scan_and_redact`] runs both and returns a [`ScanResult`].
//!
//! [`scan`], [`redact`], and [`scan_and_redact`] apply a default
//! [`WholeInputLimits`] before doing any work — [`DEFAULT_MAX_INPUT_BYTES`]
//! and [`DEFAULT_MAX_FINDINGS`] — and fail with
//! [`SecretScanErrorCode::InputLimitExceeded`] or
//! [`SecretScanErrorCode::FindingLimitExceeded`] rather than truncating.
//! [`scan_with_limits`], [`redact_with_limits`], and
//! [`scan_and_redact_with_limits`] accept an explicit [`WholeInputLimits`]
//! instead (`decision-bound-whole-input-operations-by-default`).
//!
//! # Public surface
//!
//! | Concern | API |
//! | --- | --- |
//! | Scan | [`scan`], [`scan_with_limits`], [`run_detector_pipeline`] |
//! | Redact | [`redact`], [`redact_with_limits`], [`MAX_PLACEHOLDER_LENGTH`] |
//! | Scan and redact | [`scan_and_redact`], [`scan_and_redact_with_limits`] |
//! | Golden path | [`sanitize`], [`sanitize_with_profile`] |
//! | Whole-input limits | [`WholeInputLimits`], [`DEFAULT_MAX_INPUT_BYTES`], [`DEFAULT_MAX_FINDINGS`] |
//! | Incremental | [`IncrementalSanitizer`], [`IncrementalLimits`], [`SessionState`], [`IncrementalPolicy`], [`IncrementalPolicyContext`] |
//! | Policy | [`Policy`], [`PolicyContext`], [`DefaultPolicy`], [`Action`] |
//! | Formatter | [`PlaceholderFormatter`], [`PlaceholderContext`], [`default_placeholder_formatter`], [`typed_placeholder_formatter`] |
//! | Finding | [`Finding`], [`DetectedFinding`], [`ByteRange`], [`Confidence`], [`Specificity`], [`Obfuscation`] |
//! | Result | [`ScanResult`], [`IncrementalResult`] |
//! | Sanitized error | [`SecretScanError`], [`SecretScanErrorCode`], [`DetectorFailure`], [`PolicyFailure`], [`FormatterFailure`] |
//! | Custom detectors | [`Detector`], [`Candidate`], [`DetectorContext`], [`DetectorRegistry`], [`RegisteredDetector`] |
//! | Thread-shareable built-in registry | [`BuiltInRegistry`] |
//! | Declarative rulesets | [`load_ruleset`], [`RulesetError`], [`RulesetErrorClass`] |
//! | Declarative action policy | [`load_action_policy`], [`ActionPolicy`], [`ActionPolicyError`], [`ActionPolicyErrorClass`], [`MAX_ACTION_POLICY_BYTES`] |
//! | Explain and compare action policies | [`compare_action_policies`], [`compare_action_policies_with_limits`], [`ComparedPolicy`], [`ActionComparison`], [`ComparedFinding`], [`ActionDecision`], [`DecisionBasis`], [`ComparedSide`], [`PolicyBinding`], [`ActionCounts`], [`DetectionIdentity`], [`MAX_COMPARED_POLICIES`] |
//! | Compare detection configurations | [`compare_configurations`], [`ConfigurationSide`], [`ConfigurationComparison`], [`ConfigurationResult`], [`ConfigurationDifferences`], [`ConfigurationDifference`], [`DifferenceKind`], [`Correspondence`], [`SideStatus`] |
//! | Profiles and PII activation | [`Profile`], [`PiiSelection`] |
//! | Artifact manifest | [`ArtifactManifest`], [`ArtifactKind`], [`ArtifactManifestError`] |
//! | Static custom composition | [`composition`] |
//! | Detector selection | [`DetectionSelection`], [`DetectionConfigError`] |
//! | Effective configuration | [`resolve_config`], [`describe_config`], [`ConfigRequest`], [`ConfigResolution`], [`ConfigSnapshot`], [`ConfigDiagnostic`], [`ConfigSeverity`], [`SampleRuleHits`] |
//! | Identifiers and units | [`is_identifier`], [`MAX_IDENTIFIER_LENGTH`], [`RANGE_UNIT`], [`VERSION`] |
//! | Detector building blocks | [`shannon_entropy`] |
//!
//! That table is the whole surface — it lists every name this crate root
//! exports, and `[workspace.metadata.redact-secret] core-public-api` in the
//! workspace manifest repeats it so a name cannot join or leave without a
//! reviewed manifest change. Everything else is private. In particular, the
//! built-in detector set of each profile is reached only through
//! [`DetectorRegistry::with_built_in`] (`full`) and
//! [`DetectorRegistry::with_common_built_in`] (`common`), and the retention
//! tuning the incremental session depends on is derived through
//! [`IncrementalLimits::minimum_buffered_bytes`] rather than exposed as a
//! constant, so both can change without breaking a caller.
//! `decision-define-detector-profile-and-pack-contract` fixes which built-in
//! detectors each [`Profile`] holds and its compatibility class.
//!
//! # Examples
//!
//! The minimal path redacts with the supported defaults (`full` profile,
//! [`DefaultPolicy`], [`default_placeholder_formatter`], default
//! [`WholeInputLimits`]) in one call:
//!
//! ```
//! let result = redact_secret::sanitize("API_KEY=ghp_SYNTHETICREVOKED00000000000000000000")?;
//! assert_eq!(result.text(), "API_KEY=<SECRET_1>");
//! # Ok::<(), redact_secret::SecretScanError>(())
//! ```
//!
//! Custom detectors, PII activation, a custom policy or formatter, explicit
//! limits, and registry reuse use the advanced path, [`scan_and_redact`]:
//!
//! ```
//! use redact_secret::{
//! DefaultPolicy, DetectorRegistry, default_placeholder_formatter, scan_and_redact,
//! };
//!
//! let registry = DetectorRegistry::with_built_in([])?;
//! let input = "API_KEY=ghp_SYNTHETICREVOKED00000000000000000000\nplain text";
//!
//! let result = scan_and_redact(input, ®istry, &DefaultPolicy, &default_placeholder_formatter)?;
//!
//! assert_eq!(result.text(), "API_KEY=<SECRET_1>\nplain text");
//! // Ranges index the original input, in UTF-8 bytes.
//! let range = result.findings()[0].range();
//! assert_eq!(&input[range.start()..range.end()], "ghp_SYNTHETICREVOKED00000000000000000000");
//! # Ok::<(), redact_secret::SecretScanError>(())
//! ```
//!
//! # Incremental sanitization contract
//!
//! [`IncrementalSanitizer`] runs the same built-in detectors, default
//! policy, and redaction over text supplied in chunks. It is a bounded,
//! four-state session (`accepting`, `finalized`, `aborted`, `failed`) that
//! emits only text whose detection window is closed, never rescans
//! finalized input, and accepts input independently of how a caller
//! partitions it into chunks. See the module documentation for the full
//! contract.
//!
//! The Rust core and the top-level conformance corpus are the canonical source
//! of behavior. Bindings translate host values and range units without
//! reimplementing detection (`decision-govern-cross-language-conformance`).
pub use ;
pub use ;
pub use ;
pub use ;
pub use shannon_entropy;
pub use ;
pub use ;
pub use ;
pub use ;
pub use PiiSelection;
pub use ;
pub use DefaultPolicy;
pub use SampleRuleHits;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
/// The shared product version. Every crate, binding, and package in the
/// workspace reports the same version (`decision-release-bindings-in-lockstep`).
pub const VERSION: &str = env!;
/// The string-index unit used by every range this crate reports.
///
/// Bindings convert to their host unit without changing the selected span:
/// JavaScript uses UTF-16 code units and Python uses Unicode code points.
pub const RANGE_UNIT: &str = "utf8-bytes";