use super::i_garnet_authenticator::IGarnetAuthenticator;
use crate::acl::secrets_utility::constant_equals;
pub struct GarnetPasswordAuthenticator {
pwd: Box<[u8]>,
authenticated: bool,
}
impl GarnetPasswordAuthenticator {
pub fn new(pwd: Box<[u8]>) -> Self {
Self {
pwd,
authenticated: false,
}
}
}
impl IGarnetAuthenticator for GarnetPasswordAuthenticator {
fn is_authenticated(&self) -> bool {
self.authenticated
}
fn can_authenticate(&self) -> bool {
true
}
fn has_acl_support(&self) -> bool {
false
}
fn authenticate(&mut self, password: &[u8], _username: &[u8]) -> bool {
self.authenticated = constant_equals(&self.pwd, password);
self.authenticated
}
}