mod handshake;
use self::handshake::Handshaker;
use super::{options::ConnectionPoolOptions, Connection};
use crate::{client::auth::Credential, error::Result};
#[derive(Debug)]
pub(super) struct ConnectionEstablisher {
handshaker: Handshaker,
}
impl ConnectionEstablisher {
pub(super) fn new(options: Option<&ConnectionPoolOptions>) -> Self {
let handshaker = Handshaker::new(options);
Self { handshaker }
}
pub(super) fn establish_connection(
&self,
connection: &mut Connection,
credential: Option<&Credential>,
) -> Result<()> {
self.handshaker.handshake(connection)?;
if let Some(credential) = credential {
credential.authenticate_stream(connection)?;
}
Ok(())
}
}