use super::{ScanContext, ScanPhase};
use crate::protocols::groups::GroupTester;
use crate::{Args, Result};
use async_trait::async_trait;
pub struct GroupsPhase;
impl GroupsPhase {
pub fn new() -> Self {
Self
}
}
impl Default for GroupsPhase {
fn default() -> Self {
Self::new()
}
}
#[async_trait]
impl ScanPhase for GroupsPhase {
fn name(&self) -> &'static str {
"Enumerating Key Exchange Groups"
}
fn should_run(&self, args: &Args) -> bool {
args.scan.show_groups && !args.scan.no_groups
}
async fn execute(&self, context: &mut ScanContext) -> Result<()> {
let tester = GroupTester::new(context.target());
let group_results = tester.enumerate_groups().await?;
context.results.advanced_mut().key_exchange_groups = Some(group_results);
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_groups_phase_should_run() {
let phase = GroupsPhase::new();
let mut args = Args::default();
args.scan.show_groups = true;
assert!(phase.should_run(&args));
let mut args = Args::default();
args.scan.show_groups = true;
args.scan.no_groups = true;
assert!(!phase.should_run(&args));
let args = Args::default();
assert!(!phase.should_run(&args));
let mut args = Args::default();
args.scan.all = true;
assert!(!phase.should_run(&args));
}
#[test]
fn test_groups_phase_name() {
let phase = GroupsPhase::new();
assert_eq!(phase.name(), "Enumerating Key Exchange Groups");
}
}