Fix clippy lints

Automated via `cargo clippy --workspace --all-targets -Zunstable-options --fix`.
This commit is contained in:
Jonas Platte 2021-06-07 15:34:23 +02:00
parent e18f248dbb
commit 3bac536daf
No known key found for this signature in database
GPG key ID: CC154DE0E30B7C67
33 changed files with 117 additions and 128 deletions

View file

@ -333,7 +333,7 @@ impl QrVerification {
/// This represents the ID as a string even if it is a `EventId`.
pub fn flow_id(&self) -> &str {
match self {
QrVerification::Verification(v) => &v.event_id.as_str(),
QrVerification::Verification(v) => v.event_id.as_str(),
QrVerification::SelfVerification(v) => &v.transaction_id,
QrVerification::SelfVerificationNoMasterKey(v) => &v.transaction_id,
}
@ -434,7 +434,7 @@ impl VerificationData {
pub fn to_bytes(&self) -> Result<Vec<u8>, EncodingError> {
to_bytes(
Self::QR_MODE,
&self.event_id.as_str(),
self.event_id.as_str(),
&self.first_master_key,
&self.second_master_key,
&self.shared_secret,

View file

@ -89,7 +89,7 @@ async fn login(
&sas.other_device().user_id(),
&sas.other_device().device_id()
);
print_devices(&e.sender, &client).await;
print_devices(&e.sender, client).await;
sas.accept().await.unwrap();
}
@ -110,7 +110,7 @@ async fn login(
if sas.is_done() {
print_result(&sas);
print_devices(&e.sender, &client).await;
print_devices(&e.sender, client).await;
}
}
@ -141,7 +141,7 @@ async fn login(
}
AnySyncMessageEvent::KeyVerificationKey(e) => {
let sas = client
.get_verification(&e.content.relation.event_id.as_str())
.get_verification(e.content.relation.event_id.as_str())
.await
.expect("Sas object wasn't created");
@ -149,13 +149,13 @@ async fn login(
}
AnySyncMessageEvent::KeyVerificationMac(e) => {
let sas = client
.get_verification(&e.content.relation.event_id.as_str())
.get_verification(e.content.relation.event_id.as_str())
.await
.expect("Sas object wasn't created");
if sas.is_done() {
print_result(&sas);
print_devices(&e.sender, &client).await;
print_devices(&e.sender, client).await;
}
}
_ => (),

View file

@ -27,7 +27,7 @@ impl EventHandler for EventCallback {
..
} = event
{
let member = room.get_member(&sender).await.unwrap().unwrap();
let member = room.get_member(sender).await.unwrap().unwrap();
let name = member.display_name().unwrap_or_else(|| member.user_id().as_str());
println!("{}: {}", name, msg_body);
}

View file

@ -2033,15 +2033,15 @@ impl Client {
}
}
OutgoingRequests::KeysUpload(request) => {
if let Err(e) = self.keys_upload(&r.request_id(), request).await {
if let Err(e) = self.keys_upload(r.request_id(), request).await {
warn!("Error while querying device keys {:?}", e);
}
}
OutgoingRequests::ToDeviceRequest(request) => {
// TODO remove this unwrap
if let Ok(resp) = self.send_to_device(&request).await {
if let Ok(resp) = self.send_to_device(request).await {
self.base_client
.mark_request_as_sent(&r.request_id(), &resp)
.mark_request_as_sent(r.request_id(), &resp)
.await
.unwrap();
}
@ -2050,7 +2050,7 @@ impl Client {
// TODO remove this unwrap.
if let Ok(resp) = self.send(request.clone(), None).await {
self.base_client
.mark_request_as_sent(&r.request_id(), &resp)
.mark_request_as_sent(r.request_id(), &resp)
.await
.unwrap();
}
@ -2058,7 +2058,7 @@ impl Client {
OutgoingRequests::RoomMessage(request) => {
if let Ok(resp) = self.room_send_helper(request).await {
self.base_client
.mark_request_as_sent(&r.request_id(), &resp)
.mark_request_as_sent(r.request_id(), &resp)
.await
.unwrap();
}
@ -2523,17 +2523,13 @@ impl Client {
MediaType::Uri(uri) => {
if let MediaFormat::Thumbnail(size) = &request.format {
self.send(
get_content_thumbnail::Request::from_url(
&uri,
size.width,
size.height,
)?,
get_content_thumbnail::Request::from_url(uri, size.width, size.height)?,
None,
)
.await?
.file
} else {
self.send(get_content::Request::from_url(&uri)?, None).await?.file
self.send(get_content::Request::from_url(uri)?, None).await?.file
}
}
};
@ -2562,7 +2558,7 @@ impl Client {
///
/// * `uri` - The `MxcUri` of the files.
pub async fn remove_media_content_for_uri(&self, uri: &MxcUri) -> Result<()> {
Ok(self.base_client.store().remove_media_content_for_uri(&uri).await?)
Ok(self.base_client.store().remove_media_content_for_uri(uri).await?)
}
/// Get the file of the given media event content.

View file

@ -141,7 +141,7 @@ impl Handler {
}
for (room_id, notifications) in &response.notifications {
if let Some(room) = self.get_room(&room_id) {
if let Some(room) = self.get_room(room_id) {
for notification in notifications {
self.on_room_notification(room.clone(), notification.clone()).await;
}
@ -191,20 +191,20 @@ impl Handler {
async fn handle_state_event(&self, room: Room, event: &AnySyncStateEvent) {
match event {
AnySyncStateEvent::RoomMember(member) => self.on_state_member(room, &member).await,
AnySyncStateEvent::RoomName(name) => self.on_state_name(room, &name).await,
AnySyncStateEvent::RoomMember(member) => self.on_state_member(room, member).await,
AnySyncStateEvent::RoomName(name) => self.on_state_name(room, name).await,
AnySyncStateEvent::RoomCanonicalAlias(canonical) => {
self.on_state_canonical_alias(room, &canonical).await
self.on_state_canonical_alias(room, canonical).await
}
AnySyncStateEvent::RoomAliases(aliases) => self.on_state_aliases(room, &aliases).await,
AnySyncStateEvent::RoomAvatar(avatar) => self.on_state_avatar(room, &avatar).await,
AnySyncStateEvent::RoomAliases(aliases) => self.on_state_aliases(room, aliases).await,
AnySyncStateEvent::RoomAvatar(avatar) => self.on_state_avatar(room, avatar).await,
AnySyncStateEvent::RoomPowerLevels(power) => {
self.on_state_power_levels(room, &power).await
self.on_state_power_levels(room, power).await
}
AnySyncStateEvent::RoomJoinRules(rules) => self.on_state_join_rules(room, &rules).await,
AnySyncStateEvent::RoomJoinRules(rules) => self.on_state_join_rules(room, rules).await,
AnySyncStateEvent::RoomTombstone(tomb) => {
// TODO make `on_state_tombstone` method
self.on_room_tombstone(room, &tomb).await
self.on_room_tombstone(room, tomb).await
}
AnySyncStateEvent::Custom(custom) => {
self.on_custom_event(room, &CustomEvent::State(custom)).await
@ -221,23 +221,23 @@ impl Handler {
) {
match event {
AnyStrippedStateEvent::RoomMember(member) => {
self.on_stripped_state_member(room, &member, None).await
self.on_stripped_state_member(room, member, None).await
}
AnyStrippedStateEvent::RoomName(name) => self.on_stripped_state_name(room, &name).await,
AnyStrippedStateEvent::RoomName(name) => self.on_stripped_state_name(room, name).await,
AnyStrippedStateEvent::RoomCanonicalAlias(canonical) => {
self.on_stripped_state_canonical_alias(room, &canonical).await
self.on_stripped_state_canonical_alias(room, canonical).await
}
AnyStrippedStateEvent::RoomAliases(aliases) => {
self.on_stripped_state_aliases(room, &aliases).await
self.on_stripped_state_aliases(room, aliases).await
}
AnyStrippedStateEvent::RoomAvatar(avatar) => {
self.on_stripped_state_avatar(room, &avatar).await
self.on_stripped_state_avatar(room, avatar).await
}
AnyStrippedStateEvent::RoomPowerLevels(power) => {
self.on_stripped_state_power_levels(room, &power).await
self.on_stripped_state_power_levels(room, power).await
}
AnyStrippedStateEvent::RoomJoinRules(rules) => {
self.on_stripped_state_join_rules(room, &rules).await
self.on_stripped_state_join_rules(room, rules).await
}
_ => {}
}
@ -249,18 +249,16 @@ impl Handler {
event: &AnyRoomAccountDataEvent,
) {
if let AnyRoomAccountDataEvent::FullyRead(event) = event {
self.on_non_room_fully_read(room, &event).await
self.on_non_room_fully_read(room, event).await
}
}
pub(crate) async fn handle_account_data_event(&self, event: &AnyGlobalAccountDataEvent) {
match event {
AnyGlobalAccountDataEvent::IgnoredUserList(ignored) => {
self.on_non_room_ignored_users(&ignored).await
}
AnyGlobalAccountDataEvent::PushRules(rules) => {
self.on_non_room_push_rules(&rules).await
self.on_non_room_ignored_users(ignored).await
}
AnyGlobalAccountDataEvent::PushRules(rules) => self.on_non_room_push_rules(rules).await,
_ => {}
}
}

View file

@ -368,6 +368,6 @@ impl HttpSend for Client {
request: http::Request<Bytes>,
config: RequestConfig,
) -> Result<http::Response<Bytes>, HttpError> {
send_request(&self, request, config).await
send_request(self, request, config).await
}
}

View file

@ -392,7 +392,7 @@ impl Joined {
};
let txn_id = txn_id.unwrap_or_else(Uuid::new_v4).to_string();
let request = send_message_event::Request::new(&self.inner.room_id(), &txn_id, &content);
let request = send_message_event::Request::new(self.inner.room_id(), &txn_id, &content);
let response = self.client.send(request, None).await?;
Ok(response)
@ -480,7 +480,7 @@ impl Joined {
(response, keys)
} else {
let response = self.client.upload(&content_type, &mut reader).await?;
let response = self.client.upload(content_type, &mut reader).await?;
(response, None)
};

View file

@ -63,7 +63,7 @@ impl RoomMember {
if let Some(url) = self.avatar_url() {
if let (Some(width), Some(height)) = (width, height) {
let request =
get_content_thumbnail::Request::from_url(&url, width.into(), height.into())?;
get_content_thumbnail::Request::from_url(url, width.into(), height.into())?;
let response = self.client.send(request, None).await?;
Ok(Some(response.file))
} else {

View file

@ -504,7 +504,7 @@ impl BaseClient {
}
if let Some(context) = &push_context {
let actions = push_rules.get_actions(&event.event, &context).to_vec();
let actions = push_rules.get_actions(&event.event, context).to_vec();
if actions.iter().any(|a| matches!(a, Action::Notify)) {
changes.add_notification(
@ -941,7 +941,7 @@ impl BaseClient {
async fn apply_changes(&self, changes: &StateChanges) {
for (room_id, room_info) in &changes.room_infos {
if let Some(room) = self.store.get_room(&room_id) {
if let Some(room) = self.store.get_room(room_id) {
room.update_summary(room_info.clone())
}
}
@ -978,7 +978,7 @@ impl BaseClient {
let mut user_ids = BTreeSet::new();
for member in &members {
if self.store.get_member_event(&room_id, &member.state_key).await?.is_none() {
if self.store.get_member_event(room_id, &member.state_key).await?.is_none() {
#[cfg(feature = "encryption")]
match member.content.membership {
MembershipState::Join | MembershipState::Invite => {
@ -987,7 +987,7 @@ impl BaseClient {
_ => (),
}
ambiguity_cache.handle_event(&changes, room_id, &member).await?;
ambiguity_cache.handle_event(&changes, room_id, member).await?;
if member.state_key == member.sender {
changes

View file

@ -92,7 +92,7 @@ impl RoomMember {
.map(|e| {
e.content
.users
.get(&self.user_id())
.get(self.user_id())
.map(|p| (*p).into())
.unwrap_or_else(|| e.content.users_default.into())
})

View file

@ -335,12 +335,7 @@ impl Room {
let is_own_user_id = |u: &str| u == self.own_user_id().as_str();
let members: Vec<RoomMember> = if summary.heroes.is_empty() {
self.active_members()
.await?
.into_iter()
.filter(|u| !is_own_member(&u))
.take(5)
.collect()
self.active_members().await?.into_iter().filter(|u| !is_own_member(u)).take(5).collect()
} else {
let members: Vec<_> = stream::iter(summary.heroes.iter())
.filter(|u| future::ready(!is_own_user_id(u)))
@ -528,7 +523,7 @@ impl RoomInfo {
}
pub(crate) fn handle_state_event(&mut self, event: &AnyStateEventContent) -> bool {
self.base_info.handle_state_event(&event)
self.base_info.handle_state_event(event)
}
pub(crate) fn update_notification_count(

View file

@ -197,7 +197,7 @@ impl AmbiguityCache {
{
u.clone()
} else {
self.store.get_users_with_display_name(&room_id, &old_name).await?
self.store.get_users_with_display_name(room_id, old_name).await?
};
Some(AmbiguityMap { display_name: old_name.to_string(), users: old_display_name_map })
@ -231,7 +231,7 @@ impl AmbiguityCache {
{
u.clone()
} else {
self.store.get_users_with_display_name(&room_id, &new_display_name).await?
self.store.get_users_with_display_name(room_id, new_display_name).await?
};
Some(AmbiguityMap {

View file

@ -304,7 +304,7 @@ impl SledStore {
event: &[u8],
) -> Result<T, SerializationError> {
if let Some(key) = &*self.store_key {
let encrypted: EncryptedEvent = serde_json::from_slice(&event)?;
let encrypted: EncryptedEvent = serde_json::from_slice(event)?;
Ok(key.decrypt(encrypted)?)
} else {
Ok(serde_json::from_slice(event)?)

View file

@ -139,7 +139,7 @@ impl StoreKey {
/// Expand the given passphrase into a KEY_SIZE long key.
fn expand_key(passphrase: &str, salt: &[u8], rounds: u32) -> Zeroizing<Vec<u8>> {
let mut key = Zeroizing::from(vec![0u8; KEY_SIZE]);
pbkdf2::<Hmac<Sha256>>(passphrase.as_bytes(), &salt, rounds, &mut *key);
pbkdf2::<Hmac<Sha256>>(passphrase.as_bytes(), salt, rounds, &mut *key);
key
}
@ -162,7 +162,7 @@ impl StoreKey {
let key = StoreKey::expand_key(passphrase, &salt, KDF_ROUNDS);
let key = Key::from_slice(key.as_ref());
let cipher = ChaCha20Poly1305::new(&key);
let cipher = ChaCha20Poly1305::new(key);
let mut nonce = vec![0u8; NONCE_SIZE];
nonce.try_fill(&mut rng)?;
@ -230,7 +230,7 @@ impl StoreKey {
let decrypted = match encrypted.ciphertext_info {
CipherTextInfo::ChaCha20Poly1305 { nonce, ciphertext } => {
let cipher = ChaCha20Poly1305::new(&key);
let cipher = ChaCha20Poly1305::new(key);
let nonce = Nonce::from_slice(&nonce);
cipher.decrypt(nonce, ciphertext.as_ref())?
}

View file

@ -161,7 +161,7 @@ fn encrypt_helper(mut plaintext: &mut [u8], passphrase: &str, rounds: u32) -> St
pbkdf2::<Hmac<Sha512>>(passphrase.as_bytes(), &salt, rounds, &mut derived_keys);
let (key, hmac_key) = derived_keys.split_at(KEY_SIZE);
let mut aes = Aes256Ctr::new_var(&key, &iv.to_be_bytes()).expect("Can't create AES object");
let mut aes = Aes256Ctr::new_var(key, &iv.to_be_bytes()).expect("Can't create AES object");
aes.apply_keystream(&mut plaintext);
@ -171,7 +171,7 @@ fn encrypt_helper(mut plaintext: &mut [u8], passphrase: &str, rounds: u32) -> St
payload.extend(&salt);
payload.extend(&iv.to_be_bytes());
payload.extend(&rounds.to_be_bytes());
payload.extend_from_slice(&plaintext);
payload.extend_from_slice(plaintext);
let mut hmac = Hmac::<Sha256>::new_varkey(hmac_key).expect("Can't create HMAC object");
hmac.update(&payload);
@ -218,7 +218,7 @@ fn decrypt_helper(ciphertext: &str, passphrase: &str) -> Result<String, KeyExpor
hmac.verify(&mac).map_err(|_| KeyExportError::InvalidMac)?;
let mut ciphertext = &mut decoded[ciphertext_start..ciphertext_end];
let mut aes = Aes256Ctr::new_var(&key, &iv).expect("Can't create an AES object");
let mut aes = Aes256Ctr::new_var(key, &iv).expect("Can't create an AES object");
aes.apply_keystream(&mut ciphertext);
Ok(String::from_utf8(ciphertext.to_owned())?)

View file

@ -398,7 +398,7 @@ impl ReadOnlyDevice {
// If it's one of our own devices, just check that
// we signed the device.
UserIdentities::Own(_) => {
own_identity.is_device_signed(&self).map_or(false, |_| true)
own_identity.is_device_signed(self).map_or(false, |_| true)
}
// If it's a device from someone else, first check
@ -406,10 +406,10 @@ impl ReadOnlyDevice {
// check if the other user has signed this device.
UserIdentities::Other(device_identity) => {
own_identity
.is_identity_signed(&device_identity)
.is_identity_signed(device_identity)
.map_or(false, |_| true)
&& device_identity
.is_device_signed(&self)
.is_device_signed(self)
.map_or(false, |_| true)
}
})
@ -455,7 +455,7 @@ impl ReadOnlyDevice {
return Err(OlmError::MissingSession);
};
let message = session.encrypt(&self, event_type, content).await?;
let message = session.encrypt(self, event_type, content).await?;
Ok((session, message))
}

View file

@ -540,7 +540,7 @@ impl KeyRequestMachine {
&self,
key_info: &RequestedKeyInfo,
) -> Result<bool, CryptoStoreError> {
let request = self.store.get_key_request_by_info(&key_info).await?;
let request = self.store.get_key_request_by_info(key_info).await?;
// Don't send out duplicate requests, users can re-request them if they
// think a second request might succeed.
@ -1244,7 +1244,7 @@ mod test {
.store
.get_inbound_group_session(
&room_id(),
&bob_account.identity_keys().curve25519(),
bob_account.identity_keys().curve25519(),
group_session.session_id()
)
.await
@ -1393,7 +1393,7 @@ mod test {
.store
.get_inbound_group_session(
&room_id(),
&bob_account.identity_keys().curve25519(),
bob_account.identity_keys().curve25519(),
group_session.session_id()
)
.await

View file

@ -123,7 +123,7 @@ impl OlmMachine {
pub fn new(user_id: &UserId, device_id: &DeviceId) -> Self {
let store: Box<dyn CryptoStore> = Box::new(MemoryStore::new());
let device_id: DeviceIdBox = device_id.into();
let account = ReadOnlyAccount::new(&user_id, &device_id);
let account = ReadOnlyAccount::new(user_id, &device_id);
OlmMachine::new_helper(
user_id,
@ -334,7 +334,7 @@ impl OlmMachine {
self.receive_keys_claim_response(response).await?;
}
IncomingResponse::ToDevice(_) => {
self.mark_to_device_request_as_sent(&request_id).await?;
self.mark_to_device_request_as_sent(request_id).await?;
}
IncomingResponse::SigningKeysUpload(_) => {
self.receive_cross_signing_upload_response().await?;
@ -738,7 +738,7 @@ impl OlmMachine {
async fn handle_to_device_event(&self, event: &AnyToDeviceEvent) {
match event {
AnyToDeviceEvent::RoomKeyRequest(e) => {
self.key_request_machine.receive_incoming_key_request(&e)
self.key_request_machine.receive_incoming_key_request(e)
}
AnyToDeviceEvent::KeyVerificationAccept(..)
| AnyToDeviceEvent::KeyVerificationCancel(..)
@ -748,7 +748,7 @@ impl OlmMachine {
| AnyToDeviceEvent::KeyVerificationReady(..)
| AnyToDeviceEvent::KeyVerificationDone(..)
| AnyToDeviceEvent::KeyVerificationStart(..) => {
self.handle_verification_event(&event).await;
self.handle_verification_event(event).await;
}
AnyToDeviceEvent::Dummy(_) => {}
AnyToDeviceEvent::RoomKey(_) => {}
@ -794,7 +794,7 @@ impl OlmMachine {
self.update_one_time_key_count(one_time_keys_counts).await;
for user_id in &changed_devices.changed {
if let Err(e) = self.identity_manager.mark_user_as_changed(&user_id).await {
if let Err(e) = self.identity_manager.mark_user_as_changed(user_id).await {
error!("Error marking a tracked user as changed {:?}", e);
}
}
@ -1200,7 +1200,7 @@ impl OlmMachine {
.get_inbound_group_sessions()
.await?
.drain(..)
.filter(|s| predicate(&s))
.filter(|s| predicate(s))
.collect();
for session in sessions.drain(..) {

View file

@ -376,7 +376,7 @@ impl Account {
plaintext: &str,
) -> OlmResult<(Raw<AnyToDeviceEvent>, String)> {
// TODO make the errors a bit more specific.
let decrypted_json: Value = serde_json::from_str(&plaintext)?;
let decrypted_json: Value = serde_json::from_str(plaintext)?;
let encrypted_sender = decrypted_json
.get("sender")
@ -874,7 +874,7 @@ impl ReadOnlyAccount {
}
};
device.verify_one_time_key(&one_time_key).map_err(|e| {
device.verify_one_time_key(one_time_key).map_err(|e| {
SessionCreationError::InvalidSignature(
device.user_id().to_owned(),
device.device_id().into(),
@ -889,7 +889,7 @@ impl ReadOnlyAccount {
)
})?;
self.create_outbound_session_helper(curve_key, &one_time_key).await.map_err(|e| {
self.create_outbound_session_helper(curve_key, one_time_key).await.map_err(|e| {
SessionCreationError::OlmError(
device.user_id().to_owned(),
device.device_id().into(),
@ -974,7 +974,7 @@ impl ReadOnlyAccount {
let inbound = InboundGroupSession::new(
sender_key,
signing_key,
&room_id,
room_id,
outbound.session_key().await,
Some(visibility),
)

View file

@ -144,7 +144,7 @@ impl PrivateCrossSigningIdentity {
.await
.as_ref()
.ok_or(SignatureError::MissingSigningKey)?
.sign_user(&user_identity)
.sign_user(user_identity)
.await?;
Ok(SignatureUploadRequest::new(signed_keys))

View file

@ -320,7 +320,7 @@ impl Signing {
let ciphertext = &decode(pickled.ciphertext)?;
let seed = cipher
.decrypt(&nonce, ciphertext.as_slice())
.decrypt(nonce, ciphertext.as_slice())
.map_err(|e| SigningError::Decryption(e.to_string()))?;
Ok(Self::from_seed(seed))

View file

@ -133,7 +133,7 @@ mod test {
.verify_json(
&user_id!("@example:localhost"),
&DeviceKeyId::from_parts(DeviceKeyAlgorithm::Ed25519, "GBEWHQOYGS".into()),
&signing_key,
signing_key,
&mut device_keys,
)
.expect("Can't verify device keys");

View file

@ -210,7 +210,7 @@ impl GroupSessionManager {
room_id: &RoomId,
settings: EncryptionSettings,
) -> OlmResult<(OutboundGroupSession, Option<InboundGroupSession>)> {
let outbound_session = self.sessions.get_or_load(&room_id).await?;
let outbound_session = self.sessions.get_or_load(room_id).await?;
// If there is no session or the session has expired or is invalid,
// create a new one.
@ -331,7 +331,7 @@ impl GroupSessionManager {
let mut should_rotate = user_left || visibility_changed;
for user_id in users {
let user_devices = self.store.get_user_devices(&user_id).await?;
let user_devices = self.store.get_user_devices(user_id).await?;
let non_blacklisted_devices: Vec<Device> =
user_devices.devices().filter(|d| !d.is_blacklisted()).collect();

View file

@ -246,7 +246,7 @@ impl SessionManager {
for (user_id, user_devices) in &response.one_time_keys {
for (device_id, key_map) in user_devices {
let device = match self.store.get_readonly_device(&user_id, device_id).await {
let device = match self.store.get_readonly_device(user_id, device_id).await {
Ok(Some(d)) => d,
Ok(None) => {
warn!(
@ -267,7 +267,7 @@ impl SessionManager {
info!("Creating outbound Session for {} {}", user_id, device_id);
let session = match self.account.create_outbound_session(device, &key_map).await {
let session = match self.account.create_outbound_session(device, key_map).await {
Ok(s) => s,
Err(e) => {
warn!("Error creating new outbound session {:?}", e);
@ -277,9 +277,9 @@ impl SessionManager {
changes.sessions.push(session);
self.key_request_machine.retry_keyshare(&user_id, device_id);
self.key_request_machine.retry_keyshare(user_id, device_id);
if let Err(e) = self.check_if_unwedged(&user_id, device_id).await {
if let Err(e) = self.check_if_unwedged(user_id, device_id).await {
error!(
"Error while treating an unwedged device {} {} {:?}",
user_id, device_id, e
@ -426,7 +426,7 @@ mod test {
assert!(!manager.users_for_key_claim.contains_key(bob.user_id()));
assert!(!manager.is_device_wedged(&bob_device));
manager.mark_device_as_wedged(bob_device.user_id(), &curve_key).await.unwrap();
manager.mark_device_as_wedged(bob_device.user_id(), curve_key).await.unwrap();
assert!(manager.is_device_wedged(&bob_device));
assert!(manager.users_for_key_claim.contains_key(bob.user_id()));

View file

@ -107,7 +107,7 @@ impl PickleKey {
fn expand_key(passphrase: &str, salt: &[u8], rounds: u32) -> Zeroizing<Vec<u8>> {
let mut key = Zeroizing::from(vec![0u8; KEY_SIZE]);
pbkdf2::<Hmac<Sha256>>(passphrase.as_bytes(), &salt, rounds, &mut *key);
pbkdf2::<Hmac<Sha256>>(passphrase.as_bytes(), salt, rounds, &mut *key);
key
}
@ -133,13 +133,13 @@ impl PickleKey {
let key = PickleKey::expand_key(passphrase, &salt, KDF_ROUNDS);
let key = GenericArray::from_slice(key.as_ref());
let cipher = Aes256Gcm::new(&key);
let cipher = Aes256Gcm::new(key);
let mut nonce = vec![0u8; NONCE_SIZE];
getrandom(&mut nonce).expect("Can't generate new random nonce for the pickle key");
let ciphertext = cipher
.encrypt(&GenericArray::from_slice(nonce.as_ref()), self.aes256_key.as_slice())
.encrypt(GenericArray::from_slice(nonce.as_ref()), self.aes256_key.as_slice())
.expect("Can't encrypt pickle key");
EncryptedPickleKey {
@ -169,7 +169,7 @@ impl PickleKey {
let decrypted = match encrypted.ciphertext_info {
CipherTextInfo::Aes256Gcm { nonce, ciphertext } => {
let cipher = Aes256Gcm::new(&key);
let cipher = Aes256Gcm::new(key);
let nonce = GenericArray::from_slice(&nonce);
cipher.decrypt(nonce, ciphertext.as_ref())?
}

View file

@ -213,7 +213,7 @@ impl SledStore {
let session_cache = SessionStore::new();
let pickle_key = if let Some(passphrase) = passphrase {
Self::get_or_create_pickle_key(&passphrase, &db)?
Self::get_or_create_pickle_key(passphrase, &db)?
} else {
PickleKey::try_from(DEFAULT_PICKLE.as_bytes().to_vec())
.expect("Can't create default pickle key")
@ -1111,7 +1111,7 @@ mod test {
let store = SledStore::open_with_passphrase(tmpdir_path, None).expect("Can't create store");
let account = ReadOnlyAccount::new(&user_id, &device_id);
let account = ReadOnlyAccount::new(&user_id, device_id);
store.save_account(account.clone()).await.expect("Can't save account");

View file

@ -48,8 +48,8 @@ pub enum AnyEvent<'a> {
impl AnyEvent<'_> {
pub fn sender(&self) -> &UserId {
match self {
Self::Room(e) => &e.sender(),
Self::ToDevice(e) => &e.sender(),
Self::Room(e) => e.sender(),
Self::ToDevice(e) => e.sender(),
}
}
@ -382,7 +382,7 @@ impl<'a> StartContent<'a> {
pub fn flow_id(&self) -> &str {
match self {
Self::ToDevice(c) => &c.transaction_id,
Self::Room(c) => &c.relation.event_id.as_str(),
Self::Room(c) => c.relation.event_id.as_str(),
}
}
@ -434,7 +434,7 @@ impl<'a> DoneContent<'a> {
pub fn flow_id(&self) -> &str {
match self {
Self::ToDevice(c) => &c.transaction_id,
Self::Room(c) => &c.relation.event_id.as_str(),
Self::Room(c) => c.relation.event_id.as_str(),
}
}
}

View file

@ -222,7 +222,7 @@ impl VerificationMachine {
AnyVerificationContent::Start(c) => {
if let Some(request) = self.requests.get(flow_id.as_str()) {
if request.flow_id() == &flow_id {
request.receive_start(event.sender(), &c).await?
request.receive_start(event.sender(), c).await?
} else {
flow_id_mismatch();
}

View file

@ -275,7 +275,7 @@ impl IdentitiesBeingVerified {
// We only sign other users here.
let request = if let Some(i) = i.other() {
// Signing can fail if the user signing key is missing.
match self.private_identity.sign_user(&i).await {
match self.private_identity.sign_user(i).await {
Ok(r) => Some(r),
Err(SignatureError::MissingSigningKey) => {
warn!(

View file

@ -582,7 +582,7 @@ impl RequestState<Ready> {
"Received a new verification start event",
);
let device = if let Some(d) = self.store.get_device(&sender, content.from_device()).await? {
let device = if let Some(d) = self.store.get_device(sender, content.from_device()).await? {
d
} else {
warn!(
@ -594,7 +594,7 @@ impl RequestState<Ready> {
return Ok(());
};
let identity = self.store.get_user_identity(&sender).await?;
let identity = self.store.get_user_identity(sender).await?;
match content.method() {
StartMethod::SasV1(_) => match self.to_started_sas(content, device.clone(), identity) {

View file

@ -188,7 +188,7 @@ pub fn receive_mac_event(
let mut verified_devices = Vec::new();
let mut verified_identities = Vec::new();
let info = extra_mac_info_receive(&ids, flow_id);
let info = extra_mac_info_receive(ids, flow_id);
trace!(
"Received a key.verification.mac event from {} {}",
@ -395,7 +395,7 @@ pub fn get_emoji(
) -> [(&'static str, &'static str); 7] {
let bytes = sas
.generate_bytes(
&extra_info_sas(&ids, &sas.public_key(), their_pubkey, &flow_id, we_started),
&extra_info_sas(ids, &sas.public_key(), their_pubkey, flow_id, we_started),
6,
)
.expect("Can't generate bytes");
@ -432,7 +432,7 @@ pub fn get_emoji_index(
) -> [u8; 7] {
let bytes = sas
.generate_bytes(
&extra_info_sas(&ids, &sas.public_key(), their_pubkey, &flow_id, we_started),
&extra_info_sas(ids, &sas.public_key(), their_pubkey, flow_id, we_started),
6,
)
.expect("Can't generate bytes");
@ -507,7 +507,7 @@ pub fn get_decimal(
) -> (u16, u16, u16) {
let bytes = sas
.generate_bytes(
&extra_info_sas(&ids, &sas.public_key(), their_pubkey, &flow_id, we_started),
&extra_info_sas(ids, &sas.public_key(), their_pubkey, flow_id, we_started),
5,
)
.expect("Can't generate bytes");

View file

@ -584,7 +584,7 @@ mod test {
let content = MacContent::try_from(&content).unwrap();
alice.receive_any_event(bob.user_id(), &content.into());
assert!(alice.verified_devices().unwrap().contains(&alice.other_device()));
assert!(bob.verified_devices().unwrap().contains(&bob.other_device()));
assert!(alice.verified_devices().unwrap().contains(alice.other_device()));
assert!(bob.verified_devices().unwrap().contains(bob.other_device()));
}
}

View file

@ -285,12 +285,12 @@ impl<S: Clone> SasState<S> {
/// Get our own user id.
#[cfg(test)]
pub fn user_id(&self) -> &UserId {
&self.ids.account.user_id()
self.ids.account.user_id()
}
/// Get our own device id.
pub fn device_id(&self) -> &DeviceId {
&self.ids.account.device_id()
self.ids.account.device_id()
}
#[cfg(test)]
@ -448,7 +448,7 @@ impl SasState<Created> {
sender: &UserId,
content: &AcceptContent,
) -> Result<SasState<Accepted>, SasState<Cancelled>> {
self.check_event(&sender, content.flow_id()).map_err(|c| self.clone().cancel(c))?;
self.check_event(sender, content.flow_id()).map_err(|c| self.clone().cancel(c))?;
if let AcceptMethod::MSasV1(content) = content.method() {
let accepted_protocols =
@ -604,7 +604,7 @@ impl SasState<Started> {
sender: &UserId,
content: &KeyContent,
) -> Result<SasState<KeyReceived>, SasState<Cancelled>> {
self.check_event(&sender, &content.flow_id()).map_err(|c| self.clone().cancel(c))?;
self.check_event(sender, content.flow_id()).map_err(|c| self.clone().cancel(c))?;
let their_pubkey = content.public_key().to_owned();
@ -644,7 +644,7 @@ impl SasState<Accepted> {
sender: &UserId,
content: &KeyContent,
) -> Result<SasState<KeyReceived>, SasState<Cancelled>> {
self.check_event(&sender, content.flow_id()).map_err(|c| self.clone().cancel(c))?;
self.check_event(sender, content.flow_id()).map_err(|c| self.clone().cancel(c))?;
let commitment = calculate_commitment(
content.public_key(),
@ -781,14 +781,14 @@ impl SasState<KeyReceived> {
sender: &UserId,
content: &MacContent,
) -> Result<SasState<MacReceived>, SasState<Cancelled>> {
self.check_event(&sender, content.flow_id()).map_err(|c| self.clone().cancel(c))?;
self.check_event(sender, content.flow_id()).map_err(|c| self.clone().cancel(c))?;
let (devices, master_keys) = receive_mac_event(
&self.inner.lock().unwrap(),
&self.ids,
self.verification_flow_id.as_str(),
sender,
&content,
content,
)
.map_err(|c| self.clone().cancel(c))?;
@ -846,9 +846,9 @@ impl SasState<Confirmed> {
let (devices, master_keys) = receive_mac_event(
&self.inner.lock().unwrap(),
&self.ids,
&self.verification_flow_id.as_str(),
self.verification_flow_id.as_str(),
sender,
&content,
content,
)
.map_err(|c| self.clone().cancel(c))?;
@ -881,14 +881,14 @@ impl SasState<Confirmed> {
sender: &UserId,
content: &MacContent,
) -> Result<SasState<WaitingForDone>, SasState<Cancelled>> {
self.check_event(&sender, &content.flow_id()).map_err(|c| self.clone().cancel(c))?;
self.check_event(sender, content.flow_id()).map_err(|c| self.clone().cancel(c))?;
let (devices, master_keys) = receive_mac_event(
&self.inner.lock().unwrap(),
&self.ids,
&self.verification_flow_id.as_str(),
self.verification_flow_id.as_str(),
sender,
&content,
content,
)
.map_err(|c| self.clone().cancel(c))?;
@ -965,7 +965,7 @@ impl SasState<MacReceived> {
&self.inner.lock().unwrap(),
&self.ids,
&self.state.their_pubkey,
&self.verification_flow_id.as_str(),
self.verification_flow_id.as_str(),
self.state.we_started,
)
}
@ -993,7 +993,7 @@ impl SasState<MacReceived> {
&self.inner.lock().unwrap(),
&self.ids,
&self.state.their_pubkey,
&self.verification_flow_id.as_str(),
self.verification_flow_id.as_str(),
self.state.we_started,
)
}
@ -1036,7 +1036,7 @@ impl SasState<WaitingForDone> {
sender: &UserId,
content: &DoneContent,
) -> Result<SasState<Done>, SasState<Cancelled>> {
self.check_event(&sender, content.flow_id()).map_err(|c| self.clone().cancel(c))?;
self.check_event(sender, content.flow_id()).map_err(|c| self.clone().cancel(c))?;
Ok(SasState {
inner: self.inner,