#![warn(missing_docs)]
#![deny(unsafe_code)]
pub mod config;
pub mod connector;
pub mod error;
pub mod prelogin_wrapper;
pub use config::{ClientAuth, TlsConfig, TlsVersion};
pub use connector::{TlsConnector, default_tls_config};
pub use error::TlsError;
pub use prelogin_wrapper::TlsPreloginWrapper;
pub use tokio_rustls::client::TlsStream;
pub use rustls::pki_types::{CertificateDer, PrivateKeyDer};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum TlsNegotiationMode {
PostPreLogin,
Strict,
}
impl TlsNegotiationMode {
#[must_use]
pub fn is_tls_first(&self) -> bool {
matches!(self, Self::Strict)
}
#[must_use]
pub fn prelogin_encrypted(&self) -> bool {
matches!(self, Self::Strict)
}
#[must_use]
pub fn from_encrypt_mode(encrypt_strict: bool) -> Self {
if encrypt_strict {
Self::Strict
} else {
Self::PostPreLogin
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_negotiation_mode_strict() {
let mode = TlsNegotiationMode::Strict;
assert!(mode.is_tls_first());
assert!(mode.prelogin_encrypted());
}
#[test]
fn test_negotiation_mode_post_prelogin() {
let mode = TlsNegotiationMode::PostPreLogin;
assert!(!mode.is_tls_first());
assert!(!mode.prelogin_encrypted());
}
#[test]
fn test_from_encrypt_mode() {
assert_eq!(
TlsNegotiationMode::from_encrypt_mode(true),
TlsNegotiationMode::Strict
);
assert_eq!(
TlsNegotiationMode::from_encrypt_mode(false),
TlsNegotiationMode::PostPreLogin
);
}
}