Skip to main content

Crate cloakrs_core

Crate cloakrs_core 

Source
Expand description

Core types and scanning primitives for cloakrs.

cloakrs-core contains the public data model, recognizer trait, registry, scanner, and masking strategy implementations shared by the rest of the workspace.

§Examples

use cloakrs_core::{Confidence, EntityType, Locale, PiiEntity, Recognizer, Scanner, Span};

struct Email;
impl Recognizer for Email {
    fn id(&self) -> &str { "email_example_v1" }
    fn entity_type(&self) -> EntityType { EntityType::Email }
    fn supported_locales(&self) -> &[Locale] { &[] }
    fn scan(&self, text: &str) -> Vec<PiiEntity> {
        text.find('@').map(|_| PiiEntity {
            entity_type: EntityType::Email,
            span: Span::new(0, text.len()),
            text: text.to_string(),
            confidence: Confidence::new(0.9).unwrap(),
            recognizer_id: self.id().to_string(),
        }).into_iter().collect()
    }
}

let scanner = Scanner::builder().recognizer(Email).build().unwrap();
let result = scanner.scan("jane@example.com").unwrap();
assert_eq!(result.masked_text.as_deref(), Some("[EMAIL]"));

Structs§

Confidence
Confidence score wrapper guaranteed to contain a value from 0.0 to 1.0.
ContextConfig
Configuration for context-aware confidence scoring.
ContextScore
Result of context scoring.
ContextWindow
Words surrounding a candidate match.
PiiEntity
A detected PII entity within text.
RecognizerRegistry
Registry that holds active recognizers.
ScanResult
Result of scanning text.
ScanStats
Statistics about a scan.
Scanner
The main scanner that ties detection and masking together.
ScannerBuilder
Builder for configuring a Scanner.
Span
Byte offset range in source text, using [start, end).

Enums§

CloakError
Errors produced by cloakrs core APIs.
EntityType
All supported PII entity types.
Locale
Locale selector used to choose locale-specific recognizers.
MaskStrategy
How detected PII should be masked.

Traits§

Recognizer
A recognizer that can detect a specific type of PII.

Functions§

apply_mask
Applies a masking strategy to text using the supplied findings.
context_score
Computes a bounded context confidence adjustment.
decrypt_masked_value
Decrypts a value produced by MaskStrategy::Encrypt.
surrounding_context
Extracts lowercased words before and after a candidate span.

Type Aliases§

Result
Convenient result alias for cloakrs operations.