diff --git a/native/native_rust_library/src/lib.rs b/native/native_rust_library/src/lib.rs --- a/native/native_rust_library/src/lib.rs +++ b/native/native_rust_library/src/lib.rs @@ -388,7 +388,7 @@ DEVICE_TYPE.as_str_name().to_lowercase(), ) .await?; - let mut response = identity_client + let response = identity_client .get_keyserver_keys(get_keyserver_keys_request) .await? .into_inner(); diff --git a/services/backup/src/config.rs b/services/backup/src/config.rs --- a/services/backup/src/config.rs +++ b/services/backup/src/config.rs @@ -22,7 +22,7 @@ /// Stores configuration parsed from command-line arguments /// and environment variables -pub static CONFIG: Lazy = Lazy::new(|| AppConfig::parse()); +pub static CONFIG: Lazy = Lazy::new(AppConfig::parse); /// Processes the command-line arguments and environment variables. /// Should be called at the beginning of the `main()` function. diff --git a/services/backup/src/database/mod.rs b/services/backup/src/database/mod.rs --- a/services/backup/src/database/mod.rs +++ b/services/backup/src/database/mod.rs @@ -70,8 +70,9 @@ let GetItemOutput { item: Some(item), .. - } = output else { - return Ok(None) + } = output + else { + return Ok(None); }; let backup_item = item.try_into()?; diff --git a/services/backup/src/http/handlers/backup.rs b/services/backup/src/http/handlers/backup.rs --- a/services/backup/src/http/handlers/backup.rs +++ b/services/backup/src/http/handlers/backup.rs @@ -274,8 +274,8 @@ let Some(backup_item) = db_client .find_last_backup_item(&user_id) .await - .map_err(BackupError::from)? else - { + .map_err(BackupError::from)? + else { return Err(BackupError::NoBackup.into()); }; @@ -299,8 +299,8 @@ let Some(backup_item) = db_client .find_last_backup_item(&user_id) .await - .map_err(BackupError::from)? else - { + .map_err(BackupError::from)? + else { return Err(BackupError::NoBackup.into()); }; diff --git a/services/backup/src/http/handlers/log.rs b/services/backup/src/http/handlers/log.rs --- a/services/backup/src/http/handlers/log.rs +++ b/services/backup/src/http/handlers/log.rs @@ -54,9 +54,9 @@ Debug, derive_more::From, derive_more::Display, derive_more::Error, )] enum LogWSError { - BincodeError(bincode::Error), - BlobError(BlobServiceError), - DBError(database::Error), + Bincode(bincode::Error), + Blob(BlobServiceError), + DB(database::Error), } struct LogWSActor { @@ -81,7 +81,7 @@ self.info.clone(), self.blob_client.clone(), self.db_client.clone(), - bytes.into(), + bytes, ); let fut = actix::fut::wrap_future(fut).map( diff --git a/services/blob/src/database/client.rs b/services/blob/src/database/client.rs --- a/services/blob/src/database/client.rs +++ b/services/blob/src/database/client.rs @@ -205,7 +205,9 @@ DBError::AwsSdk(err.into()) })?; - let Some(items) = response.items else { return Ok(vec![]); }; + let Some(items) = response.items else { + return Ok(vec![]); + }; items .into_iter() .filter_map(|mut row| { @@ -272,7 +274,9 @@ DBError::AwsSdk(err.into()) })?; - let Some(items) = response.items else { return Ok(vec![]); }; + let Some(items) = response.items else { + return Ok(vec![]); + }; items .into_iter() .map(PrimaryKey::try_from) diff --git a/services/blob/src/database/types.rs b/services/blob/src/database/types.rs --- a/services/blob/src/database/types.rs +++ b/services/blob/src/database/types.rs @@ -186,14 +186,11 @@ // useful for convenient calls: // ddb.get_item().set_key(Some(partition_key.into())) -impl Into for PrimaryKey { - fn into(self) -> RawAttributes { +impl From for RawAttributes { + fn from(val: PrimaryKey) -> Self { HashMap::from([ - ( - ATTR_BLOB_HASH.to_string(), - AttributeValue::S(self.blob_hash), - ), - (ATTR_HOLDER.to_string(), AttributeValue::S(self.holder)), + (ATTR_BLOB_HASH.to_string(), AttributeValue::S(val.blob_hash)), + (ATTR_HOLDER.to_string(), AttributeValue::S(val.holder)), ]) } } @@ -213,9 +210,9 @@ } } -impl Into for UncheckedKind { - fn into(self) -> AttributeValue { - AttributeValue::S(self.str_value().to_string()) +impl From for AttributeValue { + fn from(val: UncheckedKind) -> Self { + AttributeValue::S(val.str_value().to_string()) } } diff --git a/services/blob/src/http/handlers/blob.rs b/services/blob/src/http/handlers/blob.rs --- a/services/blob/src/http/handlers/blob.rs +++ b/services/blob/src/http/handlers/blob.rs @@ -142,7 +142,8 @@ ) -> actix_web::Result { info!("Upload blob request"); - let Some((name, blob_hash)) = multipart::get_text_field(&mut payload).await? else { + let Some((name, blob_hash)) = multipart::get_text_field(&mut payload).await? + else { warn!("Malformed request: expected a field."); return Err(ErrorBadRequest("Bad request")); }; diff --git a/services/feature-flags/Cargo.lock b/services/feature-flags/Cargo.lock --- a/services/feature-flags/Cargo.lock +++ b/services/feature-flags/Cargo.lock @@ -875,11 +875,14 @@ "constant_time_eq", "derive_more", "grpc_clients", + "hex", "rand", "serde", "serde_json", + "sha2", "tokio", "tracing", + "uuid", ] [[package]] @@ -2697,6 +2700,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8db7427f936968176eaa7cdf81b7f98b980b18495ec28f1b5791ac3bfe3eea9" +[[package]] +name = "uuid" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e395fcf16a7a3d8127ec99782007af141946b4795001f876d54fb0d55978560" +dependencies = [ + "getrandom", +] + [[package]] name = "valuable" version = "0.1.0" diff --git a/services/identity/src/database.rs b/services/identity/src/database.rs --- a/services/identity/src/database.rs +++ b/services/identity/src/database.rs @@ -17,8 +17,8 @@ use std::sync::Arc; use crate::ddb_utils::{ - create_one_time_key_partition_key, into_one_time_put_requests, - EthereumIdentity, Identifier, OlmAccountType, + create_one_time_key_partition_key, into_one_time_put_requests, Identifier, + OlmAccountType, }; use crate::error::{consume_error, Error}; use chrono::{DateTime, Utc}; diff --git a/services/identity/src/database/device_list.rs b/services/identity/src/database/device_list.rs --- a/services/identity/src/database/device_list.rs +++ b/services/identity/src/database/device_list.rs @@ -1042,15 +1042,15 @@ } // swap primary device with the first one - let Some(primary_device_idx) = list - .iter() - .position(|id| id == &primary_device.device_id) else { - error!( - "Primary device not found in device list (userID={})", - user_id - ); - return; - }; + let Some(primary_device_idx) = + list.iter().position(|id| id == &primary_device.device_id) + else { + error!( + "Primary device not found in device list (userID={})", + user_id + ); + return; + }; list.swap(0, primary_device_idx); info!("Reordered device list for user (userID={})", user_id); } diff --git a/services/identity/src/ddb_utils.rs b/services/identity/src/ddb_utils.rs --- a/services/identity/src/ddb_utils.rs +++ b/services/identity/src/ddb_utils.rs @@ -1,7 +1,7 @@ use chrono::{DateTime, NaiveDateTime, Utc}; use comm_lib::{ aws::ddb::types::{AttributeValue, PutRequest, WriteRequest}, - database::{AttributeExtractor, AttributeMap, Value}, + database::{AttributeExtractor, AttributeMap}, }; use std::collections::HashMap; use std::iter::IntoIterator; diff --git a/services/identity/src/error.rs b/services/identity/src/error.rs --- a/services/identity/src/error.rs +++ b/services/identity/src/error.rs @@ -2,7 +2,6 @@ use comm_lib::aws::DynamoDBError; use comm_lib::database::{DBItemAttributeError, DBItemError, Value}; use std::collections::hash_map::HashMap; -use std::fmt::{Display, Formatter, Result as FmtResult}; use tracing::error; #[derive( diff --git a/services/identity/src/grpc_services/authenticated.rs b/services/identity/src/grpc_services/authenticated.rs --- a/services/identity/src/grpc_services/authenticated.rs +++ b/services/identity/src/grpc_services/authenticated.rs @@ -21,14 +21,13 @@ use super::protos::auth::{ find_user_id_request, identity, - identity_client_service_server::IdentityClientService, EthereumIdentity, - FindUserIdRequest, FindUserIdResponse, GetDeviceListRequest, - GetDeviceListResponse, Identity, InboundKeyInfo, InboundKeysForUserRequest, - InboundKeysForUserResponse, KeyserverKeysResponse, OutboundKeyInfo, - OutboundKeysForUserRequest, OutboundKeysForUserResponse, - RefreshUserPrekeysRequest, UpdateUserPasswordFinishRequest, - UpdateUserPasswordStartRequest, UpdateUserPasswordStartResponse, - UploadOneTimeKeysRequest, + identity_client_service_server::IdentityClientService, FindUserIdRequest, + FindUserIdResponse, GetDeviceListRequest, GetDeviceListResponse, Identity, + InboundKeyInfo, InboundKeysForUserRequest, InboundKeysForUserResponse, + KeyserverKeysResponse, OutboundKeyInfo, OutboundKeysForUserRequest, + OutboundKeysForUserResponse, RefreshUserPrekeysRequest, + UpdateUserPasswordFinishRequest, UpdateUserPasswordStartRequest, + UpdateUserPasswordStartResponse, UploadOneTimeKeysRequest, }; use super::protos::unauth::{Empty, IdentityKeyInfo, Prekey}; diff --git a/services/reports/src/email/mod.rs b/services/reports/src/email/mod.rs --- a/services/reports/src/email/mod.rs +++ b/services/reports/src/email/mod.rs @@ -52,8 +52,13 @@ let requests: SendEmailBatchRequest = emails .into_iter() .filter_map(|item| { - let Some(recipient) = email_config.recipient_for_report_type(&item.report_type) else { - warn!("Recipient E-mail for {:?} not configured. Skipping", &item.report_type); + let Some(recipient) = + email_config.recipient_for_report_type(&item.report_type) + else { + warn!( + "Recipient E-mail for {:?} not configured. Skipping", + &item.report_type + ); return None; }; diff --git a/services/reports/src/report_utils.rs b/services/reports/src/report_utils.rs --- a/services/reports/src/report_utils.rs +++ b/services/reports/src/report_utils.rs @@ -23,23 +23,28 @@ } pub fn inconsistent_thread_ids(content: &ReportContent) -> HashSet { - let Some(push_result) = content - .get("pushResult") - .and_then(Value::as_object) else { return HashSet::new(); }; - let Some(before_action) = content - .get("beforeAction") - .and_then(Value::as_object) else { return HashSet::new(); }; + let Some(push_result) = content.get("pushResult").and_then(Value::as_object) + else { + return HashSet::new(); + }; + let Some(before_action) = + content.get("beforeAction").and_then(Value::as_object) + else { + return HashSet::new(); + }; find_inconsistent_object_keys(push_result, before_action) } pub fn inconsistent_user_ids(content: &ReportContent) -> HashSet { - let Some(before) = content - .get("beforeStateCheck") - .and_then(Value::as_object) else { return HashSet::new(); }; - let Some(after) = content - .get("afterStateCheck") - .and_then(Value::as_object) else { return HashSet::new(); }; + let Some(before) = content.get("beforeStateCheck").and_then(Value::as_object) + else { + return HashSet::new(); + }; + let Some(after) = content.get("afterStateCheck").and_then(Value::as_object) + else { + return HashSet::new(); + }; find_inconsistent_object_keys(before, after) } diff --git a/shared/backup_client/src/lib.rs b/shared/backup_client/src/lib.rs --- a/shared/backup_client/src/lib.rs +++ b/shared/backup_client/src/lib.rs @@ -199,9 +199,9 @@ LogWSResponse::LogDownloadFinished { .. } | LogWSResponse::LogDownload { .. } => Some(Ok(response)), LogWSResponse::LogUploaded { .. } => { - return Some(Err(WSError::InvalidBackupMessage)) + Some(Err(WSError::InvalidBackupMessage)) } - LogWSResponse::ServerError => return Some(Err(WSError::ServerError)), + LogWSResponse::ServerError => Some(Err(WSError::ServerError)), } }); diff --git a/shared/comm-lib/src/blob/client.rs b/shared/comm-lib/src/blob/client.rs --- a/shared/comm-lib/src/blob/client.rs +++ b/shared/comm-lib/src/blob/client.rs @@ -318,7 +318,8 @@ return Ok(false); } trace!("Uploading blob data..."); - let Err(upload_error) = self.upload_blob(blob_hash, data_stream).await else { + let Err(upload_error) = self.upload_blob(blob_hash, data_stream).await + else { return Ok(true); }; diff --git a/shared/comm-lib/src/blob/types.rs b/shared/comm-lib/src/blob/types.rs --- a/shared/comm-lib/src/blob/types.rs +++ b/shared/comm-lib/src/blob/types.rs @@ -12,7 +12,7 @@ impl BlobInfo { pub fn from_bytes(data: &[u8]) -> Self { Self { - blob_hash: Sha256::digest(&data).encode_hex(), + blob_hash: Sha256::digest(data).encode_hex(), holder: uuid::Uuid::new_v4().to_string(), } } diff --git a/shared/comm-lib/src/database.rs b/shared/comm-lib/src/database.rs --- a/shared/comm-lib/src/database.rs +++ b/shared/comm-lib/src/database.rs @@ -305,12 +305,12 @@ .collect::, _>>()?, ), Some(_) => Err(DBItemError::new( - attribute_name.into(), + attribute_name, Value::AttributeValue(attribute), DBItemAttributeError::IncorrectType, )), None => Err(DBItemError::new( - attribute_name.into(), + attribute_name, Value::AttributeValue(attribute), DBItemAttributeError::Missing, )), diff --git a/shared/comm-lib/src/database/blob.rs b/shared/comm-lib/src/database/blob.rs --- a/shared/comm-lib/src/database/blob.rs +++ b/shared/comm-lib/src/database/blob.rs @@ -50,7 +50,7 @@ return Ok(Self::Blob(blob_info)); } - let content_data = attrs.take_attr(in_db_attr.into())?; + let content_data = attrs.take_attr(in_db_attr)?; Ok(Self::Database(content_data)) } @@ -61,7 +61,9 @@ &mut self, blob_client: &BlobServiceClient, ) -> Result<(), BlobServiceError> { - let Self::Database(ref mut contents) = self else { return Ok(()); }; + let Self::Database(ref mut contents) = self else { + return Ok(()); + }; let data = std::mem::take(contents); let new_blob_info = BlobInfo::from_bytes(&data); diff --git a/shared/comm-lib/src/tools.rs b/shared/comm-lib/src/tools.rs --- a/shared/comm-lib/src/tools.rs +++ b/shared/comm-lib/src/tools.rs @@ -2,7 +2,7 @@ // colon is valid because it is used as a separator // in some backup service identifiers -const VALID_IDENTIFIER_CHARS: &'static [char] = &['_', '-', '=', ':']; +const VALID_IDENTIFIER_CHARS: &[char] = &['_', '-', '=', ':']; /// Checks if the given string is a valid identifier for an entity /// (e.g. backup ID, blob hash, blob holder).