1
0
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:
2021-05-14 11:57:24 +02:00
parent 210dcb9597
commit c52b7a4408
5 changed files with 80 additions and 4 deletions

View 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))
}

View File

@ -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;