1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2024-11-09 20:21:06 +01:00

Clean up userdevicesessionid_uiaarequest BTreeMap

There is no need to encode or decode anything as we are not
saving to disk
This commit is contained in:
Moritz Bitsch 2021-12-18 18:46:38 +01:00
parent fe8cfe0556
commit 0725b69abb

View file

@ -1,6 +1,6 @@
use std::collections::BTreeMap;
use std::sync::Arc; use std::sync::Arc;
use std::sync::RwLock; use std::sync::RwLock;
use std::collections::BTreeMap;
use crate::{client_server::SESSION_ID_LENGTH, utils, Error, Result}; use crate::{client_server::SESSION_ID_LENGTH, utils, Error, Result};
use ruma::{ use ruma::{
@ -20,7 +20,8 @@ use super::abstraction::Tree;
pub struct Uiaa { pub struct Uiaa {
pub(super) userdevicesessionid_uiaainfo: Arc<dyn Tree>, // User-interactive authentication pub(super) userdevicesessionid_uiaainfo: Arc<dyn Tree>, // User-interactive authentication
pub(super) userdevicesessionid_uiaarequest: RwLock<BTreeMap<Vec<u8>, Vec<u8>>>, // UiaaRequest = canonical json value pub(super) userdevicesessionid_uiaarequest:
RwLock<BTreeMap<(UserId, String, String), CanonicalJsonValue>>,
} }
impl Uiaa { impl Uiaa {
@ -149,15 +150,16 @@ impl Uiaa {
session: &str, session: &str,
request: &CanonicalJsonValue, request: &CanonicalJsonValue,
) -> Result<()> { ) -> Result<()> {
let mut userdevicesessionid = user_id.as_bytes().to_vec(); self.userdevicesessionid_uiaarequest
userdevicesessionid.push(0xff); .write()
userdevicesessionid.extend_from_slice(device_id.as_bytes()); .unwrap()
userdevicesessionid.push(0xff); .insert(
userdevicesessionid.extend_from_slice(session.as_bytes()); (
user_id.to_owned(),
self.userdevicesessionid_uiaarequest.write().unwrap().insert( device_id.to_string(),
userdevicesessionid, session.to_string(),
serde_json::to_vec(request).expect("json value to vec always works"), ),
request.to_owned(),
); );
Ok(()) Ok(())
@ -169,22 +171,16 @@ impl Uiaa {
device_id: &DeviceId, device_id: &DeviceId,
session: &str, session: &str,
) -> Result<Option<CanonicalJsonValue>> { ) -> Result<Option<CanonicalJsonValue>> {
let mut userdevicesessionid = user_id.as_bytes().to_vec(); Ok(self
userdevicesessionid.push(0xff); .userdevicesessionid_uiaarequest
userdevicesessionid.extend_from_slice(device_id.as_bytes()); .read()
userdevicesessionid.push(0xff); .unwrap()
userdevicesessionid.extend_from_slice(session.as_bytes()); .get(&(
user_id.to_owned(),
self.userdevicesessionid_uiaarequest.read().unwrap() device_id.to_string(),
.get(&userdevicesessionid) session.to_string(),
.map(|bytes| { ))
serde_json::from_str::<CanonicalJsonValue>( .map(|j| j.to_owned()))
&utils::string_from_bytes(&bytes)
.map_err(|_| Error::bad_database("Invalid uiaa request bytes in db."))?,
)
.map_err(|_| Error::bad_database("Invalid uiaa request in db."))
})
.transpose()
} }
fn update_uiaa_session( fn update_uiaa_session(