Skip to main content

scan_sql_str

Function scan_sql_str 

Source
pub fn scan_sql_str(input: &str, scanner: &Scanner) -> Result<SqlScanResult>
Expand description

Scans SQL dump text and masks PII inside quoted INSERT ... VALUES strings.

ยงExamples

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

struct Email;
impl Recognizer for Email {
    fn id(&self) -> &str { "email_test" }
    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 = scan_sql_str("INSERT INTO users VALUES ('a@test');", &scanner).unwrap();
assert!(result.masked_sql.contains("[EMAIL]"));