mirror of
https://gitlab.com/famedly/conduit.git
synced 2024-11-17 10:48:18 -07: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:
parent
fe8cfe0556
commit
0725b69abb
@ -1,6 +1,6 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::Arc;
|
||||
use std::sync::RwLock;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use crate::{client_server::SESSION_ID_LENGTH, utils, Error, Result};
|
||||
use ruma::{
|
||||
@ -20,7 +20,8 @@ use super::abstraction::Tree;
|
||||
|
||||
pub struct Uiaa {
|
||||
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 {
|
||||
@ -149,16 +150,17 @@ impl Uiaa {
|
||||
session: &str,
|
||||
request: &CanonicalJsonValue,
|
||||
) -> Result<()> {
|
||||
let mut userdevicesessionid = user_id.as_bytes().to_vec();
|
||||
userdevicesessionid.push(0xff);
|
||||
userdevicesessionid.extend_from_slice(device_id.as_bytes());
|
||||
userdevicesessionid.push(0xff);
|
||||
userdevicesessionid.extend_from_slice(session.as_bytes());
|
||||
|
||||
self.userdevicesessionid_uiaarequest.write().unwrap().insert(
|
||||
userdevicesessionid,
|
||||
serde_json::to_vec(request).expect("json value to vec always works"),
|
||||
);
|
||||
self.userdevicesessionid_uiaarequest
|
||||
.write()
|
||||
.unwrap()
|
||||
.insert(
|
||||
(
|
||||
user_id.to_owned(),
|
||||
device_id.to_string(),
|
||||
session.to_string(),
|
||||
),
|
||||
request.to_owned(),
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -169,22 +171,16 @@ impl Uiaa {
|
||||
device_id: &DeviceId,
|
||||
session: &str,
|
||||
) -> Result<Option<CanonicalJsonValue>> {
|
||||
let mut userdevicesessionid = user_id.as_bytes().to_vec();
|
||||
userdevicesessionid.push(0xff);
|
||||
userdevicesessionid.extend_from_slice(device_id.as_bytes());
|
||||
userdevicesessionid.push(0xff);
|
||||
userdevicesessionid.extend_from_slice(session.as_bytes());
|
||||
|
||||
self.userdevicesessionid_uiaarequest.read().unwrap()
|
||||
.get(&userdevicesessionid)
|
||||
.map(|bytes| {
|
||||
serde_json::from_str::<CanonicalJsonValue>(
|
||||
&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()
|
||||
Ok(self
|
||||
.userdevicesessionid_uiaarequest
|
||||
.read()
|
||||
.unwrap()
|
||||
.get(&(
|
||||
user_id.to_owned(),
|
||||
device_id.to_string(),
|
||||
session.to_string(),
|
||||
))
|
||||
.map(|j| j.to_owned()))
|
||||
}
|
||||
|
||||
fn update_uiaa_session(
|
||||
|
Loading…
Reference in New Issue
Block a user