matirx_sdk: Fix a bunch of clippy warnings.
parent
fc0d4a7d35
commit
3bcce962e3
|
@ -294,8 +294,7 @@ impl Client {
|
||||||
|
|
||||||
#[cfg(feature = "encryption")]
|
#[cfg(feature = "encryption")]
|
||||||
{
|
{
|
||||||
match e {
|
if let RoomEvent::RoomEncrypted(ref mut e) = e {
|
||||||
RoomEvent::RoomEncrypted(ref mut e) => {
|
|
||||||
e.room_id = Some(room_id.to_owned());
|
e.room_id = Some(room_id.to_owned());
|
||||||
let mut olm = self.olm.lock().await;
|
let mut olm = self.olm.lock().await;
|
||||||
|
|
||||||
|
@ -303,8 +302,6 @@ impl Client {
|
||||||
decrypted_event = o.decrypt_room_event(&e).await.ok();
|
decrypted_event = o.decrypt_room_event(&e).await.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut room = self.get_or_create_room(&room_id).write().await;
|
let mut room = self.get_or_create_room(&room_id).write().await;
|
||||||
|
|
|
@ -150,17 +150,17 @@ impl OlmMachine {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The unique user id that owns this identity.
|
/// The unique user id that owns this identity.
|
||||||
pub(crate) fn user_id(&self) -> &UserId {
|
pub fn user_id(&self) -> &UserId {
|
||||||
&self.user_id
|
&self.user_id
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The unique device id of the device that holds this identity.
|
/// The unique device id of the device that holds this identity.
|
||||||
pub(crate) fn device_id(&self) -> &DeviceId {
|
pub fn device_id(&self) -> &DeviceId {
|
||||||
&self.device_id
|
&self.device_id
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the public parts of the identity keys.
|
/// Get the public parts of the identity keys.
|
||||||
pub(crate) fn identity_keys(&self) -> &IdentityKeys {
|
pub fn identity_keys(&self) -> &IdentityKeys {
|
||||||
self.account.identity_keys()
|
self.account.identity_keys()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,7 +289,7 @@ impl OlmMachine {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
let one_time_key = if let Some(k) = key_map.values().nth(0) {
|
let one_time_key = if let Some(k) = key_map.values().next() {
|
||||||
match k {
|
match k {
|
||||||
OneTimeKey::SignedKey(k) => k,
|
OneTimeKey::SignedKey(k) => k,
|
||||||
OneTimeKey::Key(_) => {
|
OneTimeKey::Key(_) => {
|
||||||
|
@ -826,29 +826,29 @@ impl OlmMachine {
|
||||||
let encrytped_sender = decrypted_json
|
let encrytped_sender = decrypted_json
|
||||||
.get("sender")
|
.get("sender")
|
||||||
.cloned()
|
.cloned()
|
||||||
.ok_or(EventError::MissingField("sender".to_string()))?;
|
.ok_or_else(|| EventError::MissingField("sender".to_string()))?;
|
||||||
let encrytped_sender: UserId = serde_json::from_value(encrytped_sender)?;
|
let encrytped_sender: UserId = serde_json::from_value(encrytped_sender)?;
|
||||||
let recipient = decrypted_json
|
let recipient = decrypted_json
|
||||||
.get("recipient")
|
.get("recipient")
|
||||||
.cloned()
|
.cloned()
|
||||||
.ok_or(EventError::MissingField("recipient".to_string()))?;
|
.ok_or_else(|| EventError::MissingField("recipient".to_string()))?;
|
||||||
let recipient: UserId = serde_json::from_value(recipient)?;
|
let recipient: UserId = serde_json::from_value(recipient)?;
|
||||||
|
|
||||||
let recipient_keys: BTreeMap<KeyAlgorithm, String> = serde_json::from_value(
|
let recipient_keys: BTreeMap<KeyAlgorithm, String> = serde_json::from_value(
|
||||||
decrypted_json
|
decrypted_json
|
||||||
.get("recipient_keys")
|
.get("recipient_keys")
|
||||||
.cloned()
|
.cloned()
|
||||||
.ok_or(EventError::MissingField("recipient_keys".to_string()))?,
|
.ok_or_else(|| EventError::MissingField("recipient_keys".to_string()))?,
|
||||||
)?;
|
)?;
|
||||||
let keys: BTreeMap<KeyAlgorithm, String> = serde_json::from_value(
|
let keys: BTreeMap<KeyAlgorithm, String> = serde_json::from_value(
|
||||||
decrypted_json
|
decrypted_json
|
||||||
.get("keys")
|
.get("keys")
|
||||||
.cloned()
|
.cloned()
|
||||||
.ok_or(EventError::MissingField("keys".to_string()))?,
|
.ok_or_else(|| EventError::MissingField("keys".to_string()))?,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
if recipient != self.user_id || sender != &encrytped_sender {
|
if recipient != self.user_id || sender != &encrytped_sender {
|
||||||
return Err(EventError::MissmatchedSender)?;
|
return Err(EventError::MissmatchedSender.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.account.identity_keys().ed25519()
|
if self.account.identity_keys().ed25519()
|
||||||
|
@ -856,7 +856,7 @@ impl OlmMachine {
|
||||||
.get(&KeyAlgorithm::Ed25519)
|
.get(&KeyAlgorithm::Ed25519)
|
||||||
.ok_or(EventError::MissingSigningKey)?
|
.ok_or(EventError::MissingSigningKey)?
|
||||||
{
|
{
|
||||||
return Err(EventError::MissmatchedKeys)?;
|
return Err(EventError::MissmatchedKeys.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let signing_key = keys
|
let signing_key = keys
|
||||||
|
@ -887,7 +887,7 @@ impl OlmMachine {
|
||||||
c
|
c
|
||||||
} else {
|
} else {
|
||||||
warn!("Error, unsupported encryption algorithm");
|
warn!("Error, unsupported encryption algorithm");
|
||||||
return Err(EventError::UnsupportedAlgorithm)?;
|
return Err(EventError::UnsupportedAlgorithm.into());
|
||||||
};
|
};
|
||||||
|
|
||||||
let identity_keys = self.account.identity_keys();
|
let identity_keys = self.account.identity_keys();
|
||||||
|
@ -925,7 +925,7 @@ impl OlmMachine {
|
||||||
Ok(decrypted_event)
|
Ok(decrypted_event)
|
||||||
} else {
|
} else {
|
||||||
warn!("Olm event doesn't contain a ciphertext for our key");
|
warn!("Olm event doesn't contain a ciphertext for our key");
|
||||||
Err(EventError::MissingCiphertext)?
|
Err(EventError::MissingCiphertext.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1228,8 +1228,8 @@ impl OlmMachine {
|
||||||
ToDeviceEvent::RoomKey(mut e) => {
|
ToDeviceEvent::RoomKey(mut e) => {
|
||||||
self.add_room_key(sender_key, signing_key, &mut e).await
|
self.add_room_key(sender_key, signing_key, &mut e).await
|
||||||
}
|
}
|
||||||
ToDeviceEvent::ForwardedRoomKey(mut e) => {
|
ToDeviceEvent::ForwardedRoomKey(e) => {
|
||||||
self.add_forwarded_room_key(sender_key, signing_key, &mut e)
|
self.add_forwarded_room_key(sender_key, signing_key, &e)
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
warn!("Received a unexpected encrypted to-device event");
|
warn!("Received a unexpected encrypted to-device event");
|
||||||
|
@ -1310,7 +1310,7 @@ impl OlmMachine {
|
||||||
) -> MegolmResult<EventJson<RoomEvent>> {
|
) -> MegolmResult<EventJson<RoomEvent>> {
|
||||||
let content = match &event.content {
|
let content = match &event.content {
|
||||||
EncryptedEventContent::MegolmV1AesSha2(c) => c,
|
EncryptedEventContent::MegolmV1AesSha2(c) => c,
|
||||||
_ => return Err(EventError::UnsupportedAlgorithm)?,
|
_ => return Err(EventError::UnsupportedAlgorithm.into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let room_id = event.room_id.as_ref().unwrap();
|
let room_id = event.room_id.as_ref().unwrap();
|
||||||
|
@ -1893,8 +1893,9 @@ mod test {
|
||||||
alice.account.identity_keys().curve25519(),
|
alice.account.identity_keys().curve25519(),
|
||||||
alice_session.session_id(),
|
alice_session.session_id(),
|
||||||
)
|
)
|
||||||
.await
|
.await;
|
||||||
.unwrap();
|
|
||||||
|
assert!(session.unwrap().is_some());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|
|
@ -192,7 +192,7 @@ impl DeviceStore {
|
||||||
self.entries
|
self.entries
|
||||||
.get(user_id)
|
.get(user_id)
|
||||||
.and_then(|m| m.remove(device_id))
|
.and_then(|m| m.remove(device_id))
|
||||||
.and_then(|(_, d)| Some(d))
|
.map(|(_, d)| d)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a read-only view over all devices of the given user.
|
/// Get a read-only view over all devices of the given user.
|
||||||
|
|
|
@ -58,6 +58,13 @@ impl fmt::Debug for Account {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(tarpaulin, skip)]
|
||||||
|
impl Default for Account {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Account {
|
impl Account {
|
||||||
/// Create a new account.
|
/// Create a new account.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
|
@ -182,7 +189,7 @@ impl Account {
|
||||||
inner: Arc::new(Mutex::new(session)),
|
inner: Arc::new(Mutex::new(session)),
|
||||||
session_id: Arc::new(session_id),
|
session_id: Arc::new(session_id),
|
||||||
sender_key: Arc::new(their_identity_key.to_owned()),
|
sender_key: Arc::new(their_identity_key.to_owned()),
|
||||||
creation_time: Arc::new(now.clone()),
|
creation_time: Arc::new(now),
|
||||||
last_use_time: Arc::new(now),
|
last_use_time: Arc::new(now),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -223,7 +230,7 @@ impl Account {
|
||||||
inner: Arc::new(Mutex::new(session)),
|
inner: Arc::new(Mutex::new(session)),
|
||||||
session_id: Arc::new(session_id),
|
session_id: Arc::new(session_id),
|
||||||
sender_key: Arc::new(their_identity_key.to_owned()),
|
sender_key: Arc::new(their_identity_key.to_owned()),
|
||||||
creation_time: Arc::new(now.clone()),
|
creation_time: Arc::new(now),
|
||||||
last_use_time: Arc::new(now),
|
last_use_time: Arc::new(now),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,6 +87,7 @@ impl CryptoStore for MemoryStore {
|
||||||
Ok(self.tracked_users.insert(user.clone()))
|
Ok(self.tracked_users.insert(user.clone()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::ptr_arg)]
|
||||||
async fn get_device(&self, user_id: &UserId, device_id: &DeviceId) -> Result<Option<Device>> {
|
async fn get_device(&self, user_id: &UserId, device_id: &DeviceId) -> Result<Option<Device>> {
|
||||||
Ok(self.devices.get(user_id, device_id))
|
Ok(self.devices.get(user_id, device_id))
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,6 +147,7 @@ pub trait CryptoStore: Debug + Send + Sync {
|
||||||
/// * `user_id` - The user that the device belongs to.
|
/// * `user_id` - The user that the device belongs to.
|
||||||
///
|
///
|
||||||
/// * `device_id` - The unique id of the device.
|
/// * `device_id` - The unique id of the device.
|
||||||
|
#[allow(clippy::ptr_arg)]
|
||||||
async fn get_device(&self, user_id: &UserId, device_id: &DeviceId) -> Result<Option<Device>>;
|
async fn get_device(&self, user_id: &UserId, device_id: &DeviceId) -> Result<Option<Device>>;
|
||||||
|
|
||||||
/// Get all the devices of the given user.
|
/// Get all the devices of the given user.
|
||||||
|
|
|
@ -480,12 +480,12 @@ impl CryptoStore for SqliteStore {
|
||||||
|
|
||||||
let mut group_sessions = self.load_inbound_group_sessions().await?;
|
let mut group_sessions = self.load_inbound_group_sessions().await?;
|
||||||
|
|
||||||
let _ = group_sessions
|
group_sessions
|
||||||
.drain(..)
|
.drain(..)
|
||||||
.map(|s| {
|
.map(|s| {
|
||||||
self.inbound_group_sessions.add(s);
|
self.inbound_group_sessions.add(s);
|
||||||
})
|
})
|
||||||
.collect::<()>();
|
.for_each(drop);
|
||||||
|
|
||||||
let devices = self.load_devices().await?;
|
let devices = self.load_devices().await?;
|
||||||
mem::replace(&mut self.devices, devices);
|
mem::replace(&mut self.devices, devices);
|
||||||
|
@ -625,6 +625,7 @@ impl CryptoStore for SqliteStore {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::ptr_arg)]
|
||||||
async fn get_device(&self, user_id: &UserId, device_id: &DeviceId) -> Result<Option<Device>> {
|
async fn get_device(&self, user_id: &UserId, device_id: &DeviceId) -> Result<Option<Device>> {
|
||||||
Ok(self.devices.get(user_id, device_id))
|
Ok(self.devices.get(user_id, device_id))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue