#![deny(clippy::pedantic)]
#![allow(
clippy::clone_on_copy,
clippy::missing_fields_in_debug,
clippy::must_use_candidate,
clippy::missing_errors_doc
)]
use std::sync::atomic::{AtomicUsize, Ordering};
#[cfg(feature = "openssl")]
pub mod openssl;
#[cfg(feature = "rustls")]
pub mod rustls;
use ntex_service::cfg::{CfgContext, Configuration};
use ntex_util::{services::Counter, time::Millis, time::Seconds};
pub fn max_concurrent_ssl_accept(num: usize) {
MAX_SSL_ACCEPT.store(num, Ordering::Relaxed);
MAX_SSL_ACCEPT_COUNTER.with(|counts| counts.set_capacity(num));
}
static MAX_SSL_ACCEPT: AtomicUsize = AtomicUsize::new(256);
thread_local! {
static MAX_SSL_ACCEPT_COUNTER: Counter = Counter::new(MAX_SSL_ACCEPT.load(Ordering::Relaxed));
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct PskIdentity(pub Vec<u8>);
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Servername(pub String);
#[derive(Debug)]
pub struct TlsConfig {
handshake_timeout: Millis,
config: CfgContext,
}
impl Default for TlsConfig {
fn default() -> Self {
TlsConfig::new()
}
}
impl Configuration for TlsConfig {
const NAME: &str = "TLS Configuration";
fn ctx(&self) -> &CfgContext {
&self.config
}
fn set_ctx(&mut self, ctx: CfgContext) {
self.config = ctx;
}
}
impl TlsConfig {
#[must_use]
pub fn new() -> Self {
TlsConfig {
handshake_timeout: Millis(5_000),
config: CfgContext::default(),
}
}
#[inline]
pub fn handshake_timeout(&self) -> Millis {
self.handshake_timeout
}
#[must_use]
pub fn set_handshake_timeout<T: Into<Seconds>>(mut self, timeout: T) -> Self {
self.handshake_timeout = timeout.into().into();
self
}
}