pub use crate::transport::scheduler::Scheduler;
pub use crate::transport::session::{CryptoState, Session};
pub use crate::transport::stream::Stream;
pub use crate::transport::types::{LegType, PacketFlags, PacketHeader, SchedulerMode, SessionId};
pub use crate::transport::handshake::{
ClientHello, HandshakeClient, HandshakeError, HandshakeServer, ServerHello,
};
pub use crate::crypto::hybrid_kem::{HybridCiphertext, HybridKeyPackage, HybridSecretKey};
pub use crate::crypto::hybrid_sign::{
HybridSignError, HybridSignature, HybridSigningKey, HybridVerifyingKey,
};
#[derive(Debug, Clone)]
pub struct TransportConfig {
pub pqc_enabled: bool,
pub scheduler_mode: SchedulerMode,
pub max_packet_size: usize,
pub stealth_mode: bool,
}
impl Default for TransportConfig {
fn default() -> Self {
Self {
pqc_enabled: true,
scheduler_mode: SchedulerMode::LowLatency,
max_packet_size: 1400,
stealth_mode: false,
}
}
}
impl TransportConfig {
pub fn low_latency() -> Self {
Self {
scheduler_mode: SchedulerMode::LowLatency,
..Default::default()
}
}
pub fn high_throughput() -> Self {
Self {
scheduler_mode: SchedulerMode::HighThroughput,
..Default::default()
}
}
pub fn stealth() -> Self {
Self {
stealth_mode: true,
scheduler_mode: SchedulerMode::Stealth,
..Default::default()
}
}
}
pub struct PhantomBuilder {
config: TransportConfig,
server_key: Option<HybridVerifyingKey>,
}
impl PhantomBuilder {
pub fn new() -> Self {
Self {
config: TransportConfig::default(),
server_key: None,
}
}
pub fn config(mut self, config: TransportConfig) -> Self {
self.config = config;
self
}
pub fn pin_server_key(mut self, key: HybridVerifyingKey) -> Self {
self.server_key = Some(key);
self
}
pub fn server_key(&self) -> Option<&HybridVerifyingKey> {
self.server_key.as_ref()
}
pub fn get_config(&self) -> &TransportConfig {
&self.config
}
pub fn create_client_handshake(
&self,
) -> Result<HandshakeClient, crate::transport::handshake::HandshakeError> {
HandshakeClient::new()
}
pub fn create_server_handshake(
) -> Result<HandshakeServer, crate::transport::handshake::HandshakeError> {
HandshakeServer::new()
}
}
impl Default for PhantomBuilder {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_config_presets() {
let low_lat = TransportConfig::low_latency();
assert!(matches!(low_lat.scheduler_mode, SchedulerMode::LowLatency));
let high_throughput = TransportConfig::high_throughput();
assert!(matches!(
high_throughput.scheduler_mode,
SchedulerMode::HighThroughput
));
let stealth = TransportConfig::stealth();
assert!(stealth.stealth_mode);
assert!(matches!(stealth.scheduler_mode, SchedulerMode::Stealth));
}
#[test]
fn test_builder_flow() {
let builder = PhantomBuilder::new().config(TransportConfig::stealth());
assert!(builder.get_config().stealth_mode);
let client_hs = builder
.create_client_handshake()
.expect("create_client_handshake");
let _client_hello = client_hs.create_client_hello();
let server_hs = PhantomBuilder::create_server_handshake().expect("create_server_handshake");
let _server_pk = server_hs.verifying_key();
}
}