crypto: Rewrite the device keys fetching in the SQLiteStore using filter_map.

master
Damir Jelić 2020-07-21 16:28:41 +02:00
parent 578c927e58
commit a9d645cbcd
1 changed files with 12 additions and 16 deletions

View File

@ -472,23 +472,19 @@ impl SqliteStore {
.fetch_all(&mut *connection) .fetch_all(&mut *connection)
.await?; .await?;
let mut keys = BTreeMap::new(); let keys: BTreeMap<AlgorithmAndDeviceId, String> = key_rows
.iter()
.filter_map(|row| {
let algorithm: &str = &row.0;
let algorithm = KeyAlgorithm::try_from(algorithm).ok()?;
let key = &row.1;
for row in key_rows { Some((
let algorithm: &str = &row.0; AlgorithmAndDeviceId(algorithm, device_id.as_str().into()),
let algorithm = if let Ok(a) = KeyAlgorithm::try_from(algorithm) { key.to_owned(),
a ))
} else { })
continue; .collect();
};
let key = &row.1;
keys.insert(
AlgorithmAndDeviceId(algorithm, device_id.as_str().into()),
key.to_owned(),
);
}
let device = Device::new( let device = Device::new(
user_id, user_id,