Skip to content

scanner

scanner

Concrete security scanners — secrets and PII detection.

Classes

SecretScanner

SecretScanner()

Bases: BaseScanner

Detect API keys, tokens, passwords, and other secrets in text.

Source code in src/diapason/security/scanner.py
def __init__(self) -> None:
    try:
        _rust = get_rust_module()
        self._rust_impl = _rust.SecretScanner()
    except (ImportError, AttributeError, RuntimeError):
        # Security must not disappear merely because the optional native
        # accelerator is unavailable.  The Python implementation below is
        # intentionally feature-equivalent, just slower.
        self._rust_impl = None
Methods:
scan
scan(text: str) -> ScanResult

Scan text for secret patterns using Rust or the safe fallback.

Source code in src/diapason/security/scanner.py
def scan(self, text: str) -> ScanResult:
    """Scan *text* for secret patterns using Rust or the safe fallback."""
    if self._rust_impl is not None:
        return scan_result_from_json(self._rust_impl.scan(text))
    return _scan_python(text, self.PATTERNS)
redact
redact(text: str) -> str

Replace secret matches with [REDACTED:{pattern_name}].

Source code in src/diapason/security/scanner.py
def redact(self, text: str) -> str:
    """Replace secret matches with ``[REDACTED:{pattern_name}]``."""
    if self._rust_impl is not None:
        return self._rust_impl.redact(text)
    return _redact_python(text, self.PATTERNS)

PIIScanner

PIIScanner()

Bases: BaseScanner

Detect personally identifiable information in text.

Source code in src/diapason/security/scanner.py
def __init__(self) -> None:
    try:
        _rust = get_rust_module()
        self._rust_impl = _rust.PIIScanner()
    except (ImportError, AttributeError, RuntimeError):
        self._rust_impl = None
Methods:
scan
scan(text: str) -> ScanResult

Scan text for PII patterns using Rust or the safe fallback.

Source code in src/diapason/security/scanner.py
def scan(self, text: str) -> ScanResult:
    """Scan *text* for PII patterns using Rust or the safe fallback."""
    if self._rust_impl is not None:
        return scan_result_from_json(self._rust_impl.scan(text))
    return _scan_python(text, self.PATTERNS)
redact
redact(text: str) -> str

Replace PII matches with [REDACTED:{pattern_name}].

Source code in src/diapason/security/scanner.py
def redact(self, text: str) -> str:
    """Replace PII matches with ``[REDACTED:{pattern_name}]``."""
    if self._rust_impl is not None:
        return self._rust_impl.redact(text)
    return _redact_python(text, self.PATTERNS)

Functions: