use std::path::{Path, PathBuf};
#[derive(Debug, Clone)]
pub struct TlsConfig {
pub cert_path: PathBuf,
pub key_path: Option<PathBuf>,
pub ca_path: Option<PathBuf>,
pub alpn: Vec<Vec<u8>>,
pub verify_peer: bool,
}
impl TlsConfig {
pub fn server(cert: impl AsRef<Path>, key: impl AsRef<Path>) -> Self {
Self {
cert_path: cert.as_ref().to_path_buf(),
key_path: Some(key.as_ref().to_path_buf()),
ca_path: None,
alpn: vec![b"h3".to_vec()],
verify_peer: false,
}
}
pub fn client(ca: impl AsRef<Path>) -> Self {
Self {
cert_path: PathBuf::new(),
key_path: None,
ca_path: Some(ca.as_ref().to_path_buf()),
alpn: vec![b"h3".to_vec()],
verify_peer: true,
}
}
pub fn client_insecure() -> Self {
Self {
cert_path: PathBuf::new(),
key_path: None,
ca_path: None,
alpn: vec![b"h3".to_vec()],
verify_peer: false,
}
}
pub fn with_alpn(mut self, alpn: Vec<Vec<u8>>) -> Self {
self.alpn = alpn;
self
}
pub fn with_verify_peer(mut self, verify: bool) -> Self {
self.verify_peer = verify;
self
}
}