Scanner

Trait Scanner 

Source
pub trait Scanner: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn scan<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        input: &'life1 str,
        vault: &'life2 Vault,
    ) -> Pin<Box<dyn Future<Output = Result<ScanResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;

    // Provided methods
    fn scanner_type(&self) -> ScannerType { ... }
    fn version(&self) -> &str { ... }
    fn description(&self) -> &str { ... }
    fn requires_async(&self) -> bool { ... }
    fn validate_config(&self) -> Result<()> { ... }
}
Expand description

Core scanner trait

All security scanners implement this trait to provide consistent interface.

§London School TDD Design

This trait is designed to be mockable for testing:

  • Pure async interface
  • No internal state mutations
  • Testable with mock vault

§Example

use llm_shield_core::{Scanner, ScanResult, Vault};
use async_trait::async_trait;

struct MyScanner;

#[async_trait]
impl Scanner for MyScanner {
    fn name(&self) -> &str {
        "my_scanner"
    }

    async fn scan(&self, input: &str, vault: &Vault) -> Result<ScanResult> {
        // Implement scanning logic
        Ok(ScanResult::pass(input.to_string()))
    }

    fn scanner_type(&self) -> ScannerType {
        ScannerType::Input
    }
}

Required Methods§

Source

fn name(&self) -> &str

Scanner name for identification

Source

fn scan<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, input: &'life1 str, vault: &'life2 Vault, ) -> Pin<Box<dyn Future<Output = Result<ScanResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Scan input text and return result

§Parameters
  • input: Text to scan
  • vault: State storage for cross-scanner communication
§Returns
  • Ok(ScanResult): Scan completed successfully
  • Err(Error): Scan failed

Provided Methods§

Source

fn scanner_type(&self) -> ScannerType

Type of scanner (input/output/bidirectional)

Source

fn version(&self) -> &str

Scanner version

Source

fn description(&self) -> &str

Scanner description

Source

fn requires_async(&self) -> bool

Whether this scanner requires async execution

Some scanners (e.g., URL checking) must be async. Simple scanners can be sync for better performance.

Source

fn validate_config(&self) -> Result<()>

Validate scanner configuration

Implementors§