π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
fix(rust): Address cargo fmt and clippy warnings
Manav Rathiea843eba7a01
diff --git a/rust/src/api/client.rs b/rust/src/api/client.rsindex 6c0e34e856..8de5c69ae9 100644--- a/rust/src/api/client.rs+++ b/rust/src/api/client.rs@@ -1,5 +1,7 @@-use crate::{Error, Result};-use reqwest::{Client, Response};+#![allow(dead_code)]++use crate::Result;+use reqwest::Client;use std::time::Duration;const ENTE_API_ENDPOINT: &str = "https://api.ente.io";@@ -13,15 +15,13 @@ pub struct ApiClient {impl ApiClient {pub fn new(base_url: Option<String>) -> Result<Self> {- let client = Client::builder()- .timeout(Duration::from_secs(30))- .build()?;-+ let client = Client::builder().timeout(Duration::from_secs(30)).build()?;+Ok(Self {client,base_url: base_url.unwrap_or_else(|| ENTE_API_ENDPOINT.to_string()),})}-+// TODO: Implement API methods-}\ No newline at end of file+}diff --git a/rust/src/api/mod.rs b/rust/src/api/mod.rsindex f126dd43c1..05d6ac19ea 100644--- a/rust/src/api/mod.rs+++ b/rust/src/api/mod.rs@@ -1,3 +1,3 @@pub mod client;-pub use client::ApiClient;\ No newline at end of file+pub use client::ApiClient;diff --git a/rust/src/cli/account.rs b/rust/src/cli/account.rsindex 971df598f5..b15cddbcd0 100644--- a/rust/src/cli/account.rs+++ b/rust/src/cli/account.rs@@ -10,33 +10,33 @@ pub struct AccountCommand {pub enum AccountSubcommands {/// List configured accountsList,-+/// Login into existing accountAdd,-+/// Update an existing account's export directoryUpdate {/// Email address of the account#[arg(long)]email: String,-+/// Export directory path#[arg(long)]dir: String,-+/// Specify the app (photos, locker, auth)#[arg(long, default_value = "photos")]app: String,},-+/// Get token for an account for a specific appGetToken {/// Email address of the account#[arg(long)]email: String,-+/// Specify the app (photos, locker, auth)#[arg(long, default_value = "photos")]app: String,},-}\ No newline at end of file+}diff --git a/rust/src/cli/export.rs b/rust/src/cli/export.rsindex 5e7ad44e9b..4a96e9fc17 100644--- a/rust/src/cli/export.rs+++ b/rust/src/cli/export.rs@@ -5,16 +5,16 @@ pub struct ExportCommand {/// Include shared albums (pass --shared=false to exclude)#[arg(long, default_value = "true")]pub shared: bool,-+/// Include hidden albums (pass --hidden=false to exclude)#[arg(long, default_value = "true")]pub hidden: bool,-+/// Comma-separated list of album names to export#[arg(long, value_delimiter = ',')]pub albums: Option<Vec<String>>,-+/// Comma-separated list of emails to export files shared with#[arg(long, value_delimiter = ',')]pub emails: Option<Vec<String>>,-}\ No newline at end of file+}diff --git a/rust/src/cli/mod.rs b/rust/src/cli/mod.rsindex c713ce810a..8ef6a06758 100644--- a/rust/src/cli/mod.rs+++ b/rust/src/cli/mod.rs@@ -16,10 +16,10 @@ pub struct Cli {pub enum Commands {/// Manage account settingsAccount(account::AccountCommand),-+/// Export photos and filesExport(export::ExportCommand),-+/// Print version informationVersion,-}\ No newline at end of file+}diff --git a/rust/src/cli/version.rs b/rust/src/cli/version.rsindex 536b37d58e..9d8f5293c1 100644--- a/rust/src/cli/version.rs+++ b/rust/src/cli/version.rs@@ -1 +1 @@-pub const VERSION: &str = env!("CARGO_PKG_VERSION");\ No newline at end of file+pub const VERSION: &str = env!("CARGO_PKG_VERSION");diff --git a/rust/src/crypto/argon.rs b/rust/src/crypto/argon.rsindex 8fadd224d4..5bb26a5d51 100644--- a/rust/src/crypto/argon.rs+++ b/rust/src/crypto/argon.rs@@ -3,14 +3,21 @@ use libsodium_sys as sodium;/// Derive a key using Argon2id algorithm/// This matches the Go implementation using libsodium-pub fn derive_argon_key(password: &str, salt: &str, mem_limit: u32, ops_limit: u32) -> Result<Vec<u8>> {+pub fn derive_argon_key(+ password: &str,+ salt: &str,+ mem_limit: u32,+ ops_limit: u32,+) -> Result<Vec<u8>> {if mem_limit < 1024 || ops_limit < 1 {- return Err(Error::InvalidInput("Invalid memory or operation limits".into()));+ return Err(Error::InvalidInput(+ "Invalid memory or operation limits".into(),+ ));}// Decode salt from base64let salt_bytes = super::decode_base64(salt)?;-+// libsodium requires salt to be exactly crypto_pwhash_SALTBYTESif salt_bytes.len() != sodium::crypto_pwhash_SALTBYTES as usize {return Err(Error::Crypto(format!(@@ -21,16 +28,16 @@ pub fn derive_argon_key(password: &str, salt: &str, mem_limit: u32, ops_limit: u}let mut key = vec![0u8; 32]; // 32 bytes output-+let result = unsafe {sodium::crypto_pwhash(key.as_mut_ptr(),key.len() as u64,- password.as_ptr() as *const u8,+ password.as_ptr(),password.len() as u64,- salt_bytes.as_ptr() as *const u8,+ salt_bytes.as_ptr(),ops_limit as u64,- (mem_limit as usize * 1024) as usize, // Convert from KB to bytes+ mem_limit as usize * 1024, // Convert from KB to bytessodium::crypto_pwhash_ALG_ARGON2ID13 as i32,)};@@ -40,4 +47,4 @@ pub fn derive_argon_key(password: &str, salt: &str, mem_limit: u32, ops_limit: u}Ok(key)-}\ No newline at end of file+}diff --git a/rust/src/crypto/chacha.rs b/rust/src/crypto/chacha.rsindex be786a382b..883c1ae9cf 100644--- a/rust/src/crypto/chacha.rs+++ b/rust/src/crypto/chacha.rs@@ -19,7 +19,8 @@ pub fn decrypt_chacha(ciphertext: &[u8], nonce: &[u8], key: &[u8]) -> Result<Vec)));}- let mut plaintext = vec![0u8; ciphertext.len() - sodium::crypto_aead_xchacha20poly1305_ietf_ABYTES as usize];+ let mut plaintext =+ vec![0u8; ciphertext.len() - sodium::crypto_aead_xchacha20poly1305_ietf_ABYTES as usize];let mut plaintext_len: u64 = 0;let result = unsafe {@@ -37,7 +38,9 @@ pub fn decrypt_chacha(ciphertext: &[u8], nonce: &[u8], key: &[u8]) -> Result<Vec};if result != 0 {- return Err(Error::Crypto("Failed to decrypt with ChaCha20-Poly1305".into()));+ return Err(Error::Crypto(+ "Failed to decrypt with ChaCha20-Poly1305".into(),+ ));}plaintext.truncate(plaintext_len as usize);@@ -62,7 +65,8 @@ pub fn encrypt_chacha(plaintext: &[u8], nonce: &[u8], key: &[u8]) -> Result<Vec<)));}- let mut ciphertext = vec![0u8; plaintext.len() + sodium::crypto_aead_xchacha20poly1305_ietf_ABYTES as usize];+ let mut ciphertext =+ vec![0u8; plaintext.len() + sodium::crypto_aead_xchacha20poly1305_ietf_ABYTES as usize];let mut ciphertext_len: u64 = 0;let result = unsafe {@@ -80,7 +84,9 @@ pub fn encrypt_chacha(plaintext: &[u8], nonce: &[u8], key: &[u8]) -> Result<Vec<};if result != 0 {- return Err(Error::Crypto("Failed to encrypt with ChaCha20-Poly1305".into()));+ return Err(Error::Crypto(+ "Failed to encrypt with ChaCha20-Poly1305".into(),+ ));}ciphertext.truncate(ciphertext_len as usize);@@ -159,4 +165,4 @@ pub fn secret_box_seal(plaintext: &[u8], nonce: &[u8], key: &[u8]) -> Result<Vec}Ok(ciphertext)-}\ No newline at end of file+}diff --git a/rust/src/crypto/kdf.rs b/rust/src/crypto/kdf.rsindex 62b74bfa29..135e6e1261 100644--- a/rust/src/crypto/kdf.rs+++ b/rust/src/crypto/kdf.rs@@ -14,7 +14,7 @@ pub fn derive_login_key(key_enc_key: &[u8]) -> Result<Vec<u8>> {LOGIN_SUB_KEY_ID,LOGIN_SUB_KEY_LEN,)?;-+// Return the first 16 bytes of the derived keyOk(sub_key[..16].to_vec())}@@ -28,8 +28,8 @@ fn derive_sub_key() -> Result<Vec<u8>> {const CRYPTO_KDF_BLAKE2B_BYTES_MIN: usize = 16;const CRYPTO_KDF_BLAKE2B_BYTES_MAX: usize = 64;-- if sub_key_length < CRYPTO_KDF_BLAKE2B_BYTES_MIN || sub_key_length > CRYPTO_KDF_BLAKE2B_BYTES_MAX {++ if !(CRYPTO_KDF_BLAKE2B_BYTES_MIN..=CRYPTO_KDF_BLAKE2B_BYTES_MAX).contains(&sub_key_length) {return Err(Error::Crypto("subKeyLength out of bounds".into()));}@@ -45,14 +45,11 @@ fn derive_sub_key(// Create output bufferlet mut out = vec![0u8; sub_key_length];- // Initialize Blake2b state with salt and personalization- let mut state = std::mem::MaybeUninit::<sodium::crypto_generichash_blake2b_state>::uninit();-let result = unsafe {sodium::crypto_generichash_blake2b_salt_personal(out.as_mut_ptr(),sub_key_length,- std::ptr::null(), // No input data, just using key, salt, and personalization+ std::ptr::null(), // No input data, just using key, salt, and personalization0,master_key.as_ptr(),master_key.len(),@@ -66,4 +63,4 @@ fn derive_sub_key(}Ok(out)-}\ No newline at end of file+}diff --git a/rust/src/crypto/mod.rs b/rust/src/crypto/mod.rsindex d6b883a936..c9b19b4c68 100644--- a/rust/src/crypto/mod.rs+++ b/rust/src/crypto/mod.rs@@ -1,8 +1,7 @@use crate::Result;-use base64::{engine::general_purpose::STANDARD as BASE64, Engine};+use base64::{Engine, engine::general_purpose::STANDARD as BASE64};use libsodium_sys as sodium;use std::sync::Once;-use zeroize::Zeroize;mod argon;mod chacha;@@ -16,11 +15,9 @@ static INIT: Once = Once::new();/// Initialize libsodium. Must be called before any crypto operations.pub fn init() -> Result<()> {- INIT.call_once(|| {- unsafe {- if sodium::sodium_init() < 0 {- panic!("Failed to initialize libsodium");- }+ INIT.call_once(|| unsafe {+ if sodium::sodium_init() < 0 {+ panic!("Failed to initialize libsodium");}});Ok(())@@ -34,4 +31,4 @@ pub fn decode_base64(input: &str) -> Result<Vec<u8>> {/// Encode bytes to base64 stringpub fn encode_base64(input: &[u8]) -> String {BASE64.encode(input)-}\ No newline at end of file+}diff --git a/rust/src/lib.rs b/rust/src/lib.rsindex da6c5fd203..cd7da447fd 100644--- a/rust/src/lib.rs+++ b/rust/src/lib.rs@@ -6,4 +6,4 @@ pub mod storage;pub mod sync;pub mod utils;-pub use models::error::{Error, Result};\ No newline at end of file+pub use models::error::{Error, Result};diff --git a/rust/src/main.rs b/rust/src/main.rsindex d38bff6dbf..74bcae5f12 100644--- a/rust/src/main.rs+++ b/rust/src/main.rs@@ -1,31 +1,34 @@use clap::Parser;-use ente_rs::{cli::{Cli, Commands}, Result};+use ente_rs::{+ Result,+ cli::{Cli, Commands},+};#[tokio::main]async fn main() -> Result<()> {// Initialize loggerenv_logger::init();-+// Initialize libsodiumente_rs::crypto::init()?;-+// Parse CLI argumentslet cli = Cli::parse();-+// Handle commandsmatch cli.command {Commands::Version => {println!("ente-rs version {}", ente_rs::cli::version::VERSION);}- Commands::Account(account_cmd) => {+ Commands::Account(_account_cmd) => {// TODO: Implement account commandsprintln!("Account command not yet implemented");}- Commands::Export(export_cmd) => {+ Commands::Export(_export_cmd) => {// TODO: Implement export commandprintln!("Export command not yet implemented");}}-+Ok(())-}\ No newline at end of file+}diff --git a/rust/src/models/account.rs b/rust/src/models/account.rsindex 2c338b04ff..667b1585db 100644--- a/rust/src/models/account.rs+++ b/rust/src/models/account.rs@@ -1,3 +1,5 @@+#![allow(dead_code)]+use serde::{Deserialize, Serialize};use uuid::Uuid;use zeroize::Zeroize;@@ -88,4 +90,4 @@ pub struct AuthResponse {pub encrypted_token: Option<String>,#[serde(rename = "keyAttributes")]pub key_attributes: Option<KeyAttributes>,-}\ No newline at end of file+}diff --git a/rust/src/models/collection.rs b/rust/src/models/collection.rsindex d0d3b44aa8..db67b23b12 100644--- a/rust/src/models/collection.rs+++ b/rust/src/models/collection.rs@@ -1,3 +1,5 @@+#![allow(dead_code)]+use serde::{Deserialize, Serialize};#[derive(Debug, Clone, Serialize, Deserialize)]@@ -51,4 +53,4 @@ pub struct PublicURL {pub device_limit: i32,#[serde(rename = "validTill")]pub valid_till: i64,-}\ No newline at end of file+}diff --git a/rust/src/models/error.rs b/rust/src/models/error.rsindex 7369162adf..c41179ce71 100644--- a/rust/src/models/error.rs+++ b/rust/src/models/error.rs@@ -4,39 +4,39 @@ use thiserror::Error;pub enum Error {#[error("IO error: {0}")]Io(#[from] std::io::Error),-+#[error("Network error: {0}")]Network(#[from] reqwest::Error),-+#[error("Serialization error: {0}")]Serialization(#[from] serde_json::Error),-+#[error("Database error: {0}")]Database(#[from] sled::Error),-+#[error("Crypto error: {0}")]Crypto(String),-+#[error("Authentication failed: {0}")]AuthenticationFailed(String),-+#[error("Invalid configuration: {0}")]InvalidConfig(String),-+#[error("Not found: {0}")]NotFound(String),-+#[error("Invalid input: {0}")]InvalidInput(String),-+#[error("SRP error: {0}")]Srp(String),-+#[error("Base64 decode error: {0}")]Base64Decode(#[from] base64::DecodeError),-+#[error("{0}")]Generic(String),}-pub type Result<T> = std::result::Result<T, Error>;\ No newline at end of file+pub type Result<T> = std::result::Result<T, Error>;diff --git a/rust/src/models/file.rs b/rust/src/models/file.rsindex b6b4d808bd..f85b40c3e6 100644--- a/rust/src/models/file.rs+++ b/rust/src/models/file.rs@@ -1,3 +1,5 @@+#![allow(dead_code)]+use serde::{Deserialize, Serialize};#[derive(Debug, Clone, Serialize, Deserialize)]@@ -45,4 +47,4 @@ pub enum FileType {Video,LivePhoto,Other,-}\ No newline at end of file+}diff --git a/rust/src/models/mod.rs b/rust/src/models/mod.rsindex c0361c7fde..b17d4e426b 100644--- a/rust/src/models/mod.rs+++ b/rust/src/models/mod.rs@@ -1,6 +1,6 @@-pub mod error;pub mod account;-pub mod file;pub mod collection;+pub mod error;+pub mod file;-pub use error::{Error, Result};\ No newline at end of file+pub use error::{Error, Result};diff --git a/rust/src/storage/mod.rs b/rust/src/storage/mod.rsindex 40acfeebce..a4cb12346c 100644--- a/rust/src/storage/mod.rs+++ b/rust/src/storage/mod.rs@@ -1,3 +1,5 @@+#![allow(dead_code)]+use crate::Result;use sled::Db;use std::path::Path;@@ -11,6 +13,6 @@ impl Storage {let db = sled::open(path)?;Ok(Self { db })}-+// TODO: Implement storage methods-}\ No newline at end of file+}diff --git a/rust/src/sync/mod.rs b/rust/src/sync/mod.rsindex 4987e8934d..951a255363 100644--- a/rust/src/sync/mod.rs+++ b/rust/src/sync/mod.rs@@ -1 +1 @@-// TODO: Implement sync functionality\ No newline at end of file+// TODO: Implement sync functionalitydiff --git a/rust/src/utils/mod.rs b/rust/src/utils/mod.rsindex e25c2ed1f1..3a997a187c 100644--- a/rust/src/utils/mod.rs+++ b/rust/src/utils/mod.rs@@ -1,5 +1,5 @@-use std::path::PathBuf;use dirs;+use std::path::PathBuf;/// Get the CLI configuration directorypub fn get_cli_config_dir() -> crate::Result<PathBuf> {@@ -7,22 +7,22 @@ pub fn get_cli_config_dir() -> crate::Result<PathBuf> {if let Ok(config_dir) = std::env::var("ENTE_CLI_CONFIG_DIR") {return Ok(PathBuf::from(config_dir));}-+// For backward compatibilityif let Ok(config_dir) = std::env::var("ENTE_CLI_CONFIG_PATH") {return Ok(PathBuf::from(config_dir));}-+// Default to ~/.entelet home_dir = dirs::home_dir().ok_or_else(|| crate::Error::Generic("Could not determine home directory".into()))?;-+let cli_path = home_dir.join(".ente");-+// Create directory if it doesn't existif !cli_path.exists() {std::fs::create_dir_all(&cli_path)?;}-+Ok(cli_path)-}\ No newline at end of file+}