use async_trait::async_trait;
use tokio::sync::mpsc::UnboundedSender;
use crate::{Config, Finding, Target};
pub struct ScanInput {
pub seed: String,
pub targets: Vec<Target>,
pub live_tx: Option<UnboundedSender<Finding>>,
pub target_tx: Option<UnboundedSender<Target>>,
}
impl ScanInput {
pub fn emit(&self, f: Finding) {
if let Some(tx) = &self.live_tx {
let _ = tx.send(f);
}
}
pub fn emit_target(&self, t: Target) {
if let Some(tx) = &self.target_tx {
let _ = tx.send(t);
}
}
}
pub struct ScanOutput {
pub findings: Vec<Finding>,
pub targets: Vec<Target>,
}
impl ScanOutput {
pub fn empty() -> Self {
Self {
findings: Vec::new(),
targets: Vec::new(),
}
}
}
#[async_trait]
pub trait Scanner: Send + Sync {
fn name(&self) -> &'static str;
fn tags(&self) -> &[&'static str];
fn accepts(&self, target: &Target) -> bool;
async fn run(&self, input: ScanInput, config: &Config) -> anyhow::Result<ScanOutput>;
}