use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum SecurityLevel {
Classical,
PostQuantum,
TrueVernam,
}
impl Default for SecurityLevel {
fn default() -> Self {
SecurityLevel::PostQuantum
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConnectionConfig {
pub security: SecurityLevel,
pub timeout: std::time::Duration,
pub buffer_size: usize,
pub enable_scrambling: bool,
pub enable_anti_replay: bool,
pub enable_compression: bool,
pub max_message_size: usize,
}
impl Default for ConnectionConfig {
fn default() -> Self {
Self {
security: SecurityLevel::default(),
timeout: std::time::Duration::from_secs(30),
buffer_size: 64 * 1024, enable_scrambling: true,
enable_anti_replay: true,
enable_compression: false,
max_message_size: 16 * 1024 * 1024, }
}
}
impl ConnectionConfig {
pub fn post_quantum() -> Self {
Self {
security: SecurityLevel::PostQuantum,
..Default::default()
}
}
pub fn classical() -> Self {
Self {
security: SecurityLevel::Classical,
..Default::default()
}
}
pub fn true_vernam() -> Self {
Self {
security: SecurityLevel::TrueVernam,
..Default::default()
}
}
pub fn with_buffer_size(mut self, size: usize) -> Self {
self.buffer_size = size;
self
}
pub fn with_timeout(mut self, timeout: std::time::Duration) -> Self {
self.timeout = timeout;
self
}
pub fn with_scrambling(mut self, enable: bool) -> Self {
self.enable_scrambling = enable;
self
}
pub fn with_anti_replay(mut self, enable: bool) -> Self {
self.enable_anti_replay = enable;
self
}
pub fn with_compression(mut self, enable: bool) -> Self {
self.enable_compression = enable;
self
}
pub fn with_max_message_size(mut self, size: usize) -> Self {
self.max_message_size = size;
self
}
}