mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-07-10 09:32:48 +00:00
Can create auth challenge
This commit is contained in:
41
src/helpers/admin_key_authentication_challenges_helper.rs
Normal file
41
src/helpers/admin_key_authentication_challenges_helper.rs
Normal file
@ -0,0 +1,41 @@
|
||||
//! # Administrators key authentication challenges helper
|
||||
//!
|
||||
//! Allows to temporarily stores keys authentication challenges
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use webauthn_rs::AuthenticationState;
|
||||
|
||||
use crate::data::error::Res;
|
||||
|
||||
static mut CACHE: Option<Arc<Mutex<HashMap<u64, AuthenticationState>>>> = None;
|
||||
|
||||
/// Initialize this helper's cache
|
||||
pub fn init() {
|
||||
unsafe {
|
||||
let map = HashMap::new();
|
||||
CACHE = Some(Arc::new(Mutex::new(map)));
|
||||
}
|
||||
}
|
||||
|
||||
/// Store a new entry in the cache
|
||||
pub fn set(key_id: u64, state: AuthenticationState) -> Res {
|
||||
let cache = unsafe {
|
||||
CACHE.as_ref().unwrap().lock()
|
||||
};
|
||||
|
||||
cache?.insert(key_id, state);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get(key_id: u64) -> Res<Option<AuthenticationState>> {
|
||||
let cache = unsafe {
|
||||
CACHE.as_ref().unwrap().lock()
|
||||
};
|
||||
|
||||
Ok(cache?.remove(&key_id))
|
||||
}
|
@ -25,4 +25,5 @@ pub mod forez_presence_helper;
|
||||
pub mod admin_account_helper;
|
||||
pub mod admin_account_key_helper;
|
||||
pub mod admin_access_token_helper;
|
||||
pub mod admin_key_registration_challenges_helper;
|
||||
pub mod admin_key_registration_challenges_helper;
|
||||
pub mod admin_key_authentication_challenges_helper;
|
Reference in New Issue
Block a user