Skip to main content

redact_core/
lib.rs

1// Copyright 2026 Censgate LLC.
2// Licensed under the Apache License, Version 2.0. See the LICENSE file
3// in the project root for license information.
4
5//! Redact Core - PII Detection and Anonymization Engine
6//!
7//! A high-performance, Rust-based PII detection and anonymization library
8//! designed as a replacement for Microsoft Presidio.
9//!
10//! # Features
11//!
12//! - **Pattern-based Detection**: Regex-based PII recognizers for structured data
13//! - **NER Support**: Named Entity Recognition using ONNX Runtime (via redact-ner)
14//! - **Multiple Anonymization Strategies**: Replace, mask, hash, encrypt
15//! - **Policy-Aware**: Configurable rules and thresholds
16//! - **Multi-platform**: Server, CLI, and (via `redact-wasm`) WebAssembly
17//! - **High Performance**: Zero-copy where possible, efficient overlap resolution
18//!
19//! # WebAssembly
20//!
21//! For `wasm32-unknown-unknown`, use the **`redact-wasm`** crate as the supported
22//! entry point. It enables the JS RNG backends (`getrandom` / `uuid`) required by
23//! this crate on WASM. Building `redact-core` alone for wasm32 is not supported.
24//!
25//! # Example
26//!
27//! ```no_run
28//! use redact_core::{AnalyzerEngine, AnonymizerConfig, AnonymizationStrategy};
29//!
30//! let mut analyzer = AnalyzerEngine::new();
31//!
32//! let text = "Contact John Doe at john@example.com or 555-1234";
33//! let result = analyzer.analyze(text, None).unwrap();
34//!
35//! println!("Detected {} entities", result.detected_entities.len());
36//!
37//! // Anonymize with replacement strategy
38//! let config = AnonymizerConfig {
39//!     strategy: AnonymizationStrategy::Replace,
40//!     ..Default::default()
41//! };
42//! let anonymized = analyzer.anonymize(text, None, &config).unwrap();
43//! println!("Anonymized: {}", anonymized.text);
44//! ```
45
46pub mod anonymizers;
47pub mod engine;
48pub mod policy;
49pub mod recognizers;
50pub mod trace;
51pub mod types;
52pub mod utf8;
53
54// Re-export commonly used types
55pub use anonymizers::{AnonymizationStrategy, AnonymizerConfig, AnonymizerRegistry};
56pub use engine::AnalyzerEngine;
57pub use recognizers::{evaluate_generic_candidate, Recognizer, RecognizerRegistry};
58pub use trace::{operations_enabled, with_operation_spans};
59pub use types::{
60    AnalysisMetadata, AnalysisResult, AnonymizedResult, EntityType, RecognizerResult, Token,
61};
62pub use utf8::{ceil_char_boundary, floor_char_boundary};
63
64/// Version of the redact-core library
65pub const VERSION: &str = env!("CARGO_PKG_VERSION");
66
67#[cfg(test)]
68mod tests {
69    use super::*;
70
71    #[test]
72    fn test_version() {
73        assert!(!VERSION.is_empty());
74    }
75}