Skip to main content

aha_misc/tavern/
option.rs

1//! Some options
2
3use std::path::PathBuf;
4
5use clap::Args;
6
7/// Network protocol types supported by the client.
8#[derive(Debug, Clone, Copy)]
9pub enum Protocol {
10    /// TCP protocol
11    Tcp,
12    /// UDP protocol
13    Udp,
14}
15
16/// Options for configuring network client fuzzing.
17///
18/// This struct defines parameters needed for fuzzing network clients,
19/// including protocol type, host, port, and timing configurations.
20#[derive(Args, Debug)]
21pub struct NetworkClientOptions {
22    /// Network protocol (tcp/udp)
23    #[arg(long, default_value = "tcp")]
24    pub protocol: String,
25
26    /// Target host
27    #[arg(long, default_value = "127.0.0.1")]
28    pub host: String,
29
30    /// Target port
31    #[arg(long, default_value = "13337")]
32    pub port: u16,
33
34    /// Sleep time in microseconds
35    #[arg(long, default_value = "100000")]
36    pub sleep: u64,
37
38    /// Restart try time if connection fails
39    #[arg(long, default_value = "10")]
40    pub try_time: u64,
41}
42
43impl NetworkClientOptions {
44    /// Get the protocol enum from the string configuration.
45    ///
46    /// # Returns
47    /// A `Protocol` enum value corresponding to the configured protocol string.
48    ///
49    /// # Panics
50    /// Panics if an invalid protocol is specified.
51    pub fn protocol(&self) -> Protocol {
52        match self.protocol.as_str() {
53            "tcp" => Protocol::Tcp,
54            "udp" => Protocol::Udp,
55            _ => panic!("Invalid protocol specified"),
56        }
57    }
58
59    /// Get target address as a string.
60    pub fn address(&self) -> String {
61        format!("{}:{}", self.host, self.port)
62    }
63}
64
65/// SSL configuration options.
66///
67/// This struct defines the parameters needed for SSL connections,
68/// including certificate and key file paths.
69#[derive(Args, Debug)]
70pub struct SSLOptions {
71    /// SSL cert file
72    #[arg(long = "cert-file")]
73    pub cert_file: Option<PathBuf>,
74
75    /// SSL key file
76    #[arg(long = "key-file")]
77    pub key_file: Option<PathBuf>,
78}
79
80impl SSLOptions {
81    /// 
82    pub fn cert_file(&self) -> Option<String> {
83        self.cert_file
84            .clone()
85            .map(|p| p.to_str().unwrap().to_string())
86    }
87
88    /// 
89    pub fn key_file(&self) -> Option<String> {
90        self.key_file
91            .clone()
92            .map(|p| p.to_str().unwrap().to_string())
93    }
94}