crypto: Return a result when searching for missing sessions.

master
Damir Jelić 2020-04-27 16:26:03 +02:00
parent 6d67cd2ac7
commit 96144404ed
3 changed files with 8 additions and 8 deletions

View File

@ -898,7 +898,7 @@ impl AsyncClient {
.read() .read()
.await .await
.get_missing_sessions(users) .get_missing_sessions(users)
.await .await?
}; };
if !missing_sessions.is_empty() { if !missing_sessions.is_empty() {

View File

@ -435,12 +435,12 @@ impl Client {
pub async fn get_missing_sessions( pub async fn get_missing_sessions(
&self, &self,
users: impl Iterator<Item = &UserId>, users: impl Iterator<Item = &UserId>,
) -> BTreeMap<UserId, BTreeMap<DeviceId, KeyAlgorithm>> { ) -> Result<BTreeMap<UserId, BTreeMap<DeviceId, KeyAlgorithm>>> {
let mut olm = self.olm.lock().await; let mut olm = self.olm.lock().await;
match &mut *olm { match &mut *olm {
Some(o) => o.get_missing_sessions(users).await, Some(o) => Ok(o.get_missing_sessions(users).await?),
None => BTreeMap::new(), None => Ok(BTreeMap::new()),
} }
} }

View File

@ -202,11 +202,11 @@ impl OlmMachine {
pub async fn get_missing_sessions( pub async fn get_missing_sessions(
&mut self, &mut self,
users: impl Iterator<Item = &UserId>, users: impl Iterator<Item = &UserId>,
) -> BTreeMap<UserId, BTreeMap<DeviceId, KeyAlgorithm>> { ) -> Result<BTreeMap<UserId, BTreeMap<DeviceId, KeyAlgorithm>>> {
let mut missing = BTreeMap::new(); let mut missing = BTreeMap::new();
for user_id in users { for user_id in users {
let user_devices = self.store.get_user_devices(user_id).await.unwrap(); let user_devices = self.store.get_user_devices(user_id).await?;
for device in user_devices.devices() { for device in user_devices.devices() {
let sender_key = if let Some(k) = device.get_key(&KeyAlgorithm::Curve25519) { let sender_key = if let Some(k) = device.get_key(&KeyAlgorithm::Curve25519) {
@ -215,7 +215,7 @@ impl OlmMachine {
continue; continue;
}; };
let sessions = self.store.get_sessions(sender_key).await.unwrap(); let sessions = self.store.get_sessions(sender_key).await?;
let is_missing = if let Some(sessions) = sessions { let is_missing = if let Some(sessions) = sessions {
sessions.lock().await.is_empty() sessions.lock().await.is_empty()
@ -237,7 +237,7 @@ impl OlmMachine {
} }
} }
missing Ok(missing)
} }
pub async fn receive_keys_claim_response( pub async fn receive_keys_claim_response(