Rename Authenticator to UserAuthenticator

This commit is contained in:
Xiretza 2024-02-10 12:35:05 +00:00
parent ffd3a95076
commit e56c7525e2

View file

@ -31,12 +31,12 @@ pub enum AuthenticationError {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct Authenticator { pub struct UserAuthenticator {
db: Arc<Mutex<SqliteDatabase>>, db: Arc<Mutex<SqliteDatabase>>,
} }
impl Authenticator { impl UserAuthenticator {
const USER_TOKEN_LEN: usize = 30; const TOKEN_LEN: usize = 30;
pub fn new(db: Arc<Mutex<SqliteDatabase>>) -> Self { pub fn new(db: Arc<Mutex<SqliteDatabase>>) -> Self {
Self { db } Self { db }
@ -45,7 +45,7 @@ impl Authenticator {
#[instrument] #[instrument]
pub async fn create_user_token(&mut self, username: &str, password: &Password) -> UserToken { pub async fn create_user_token(&mut self, username: &str, password: &Password) -> UserToken {
let new_token = let new_token =
UserToken::from(Alphanumeric.sample_string(&mut thread_rng(), Self::USER_TOKEN_LEN)); UserToken::from(Alphanumeric.sample_string(&mut thread_rng(), Self::TOKEN_LEN));
let mut db = self.db.lock().await; let mut db = self.db.lock().await;
if let Err(err) = db.save_token(username, &new_token).await { if let Err(err) = db.save_token(username, &new_token).await {
@ -85,12 +85,12 @@ impl ServerPadlockGenerator {
} }
pub struct UserServerKeyGenerator { pub struct UserServerKeyGenerator {
user_authenticator: Arc<Authenticator>, user_authenticator: Arc<UserAuthenticator>,
padlock_generator: Arc<ServerPadlockGenerator>, padlock_generator: Arc<ServerPadlockGenerator>,
} }
impl UserServerKeyGenerator { impl UserServerKeyGenerator {
pub fn new(/* Authenticator, ServerPadlockGenerator? */) -> Self { pub fn new(/* UserAuthenticator, ServerPadlockGenerator? */) -> Self {
todo!() todo!()
} }