use super::authentication_settings::{AuthSetup, IAuthenticationSettings};
use crate::{
AclError,
auth::{GarnetAuthenticator, GarnetPasswordAuthenticator},
};
pub struct PasswordAuthenticationSettings {
pwd: Box<[u8]>,
}
impl PasswordAuthenticationSettings {
pub fn new(pwd: &str) -> Result<Self, AclError> {
if pwd.is_empty() {
return Err(AclError::Acl("Password cannot be null.".into()));
}
Ok(Self {
pwd: pwd.as_bytes().to_vec().into(),
})
}
}
impl IAuthenticationSettings for PasswordAuthenticationSettings {
fn create_authenticator(&self, _setup: &AuthSetup) -> Result<GarnetAuthenticator, AclError> {
Ok(GarnetAuthenticator::Password(
GarnetPasswordAuthenticator::new(self.pwd.clone()),
))
}
}