π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Prune Rust comments
Manav Rathi9f5040e5d7d3
diff --git a/rust/apps/cli/src/api/models.rs b/rust/apps/cli/src/api/models.rsindex 0980c1aca7..d393007def 100644--- a/rust/apps/cli/src/api/models.rs+++ b/rust/apps/cli/src/api/models.rs@@ -3,8 +3,6 @@ use std::fmt;use serde::{Deserialize, Serialize};use uuid::Uuid;-// ========== Authentication Models ==========-fn default_email_mfa_enabled() -> bool {true}@@ -266,8 +264,6 @@ impl fmt::Debug for EnableTwoFactorRequest {}}-// ========== User Models ==========-#[derive(Debug, Deserialize)]#[serde(rename_all = "camelCase")]pub struct UserDetails {@@ -321,8 +317,6 @@ pub struct Storage {pub used: i64,}-// ========== Collection Models ==========-#[derive(Debug, Deserialize, Serialize, Clone)]#[serde(rename_all = "camelCase")]pub struct Collection {@@ -387,8 +381,6 @@ pub struct GetCollectionsResponse {pub collections: Vec<Collection>,}-// ========== File Models ==========-#[derive(Debug, Deserialize, Serialize, Clone)]#[serde(rename_all = "camelCase")]pub struct File {@@ -453,8 +445,6 @@ pub struct GetFileResponse {pub file: File,}-// ========== Diff/Sync Models ==========-#[derive(Debug, Serialize)]#[serde(rename_all = "camelCase")]pub struct GetDiffRequest {@@ -469,8 +459,6 @@ pub struct GetDiffResponse {pub has_more: bool,}-// ========== Download Models ==========-#[derive(Debug, Deserialize)]pub struct GetFileUrlResponse {pub url: String,diff --git a/rust/apps/cli/src/commands/export.rs b/rust/apps/cli/src/commands/export.rsindex d708aabe22..f745ea0831 100644--- a/rust/apps/cli/src/commands/export.rs+++ b/rust/apps/cli/src/commands/export.rs@@ -17,16 +17,12 @@ use std::path::{Path, PathBuf};use tokio::fs;use tokio::io::AsyncWriteExt;-/// Information about a file already on disk, loaded from metadata#[derive(Debug, Clone)]struct ExistingFile {- /// Path to the actual file on diskfile_path: PathBuf,- /// Path to the metadata JSON filemeta_path: PathBuf,}-/// Load existing file metadata for a specific albumasync fn load_album_metadata(export_path: &Path,album_name: &str,@@ -49,7 +45,6 @@ async fn load_album_metadata(while let Some(entry) = entries.next_entry().await? {let meta_path = entry.path();- // Skip non-JSON files and album_meta.jsonif meta_path.extension().is_none_or(|ext| ext != "json") {continue;}@@ -61,7 +56,6 @@ async fn load_album_metadata(continue;}- // Read and parse metadata filelet json_content = match fs::read_to_string(&meta_path).await {Ok(content) => content,Err(e) => {@@ -78,7 +72,6 @@ async fn load_album_metadata(}};- // Check if the actual file existsfor filename in &disk_metadata.info.file_names {let filename = validate_stored_file_name(filename)?;let file_path = export_path.join(album_name).join(filename);@@ -90,7 +83,7 @@ async fn load_album_metadata(meta_path: meta_path.clone(),},);- break; // Only need one existing file per ID+ break;}}}@@ -99,15 +92,11 @@ async fn load_album_metadata(}pub async fn run_export(account_email: Option<String>, filter: ExportFilter) -> Result<()> {- // Initialize crypto- // Open databaselet config_dir = crate::utils::get_cli_config_dir()?;let db_path = config_dir.join("ente.db");let storage = Storage::new(&db_path)?;- // Get accounts to exportlet accounts = if let Some(email) = account_email {- // Export specific account - try to find it with any applet all_accounts = storage.accounts().list()?;log::debug!("Found {} total accounts", all_accounts.len());let matching: Vec<Account> = all_accounts@@ -122,7 +111,6 @@ pub async fn run_export(account_email: Option<String>, filter: ExportFilter) ->}matching} else {- // Export all accountsstorage.accounts().list()?};@@ -131,7 +119,6 @@ pub async fn run_export(account_email: Option<String>, filter: ExportFilter) ->return Ok(());}- // Apply email filter at account level (matching Go CLI behavior)let accounts_to_export: Vec<Account> = if let Some(ref emails) = filter.emails {if emails.is_empty() {accounts@@ -158,12 +145,10 @@ pub async fn run_export(account_email: Option<String>, filter: ExportFilter) ->return Ok(());}- // Export each accountlet mut failures = 0;for account in accounts_to_export {println!("\n=== Exporting account: {} ===", account.email);- // First sync the account (like Go implementation does)println!("Syncing account data...");if let Err(e) = sync_account_before_export(&storage, &account).await {log::error!("Failed to sync account {}: {}", account.email, e);@@ -191,31 +176,24 @@ pub async fn run_export(account_email: Option<String>, filter: ExportFilter) ->}async fn sync_account_before_export(storage: &Storage, account: &Account) -> Result<()> {- // Get stored secretslet secrets = storage.accounts().get_secrets(account.user_id, account.app)?.ok_or_else(|| crate::Error::NotFound("Account secrets not found".into()))?;- // Create API client with account's endpointlet api_client = AppClient::new(Some(account.endpoint.clone()), account.app)?;- // Store token for this accountlet token = b64::encode_url_safe(&secrets.token);api_client.set_token(&token);- // Get the database path to create a new Storage instancelet db_path = storage.db_path().ok_or_else(|| crate::Error::Generic("Database path not available".into()))?;- // Create new Storage instance for sync engine (needed for ownership)let sync_storage = Storage::new(db_path)?;- // Create sync enginelet sync_engine = SyncEngine::new(api_client, sync_storage, account.clone());- // Run sync for this accountlet stats = sync_engine.sync().await?;log::info!(@@ -228,7 +206,6 @@ async fn sync_account_before_export(storage: &Storage, account: &Account) -> Res}async fn export_account(storage: &Storage, account: &Account, filter: &ExportFilter) -> Result<()> {- // Get export directorylet export_dir = account.export_dir.as_ref()@@ -237,33 +214,25 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFilprintln!("Export directory: {export_dir}");- // Create export directory if neededfs::create_dir_all(export_path).await?;- // Track exported hashes for deduplication within this export sessionlet mut exported_hashes: HashMap<String, PathBuf> = HashMap::new();- // Track albums that have metadata writtenlet mut albums_with_metadata: HashMap<String, bool> = HashMap::new();- // Track file indices per album for unique metadata filenameslet mut album_file_indices: HashMap<String, usize> = HashMap::new();- // Track existing files per album (loaded on demand)let mut album_existing_files: HashMap<String, HashMap<i64, ExistingFile>> = HashMap::new();- // Get stored secretslet secrets = storage.accounts().get_secrets(account.user_id, account.app)?.ok_or_else(|| crate::Error::NotFound("Account secrets not found".into()))?;- // Create API client with account's endpointlet api_client = AppClient::new(Some(account.endpoint.clone()), account.app)?;- // Store token for this account- // Token is stored as raw bytes from sealed_box_open- // The Go CLI encodes it as base64 URL-encoded string WITH padding for the API+ // The decrypted token is raw bytes. The API expects padded URL-safe base64,+ // matching the Go CLI.let token = b64::encode_url_safe(&secrets.token);api_client.set_token(&token);@@ -272,26 +241,21 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFil// Master key is already raw bytes, no need to decodelet master_key = &secrets.master_key;- // We'll also need the secret key and public key for decrypting shared collection keyslet secret_key = &secrets.secret_key;let public_key = &secrets.public_key;- // Step 1: Fetch all collections and create a map of collection IDs to collectionsprintln!("\nFetching collections...");let collections = api.get_collections(0).await?;println!("Found {} collections", collections.len());- // Create collection ID to collection map and decrypt collection keyslet mut collection_map: HashMap<i64, (crate::api::models::Collection, Vec<u8>)> =HashMap::new();for mut collection in collections {- // Skip deleted collectionsif collection.is_deleted {continue;}- // Log collection processing (with better handling of empty owner email)let owner_info = if collection.owner.email.is_empty() {format!("owner_id={}", collection.owner.id)} else {@@ -306,12 +270,9 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFilowner_info);- // Decrypt collection key- // Collections can be encrypted in two ways:- // 1. Owned collections: Use secret_box with master key and nonce- // 2. Shared collections: Use sealed_box with public key cryptography+ // Owned collection keys use secretbox with the master key.+ // Collections shared with us use sealed box.let collection_key = if let Some(ref key_nonce) = collection.key_decryption_nonce {- // Owned collection - decrypt with master keymatch decrypt_collection_key(&collection.encrypted_key,key_nonce,@@ -328,7 +289,6 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFil}}} else {- // Shared collection - check if it's shared with us (not by us)if collection.owner.id == account.user_id {log::warn!("Collection {} owned by current user but missing key_decryption_nonce, skipping",@@ -337,7 +297,6 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFilcontinue;}- // This is a collection shared with us - decrypt with sealed_boxlog::info!("Collection {} is shared from user {}, using sealed_box decryption",collection.id,@@ -356,7 +315,6 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFil}};- // Decrypt collection name if it's encryptedif collection.name.as_ref().is_none_or(|n| n.is_empty())&& let Some(ref encrypted_name) = collection.encrypted_name&& let Some(ref nonce) = collection.name_decryption_nonce@@ -375,11 +333,9 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFilcollection_map.insert(collection.id, (collection, collection_key));}- // Step 2: Fetch all files from all collections (like Go CLI does)println!("\nFetching all files...");let mut all_files = Vec::new();- // Iterate through each collection and fetch its filesfor collection_id in collection_map.keys() {let mut has_more = true;let mut since_time = 0i64;@@ -392,7 +348,6 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFilbreak;}- // Update since_time for next batchfor file in &files {if file.updation_time > since_time {since_time = file.updation_time;@@ -405,24 +360,19 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFilprintln!("Found {} total files", all_files.len());- // Step 3: Process each file and export to the correct album folderlet mut total_files = 0;let mut exported_files = 0;let mut skipped_files = 0;let mut deleted_files = 0;for file in all_files {- // Skip deleted filesif file.is_deleted {deleted_files += 1;continue;}- // Count non-deleted filestotal_files += 1;- // Find the collection this file belongs to- // Files have a collection_id field that indicates which album they belong tolet collection_info = match collection_map.get(&file.collection_id) {Some(info) => info,None => {@@ -437,18 +387,14 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFillet (collection, collection_key) = collection_info;- // Apply collection filterslet collection_name = collection.name.as_deref().unwrap_or("Unnamed");- // Determine if collection is sharedlet is_shared = collection.sharees.as_ref().is_some_and(|s| !s.is_empty())|| collection.shared_magic_metadata.is_some()|| collection.owner.id != account.user_id;- // Determine if collection is hidden from metadatalet is_hidden = check_collection_visibility(collection, collection_key);- // Log collection visibility for debugginglog::debug!("Collection {}: name={:?}, is_hidden={}, is_shared={}",collection.id,@@ -462,7 +408,6 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFilcontinue;}- // Decrypt the file key using the collection keylet file_key = match decrypt_file_key(&file.encrypted_key,&file.key_decryption_nonce,@@ -475,7 +420,6 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFil}};- // Decrypt metadata to get original filename and hashlet metadata = match decrypt_file_metadata(&file, &file_key) {Ok(meta) => meta,Err(e) => {@@ -484,7 +428,6 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFil}};- // Decrypt public magic metadata to check for edited namelet pub_magic_metadata = if let Some(pub_magic_metadata) = file.pub_magic_metadata.as_ref(){match decrypt_magic_metadata(pub_magic_metadata, &file_key) {@@ -502,7 +445,6 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFilNone};- // Check for deduplication by hashlet content_hash = if let Some(ref meta) = metadata {let hash = match meta.get_file_type() {crate::models::metadata::FileType::Image => {@@ -524,7 +466,6 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFilNone};- // Generate export path with original filename from metadatalet file_path = generate_export_path(export_path,&file,@@ -533,7 +474,6 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFilpub_magic_metadata.as_ref(),)?;- // Determine album folderlet album_folder = if let Some(ref name) = collection.name&& !name.is_empty(){@@ -542,7 +482,6 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFil"Uncategorized".to_string()};- // Load existing files for this album if not already loadedif !album_existing_files.contains_key(&album_folder) {let existing = load_album_metadata(export_path, &album_folder).await?;log::debug!(@@ -553,11 +492,9 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFilalbum_existing_files.insert(album_folder.clone(), existing);}- // Check if this file already exists in the album by ID (for rename detection)let existing_files = album_existing_files.get_mut(&album_folder).unwrap();if let Some(existing) = existing_files.remove(&file.id) {if existing.file_path == file_path {- // File exists at the same path - no rename neededlog::debug!("File {} already exists at correct path: {:?}",file.id,@@ -565,13 +502,11 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFil);skipped_files += 1;- // Add to hash map even for existing files to prevent duplicatesif let Some(hash) = content_hash {exported_hashes.insert(hash.clone(), file_path.clone());}continue;} else {- // File exists at different path - it was renamedlog::info!("File {} renamed from {:?} to {:?}",file.id,@@ -579,28 +514,23 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFilfile_path);- // Remove old fileif existing.file_path.exists() {log::debug!("Removing old file: {:?}", existing.file_path);fs::remove_file(&existing.file_path).await.ok();}- // For live photos, also remove the MOV componentlet is_live_photo = metadata.as_ref().map(|m| m.is_live_photo()).unwrap_or(false);if is_live_photo {- // Try to remove old MOV file- // The MOV file has the same base name but with .MOV extensionlet old_mov_path = existing.file_path.with_extension("MOV");if old_mov_path.exists() {log::debug!("Removing old live photo MOV component: {:?}", old_mov_path);fs::remove_file(&old_mov_path).await.ok();}- // Also try lowercase .movlet old_mov_path_lower = existing.file_path.with_extension("mov");if old_mov_path_lower.exists() && old_mov_path_lower != old_mov_path {log::debug!(@@ -611,28 +541,21 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFil}}- // Remove old metadataif existing.meta_path.exists() {log::debug!("Removing old metadata: {:?}", existing.meta_path);fs::remove_file(&existing.meta_path).await.ok();}-- // Continue to re-export with new name}} else if file_path.exists() {- // File exists but not tracked by ID (old export or hash collision)log::debug!("File already exists (not tracked by ID): {file_path:?}");skipped_files += 1;- // Add to hash map even for existing files to prevent duplicatesif let Some(hash) = content_hash {exported_hashes.insert(hash.clone(), file_path.clone());}continue;}- // Check if we've already downloaded this file content (by hash) in another album- // If so, we can copy it instead of downloading againlet need_download = if let Some(hash) = content_hash&& let Some(existing_path) = exported_hashes.get(hash)&& existing_path != &file_path@@ -643,20 +566,17 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFilexisting_path.display());- // Copy the existing file to the new locationif let Some(parent) = file_path.parent() {fs::create_dir_all(parent).await?;}fs::copy(existing_path, &file_path).await?;- // For live photos, also copy the MOV componentlet is_live_photo = metadata.as_ref().map(|m| m.is_live_photo()).unwrap_or(false);if is_live_photo {- // Try to copy MOV filelet existing_mov = existing_path.with_extension("MOV");let new_mov = file_path.with_extension("MOV");if existing_mov.exists() {@@ -667,7 +587,6 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFil);fs::copy(&existing_mov, &new_mov).await.ok();} else {- // Try lowercase .movlet existing_mov_lower = existing_path.with_extension("mov");let new_mov_lower = file_path.with_extension("mov");if existing_mov_lower.exists() {@@ -686,16 +605,13 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFiltrue};- // Download and save file only if neededif need_download {log::debug!("Downloading file {} to {:?}", file.id, file_path);- // Ensure directory existsif let Some(parent) = file_path.parent() {fs::create_dir_all(parent).await?;}- // Download encrypted filelet encrypted_data = api.download_file(file.id).await?;// The file nonce/header is stored separately in the API response@@ -707,8 +623,6 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFil}};- // Decrypt the file data using streaming XChaCha20-Poly1305- // Use chunked decryption for large fileslet decrypt_result = crypto::Header::try_from_slice(&file_nonce).and_then(|header| {crypto::stream::decrypt_file_data(&encrypted_data,@@ -729,14 +643,12 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFil}};- // Check if this is a live photo that needs extractionlet is_live_photo = metadata.as_ref().map(|m| m.is_live_photo()).unwrap_or(false);if is_live_photo {- // Extract live photo components from ZIPif let Err(e) = extract_live_photo(&decrypted, &file_path).await {log::error!("Failed to extract live photo {}: {}", file.id, e);// Fall back to saving as ZIP@@ -745,7 +657,6 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFilfile_handle.sync_all().await?;}} else {- // Write regular filelet mut file_handle = fs::File::create(&file_path).await?;file_handle.write_all(&decrypted).await?;file_handle.sync_all().await?;@@ -754,21 +665,17 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFilexported_files += 1;- // Add hash to deduplication mapif let Some(hash) = content_hash {exported_hashes.insert(hash.clone(), file_path.clone());}- // Write album metadata if not already written for this albumif !albums_with_metadata.contains_key(&album_folder) {write_album_metadata(export_path, &album_folder, collection, account.user_id).await?;albums_with_metadata.insert(album_folder.clone(), true);}- // Get and increment file index for this albumlet file_index = album_file_indices.entry(album_folder.clone()).or_insert(0);- // Write file metadatalet filename = file_path.file_name().and_then(|n| n.to_str())@@ -783,20 +690,15 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFil).await?;- // Note: We don't add newly exported files to album_existing_files- // That map is only for tracking files that existed before this export- // and need to be checked for deletion+ // Keep this map limited to pre-existing files; leftovers are deleted below.*file_index += 1;- // Progress indicator - show every 10 files for better UXif exported_files % 10 == 0 || exported_files == 1 {println!(" [{}/{}] Exported files...", exported_files, total_files);}}- // Clean up deleted files that are still on disk- // Any files remaining in album_existing_files were not seen during export (deleted)let mut removed_files = 0;for (album_name, remaining_files) in album_existing_files {for (file_id, existing_file) in remaining_files {@@ -807,7 +709,6 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFilexisting_file.file_path);- // Remove the actual fileif existing_file.file_path.exists() {if let Err(e) = fs::remove_file(&existing_file.file_path).await {log::warn!(@@ -820,21 +721,18 @@ async fn export_account(storage: &Storage, account: &Account, filter: &ExportFil}}- // For live photos, also remove the MOV componentlet mov_path = existing_file.file_path.with_extension("MOV");if mov_path.exists() {log::debug!("Removing live photo MOV component: {:?}", mov_path);fs::remove_file(&mov_path).await.ok();}- // Also try lowercase .movlet mov_path_lower = existing_file.file_path.with_extension("mov");if mov_path_lower.exists() && mov_path_lower != mov_path {log::debug!("Removing live photo mov component: {:?}", mov_path_lower);fs::remove_file(&mov_path_lower).await.ok();}- // Remove the metadata fileif existing_file.meta_path.exists() {log::debug!("Removing metadata for deleted file: {:?}",@@ -896,27 +794,21 @@ fn generate_export_path(metadata: Option<&FileMetadata>,pub_magic_metadata: Option<&serde_json::Value>,) -> Result<PathBuf> {- // Start with export directorylet mut path = export_dir.to_path_buf();// Match Go CLI structure: export_dir/AlbumName/filename- // Use collection/album name as folder, or "Uncategorized" if nonelet album_folder = if let Some(col) = collection&& let Some(ref name) = col.name&& !name.is_empty(){- // Sanitize collection name for filesystem (matching Go's approach)sanitize_album_name(name)} else {- // Files without a collection go to "Uncategorized" (matching Go CLI)"Uncategorized".to_string()};path.push(album_folder);- // Use filename from public magic metadata (edited name) or regular metadatalet filename = {- // First check for edited name in public magic metadataif let Some(pub_meta) = pub_magic_metadata&& let Some(edited_name) = pub_meta.get("editedName")&& let Some(name_str) = edited_name.as_str()@@ -924,18 +816,15 @@ fn generate_export_path({sanitize_filename(name_str)} else if let Some(meta) = metadata {- // Fall back to original title from metadataif let Some(title) = meta.get_title() {sanitize_filename(title)} else {- // Match Go CLI behavior: error if no title foundreturn Err(crate::Error::Generic(format!("File {} has no title in metadata",file.id)));}} else {- // Match Go CLI behavior: error if no metadatareturn Err(crate::Error::Generic(format!("File {} has no metadata",file.id@@ -947,7 +836,6 @@ fn generate_export_path(Ok(path)}-/// Decrypt a collection key using the master keyfn decrypt_collection_key(encrypted_key: &str,nonce: &str,@@ -957,7 +845,6 @@ fn decrypt_collection_key(let encrypted_bytes = b64::decode(encrypted_key)?;let nonce_bytes = b64::decode(nonce)?;- // Collection keys are encrypted with secret_box (XSalsa20-Poly1305) using master keyOk(crypto::secretbox::decrypt(&encrypted_bytes,&crypto::Nonce::try_from_slice(&nonce_bytes)?,@@ -965,7 +852,6 @@ fn decrypt_collection_key()?)}-/// Decrypt a shared collection key using public key cryptography (sealed box)fn decrypt_shared_collection_key(encrypted_key: &str,public_key: &[u8],@@ -973,8 +859,6 @@ fn decrypt_shared_collection_key() -> Result<Vec<u8>> {let encrypted_bytes = b64::decode(encrypted_key)?;- // Shared collection keys are encrypted with sealed_box (crypto_box_seal)- // which uses the recipient's public key and an ephemeral keypairOk(crypto::sealed::open(&encrypted_bytes,&crypto::PublicKey::try_from_slice(public_key)?,@@ -982,7 +866,6 @@ fn decrypt_shared_collection_key()?)}-/// Decrypt a collection name using the collection keyfn decrypt_collection_name(encrypted_name: &str,nonce: &str,@@ -991,24 +874,20 @@ fn decrypt_collection_name(let encrypted_bytes = b64::decode(encrypted_name)?;let nonce_bytes = b64::decode(nonce)?;- // Collection names are encrypted with secret_box using the collection keylet decrypted = crypto::secretbox::decrypt(&encrypted_bytes,&crypto::Nonce::try_from_slice(&nonce_bytes)?,&crypto::Key::try_from_slice(collection_key)?,)?;- // Convert to stringString::from_utf8(decrypted).map_err(|e| crate::Error::Generic(format!("Invalid UTF-8 in collection name: {}", e)))}-/// Decrypt a file key using the collection keyfn decrypt_file_key(encrypted_key: &str, nonce: &str, collection_key: &[u8]) -> Result<Vec<u8>> {let encrypted_bytes = b64::decode(encrypted_key)?;let nonce_bytes = b64::decode(nonce)?;- // File keys are encrypted with secret_box (XSalsa20-Poly1305) using collection keyOk(crypto::secretbox::decrypt(&encrypted_bytes,&crypto::Nonce::try_from_slice(&nonce_bytes)?,@@ -1016,9 +895,7 @@ fn decrypt_file_key(encrypted_key: &str, nonce: &str, collection_key: &[u8]) ->)?)}-// Removed generate_fallback_filename - Go CLI panics if no title, we return error instead--/// Reduce a sanitized name to a single path component, never `.`, `..`, or empty.+// Reduce a sanitized name to one path component, never `.`, `..`, or empty.fn safe_path_component(name: String) -> String {let trimmed = name.trim();if trimmed.is_empty() || trimmed == "." || trimmed == ".." {@@ -1039,7 +916,6 @@ fn validate_stored_file_name(name: &str) -> Result<&str> {}}-/// Sanitize a filename for the filesystemfn sanitize_filename(name: &str) -> String {let sanitized = name.chars()@@ -1053,7 +929,6 @@ fn sanitize_filename(name: &str) -> String {safe_path_component(sanitized)}-/// Sanitize an album/collection name into a safe single path componentfn sanitize_album_name(name: &str) -> String {let sanitized = name.chars()@@ -1067,12 +942,10 @@ fn sanitize_album_name(name: &str) -> String {safe_path_component(sanitized)}-/// Decrypt file metadatafn decrypt_file_metadata(file: &crate::api::models::File,file_key: &[u8],) -> Result<Option<FileMetadata>> {- // Check if metadata existsif file.metadata.encrypted_data.is_none() || file.metadata.decryption_header.is_empty() {return Ok(None);}@@ -1081,24 +954,20 @@ fn decrypt_file_metadata(let encrypted_bytes = b64::decode(encrypted_data)?;let header_bytes = b64::decode(&file.metadata.decryption_header)?;- // Decrypt the metadata using streaming XChaCha20-Poly1305let decrypted = crypto::blob::decrypt(&encrypted_bytes,&crypto::Header::try_from_slice(&header_bytes)?,&crypto::Key::try_from_slice(file_key)?,)?;- // Parse JSON metadatalet metadata: FileMetadata = serde_json::from_slice(&decrypted)?;Ok(Some(metadata))}-/// Decrypt magic metadata (public or private)fn decrypt_magic_metadata(magic_metadata: &crate::api::models::MagicMetadata,file_key: &[u8],) -> Result<Option<serde_json::Value>> {- // Check if data existsif magic_metadata.data.is_empty() || magic_metadata.header.is_empty() {return Ok(None);}@@ -1106,19 +975,16 @@ fn decrypt_magic_metadata(let encrypted_bytes = b64::decode(&magic_metadata.data)?;let header_bytes = b64::decode(&magic_metadata.header)?;- // Decrypt the metadata using streaming XChaCha20-Poly1305let decrypted = crypto::blob::decrypt(&encrypted_bytes,&crypto::Header::try_from_slice(&header_bytes)?,&crypto::Key::try_from_slice(file_key)?,)?;- // Parse as generic JSON since magic metadata structure can varylet metadata: serde_json::Value = serde_json::from_slice(&decrypted)?;Ok(Some(metadata))}-/// Check if a collection is hidden based on its metadatafn check_collection_visibility(collection: &crate::api::models::Collection,collection_key: &[u8],@@ -1144,7 +1010,6 @@ fn check_collection_visibility(false}-/// Write album metadata to .meta/album_meta.jsonasync fn write_album_metadata(export_path: &Path,album_folder: &str,@@ -1171,7 +1036,6 @@ async fn write_album_metadata(Ok(())}-/// Write file metadata to .meta folderasync fn write_file_metadata(export_path: &Path,album_folder: &str,@@ -1183,8 +1047,6 @@ async fn write_file_metadata(let meta_dir = export_path.join(album_folder).join(".meta");fs::create_dir_all(&meta_dir).await?;- // Generate unique metadata filename- // At this point, filename should always be valid since we error out earlier if notlet base_name = Path::new(filename).file_stem().and_then(|s| s.to_str())@@ -1194,7 +1056,6 @@ async fn write_file_metadata(.and_then(|s| s.to_str()).unwrap_or(""); // Extension might be legitimately missing for some files- // Create metadata filename like "IMG_1234.jpg_0.json"let meta_filename = format!("{}_{}.{}.json", base_name, file_index, extension);let mut disk_metadata = DiskFileMetadata::from_file(file, metadata, filename.to_string());diff --git a/rust/apps/cli/src/commands/sync.rs b/rust/apps/cli/src/commands/sync.rsindex a3f4742a6f..85c3477bfa 100644--- a/rust/apps/cli/src/commands/sync.rs+++ b/rust/apps/cli/src/commands/sync.rs@@ -14,15 +14,11 @@ pub async fn run_sync(metadata_only: bool,full_sync: bool,) -> Result<()> {- // Initialize crypto- // Open databaselet config_dir = crate::utils::get_cli_config_dir()?;let db_path = config_dir.join("ente.db");let storage = Storage::new(&db_path)?;- // Get accounts to synclet accounts = if let Some(email) = account_email {- // Sync specific accountlet all_accounts = storage.accounts().list()?;let matching: Vec<Account> = all_accounts.into_iter()@@ -36,7 +32,6 @@ pub async fn run_sync(}matching} else {- // Sync all accountsstorage.accounts().list()?};@@ -45,7 +40,6 @@ pub async fn run_sync(return Ok(());}- // Sync each accountfor account in accounts {println!("\n=== Syncing account: {} ===", account.email);@@ -66,66 +60,51 @@ async fn sync_account(metadata_only: bool,full_sync: bool,) -> Result<()> {- // Get stored secretslet secrets = storage.accounts().get_secrets(account.user_id, account.app)?.ok_or_else(|| crate::Error::NotFound("Account secrets not found".into()))?;- // Create API client with account's endpointlet api_client = AppClient::new(Some(account.endpoint.clone()), account.app)?;- // Store token for this accountlet token = b64::encode_url_safe(&secrets.token);api_client.set_token(&token);- // Clear sync state if full sync requestedif full_sync {println!("Performing full sync (clearing existing sync state)...");storage.sync().clear_sync_state(account.user_id)?;}- // Create sync engine (need to create new instances for ownership)let db_path = storage.db_path().ok_or_else(|| crate::Error::Generic("Database path not available".into()))?;- // Create API client for sync enginelet sync_api_client = AppClient::new(Some(account.endpoint.clone()), account.app)?;sync_api_client.set_token(&token);let sync_storage = Storage::new(db_path)?;let sync_engine = SyncEngine::new(sync_api_client, sync_storage, account.clone());- // Run syncprintln!("Fetching collections and files...");let stats = sync_engine.sync().await?;- // Display sync statisticsdisplay_sync_stats(&stats);- // Download files if not metadata-onlyif !metadata_only {- // Get pending downloadslet pending_files = storage.sync().get_pending_downloads(account.user_id)?;if !pending_files.is_empty() {println!("\nπ₯ Found {} files to download", pending_files.len());- // Get collections to decrypt collection keys- // Need to fetch from API to get the api::models::Collection type with encrypted_keylet api = ApiMethods::new(&api_client);let api_collections = api.get_collections(0).await?;- // Decrypt collection keyslet collection_keys = decrypt_collection_keys(&api_collections,&secrets.master_key,&secrets.secret_key,)?;- // Create download manager- // Create a new API client for the download managerlet download_api_client =AppClient::new(Some(account.endpoint.clone()), account.app)?;download_api_client.set_token(&token);@@ -133,14 +112,12 @@ async fn sync_account(let mut download_manager = DownloadManager::new(download_api_client)?;download_manager.set_collection_keys(collection_keys);- // Determine export directorylet export_dir = if let Some(ref dir) = account.export_dir {PathBuf::from(dir)} else {std::env::current_dir()?.join("ente-export")};- // Prepare download tasks with proper pathslet download_tasks = prepare_download_tasks(&pending_files,&export_dir,@@ -149,13 +126,11 @@ async fn sync_account().await?;- // First, mark files that already exist as syncedlet mut already_synced = 0;let mut to_download = Vec::new();for (file, path) in download_tasks {if path.exists() {- // File already exists, mark it as synced in databasestorage.sync().mark_file_synced(file.id, Some(path.to_str().unwrap_or("")))?;@@ -172,10 +147,8 @@ async fn sync_account(if !to_download.is_empty() {println!("π₯ Downloading {} new files", to_download.len());- // Download files with progress barlet download_stats = download_manager.download_files(to_download).await?;- // Update local paths in database for newly downloaded filesfor (file, path) in &download_stats.successful_downloads {storage.sync()@@ -229,7 +202,6 @@ fn display_sync_stats(stats: &SyncStats) {println!("βββββββββββββββββββββββββββββββββββββββ");}-/// Decrypt collection keys for file decryptionfn decrypt_collection_keys(collections: &[crate::api::models::Collection],master_key: &[u8],@@ -243,7 +215,6 @@ fn decrypt_collection_keys(continue;}- // Decrypt collection keylet encrypted_bytes = b64::decode(&collection.encrypted_key)?;let nonce_bytes = b64::decode(&collection.key_decryption_nonce)?;@@ -271,7 +242,6 @@ fn decrypt_collection_keys(Ok(keys)}-/// Sanitize a filename for the filesystemfn sanitize_filename(name: &str) -> String {name.chars().map(|c| match c {@@ -285,7 +255,6 @@ fn sanitize_filename(name: &str) -> String {.to_string()}-/// Prepare download tasks with proper file pathsasync fn prepare_download_tasks(files: &[crate::models::file::RemoteFile],export_dir: &Path,@@ -297,19 +266,15 @@ async fn prepare_download_tasks(let mut tasks = Vec::new();let mut seen_hashes: HashMap<String, PathBuf> = HashMap::new();- // Create collection lookup maplet collection_map: HashMap<i64, &crate::api::models::Collection> =collections.iter().map(|c| (c.id, c)).collect();for file in files {- // Get collection for this filelet collection = collection_map.get(&file.collection_id);- // Try to decrypt metadata to get original filenamelet (metadata, pub_magic_metadata) = if let Some(col_key) =download_manager.collection_keys.get(&file.collection_id){- // Decrypt file key firstlet file_key = {let key_bytes = b64::decode(&file.encrypted_key)?;let nonce = b64::decode(&file.key_decryption_nonce)?;@@ -320,7 +285,6 @@ async fn prepare_download_tasks()?};- // Decrypt regular metadatalet regular_meta = if !file.metadata.encrypted_data.is_empty() {if !file.metadata.decryption_header.is_empty() {let encrypted_bytes = b64::decode(&file.metadata.encrypted_data)?;@@ -348,7 +312,6 @@ async fn prepare_download_tasks(None};- // Decrypt public magic metadata if availablelet pub_meta = if let Some(ref magic) = file.pub_magic_metadata {if !magic.data.is_empty() && !magic.header.is_empty() {let encrypted_bytes = b64::decode(&magic.data)?;@@ -387,10 +350,8 @@ async fn prepare_download_tasks((None, None)};- // Generate export pathlet mut path = export_dir.to_path_buf();- // Add date-based directory structurelet datetime = Utc.timestamp_micros(file.updated_at).single()@@ -402,7 +363,6 @@ async fn prepare_download_tasks(path.push(year);path.push(month);- // Add collection name if availableif let Some(col) = collection&& let Some(ref name) = col.name&& !name.is_empty()@@ -419,9 +379,7 @@ async fn prepare_download_tasks(path.push(safe_name.trim());}- // Use filename from public magic metadata (edited name) or regular metadatalet filename = {- // First check for edited name in public magic metadatalet base_name = if let Some(ref pub_meta) = pub_magic_metadata&& let Some(edited_name) = pub_meta.get("editedName")&& let Some(name_str) = edited_name.as_str()@@ -429,7 +387,6 @@ async fn prepare_download_tasks({sanitize_filename(name_str)} else if let Some(ref meta) = metadata {- // Fall back to original title from metadataif let Some(title) = meta.get_title() {sanitize_filename(title)} else {@@ -443,10 +400,8 @@ async fn prepare_download_tasks(continue; // Skip this file};- // For live photos, ensure .zip extension if not already presentif let Some(ref meta) = metadata {if meta.is_live_photo() && !base_name.to_lowercase().ends_with(".zip") {- // Remove any existing extension and add .zipif let Some(pos) = base_name.rfind('.') {format!("{}.zip", &base_name[..pos])} else {@@ -462,7 +417,6 @@ async fn prepare_download_tasks(path.push(filename);- // Check for deduplication by hashlet content_hash = if let Some(ref meta) = metadata {match meta.get_file_type() {crate::models::metadata::FileType::Image => {@@ -477,7 +431,6 @@ async fn prepare_download_tasks(None};- // Skip if we've already seen this hash (duplicate)if let Some(hash) = content_hash {if let Some(existing_path) = seen_hashes.get(hash) {log::info!(diff --git a/rust/apps/cli/src/models/export_metadata.rs b/rust/apps/cli/src/models/export_metadata.rsindex 2847d41730..d11ead2c61 100644--- a/rust/apps/cli/src/models/export_metadata.rs+++ b/rust/apps/cli/src/models/export_metadata.rs@@ -1,7 +1,7 @@use chrono::{DateTime, Local, TimeZone};use serde::{Deserialize, Deserializer, Serialize, Serializer};-/// Custom serializer for timestamp fields to match Go CLI's ISO 8601 format+// Match the Go CLI's ISO 8601 timestamp format.fn serialize_timestamp_as_iso8601<S>(timestamp_micros: &i64,serializer: S,@@ -17,13 +17,11 @@ where.single().ok_or_else(|| serde::ser::Error::custom("Invalid timestamp"))?;- // Format with milliseconds and timezone offset (matching Go CLI format)let iso_string = datetime.to_rfc3339_opts(chrono::SecondsFormat::Millis, true);serializer.serialize_str(&iso_string)}-/// Custom deserializer that can handle both i64 and ISO string timestampsfn deserialize_timestamp_from_iso_or_i64<'de, D>(deserializer: D) -> Result<i64, D::Error>whereD: Deserializer<'de>,@@ -39,16 +37,12 @@ wherematch TimestampFormat::deserialize(deserializer)? {TimestampFormat::Microseconds(micros) => Ok(micros),- TimestampFormat::IsoString(s) => {- // Parse ISO string back to microseconds- DateTime::parse_from_rfc3339(&s)- .map(|dt| dt.timestamp_micros())- .map_err(|e| Error::custom(format!("Invalid ISO timestamp: {}", e)))- }+ TimestampFormat::IsoString(s) => DateTime::parse_from_rfc3339(&s)+ .map(|dt| dt.timestamp_micros())+ .map_err(|e| Error::custom(format!("Invalid ISO timestamp: {}", e))),}}-/// Album metadata matching Go's export.AlbumMetadata structure#[derive(Debug, Clone, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct AlbumMetadata {@@ -57,10 +51,8 @@ pub struct AlbumMetadata {pub owner_id: i64,pub album_name: String,pub is_deleted: bool,- /// Account IDs that own this album (for shared export directories)#[serde(rename = "accountOwnerIDs")]pub account_owner_ids: Vec<i64>,- /// Folder name on disk (excluded from JSON)#[serde(skip)]pub folder_name: String,}@@ -78,7 +70,6 @@ impl AlbumMetadata {}}-/// File metadata matching Go's export.DiskFileMetadata structure#[derive(Debug, Clone, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct DiskFileMetadata {@@ -91,19 +82,17 @@ pub struct DiskFileMetadata {serialize_with = "serialize_timestamp_as_iso8601",deserialize_with = "deserialize_timestamp_from_iso_or_i64")]- pub creation_time: i64, // Unix timestamp in microseconds (serialized as ISO 8601)+ pub creation_time: i64,#[serde(serialize_with = "serialize_timestamp_as_iso8601",deserialize_with = "deserialize_timestamp_from_iso_or_i64")]- pub modification_time: i64, // Unix timestamp in microseconds (serialized as ISO 8601)+ pub modification_time: i64,pub info: FileInfo,- /// Meta filename on disk (excluded from JSON)#[serde(skip)]pub meta_file_name: String,}-/// File info matching Go's export.Info structure#[derive(Debug, Clone, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct FileInfo {@@ -112,11 +101,9 @@ pub struct FileInfo {pub hash: Option<String>,#[serde(rename = "ownerID")]pub owner_id: i64,- /// Multiple filenames for live photos or burst photospub file_names: Vec<String>,}-/// Location metadata#[derive(Debug, Clone, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct Location {@@ -130,7 +117,6 @@ impl DiskFileMetadata {metadata: Option<&crate::models::metadata::FileMetadata>,filename: String,) -> Self {- // Extract metadata valueslet (title, location, creation_time) = if let Some(meta) = metadata {let title = meta.get_title().unwrap_or(&filename).to_string();let location = meta.latitude.and_then(|lat| {@@ -140,7 +126,6 @@ impl DiskFileMetadata {})});- // Use creation time from metadata if availablelet creation_time = meta.creation_time.unwrap_or(file.updation_time);(title, location, creation_time)@@ -150,12 +135,10 @@ impl DiskFileMetadata {(title, None, creation_time)};- // Use modification time from metadata or fall back to updation timelet modification_time = metadata.and_then(|m| m.modification_time).unwrap_or(file.updation_time);- // Get hash from metadatalet hash = metadata.and_then(|m| {m.hash.as_ref()@@ -166,7 +149,7 @@ impl DiskFileMetadata {Self {title,- description: None, // FileMetadata doesn't have description field+ description: None,location,creation_time,modification_time,diff --git a/rust/apps/cli/src/models/filter.rs b/rust/apps/cli/src/models/filter.rsindex 525bddaece..91b00d3e7d 100644--- a/rust/apps/cli/src/models/filter.rs+++ b/rust/apps/cli/src/models/filter.rs@@ -1,38 +1,29 @@-/// Export filter options#[derive(Debug, Clone, Default)]pub struct ExportFilter {- /// Include shared albumspub include_shared: bool,- /// Include hidden albumspub include_hidden: bool,- /// Specific album names to export (None means all)pub albums: Option<Vec<String>>,- /// Specific user emails to export files shared with (None means all)pub emails: Option<Vec<String>>,}impl ExportFilter {- /// Check if a collection should be included based on filterspub fn should_include_collection(&self,collection_name: &str,is_shared: bool,is_hidden: bool,) -> bool {- // Check shared filterif is_shared && !self.include_shared {return false;}- // Check hidden filterif is_hidden && !self.include_hidden {return false;}- // Check album name filterif let Some(ref albums) = self.albums&& !albums.is_empty()&& !albums.iter().any(|a| a == collection_name)@@ -43,7 +34,6 @@ impl ExportFilter {true}- /// Check if a file should be included based on email filterpub fn should_include_file_by_owner(&self, owner_email: Option<&str>) -> bool {if let Some(ref emails) = self.emails&& !emails.is_empty()diff --git a/rust/apps/cli/src/models/metadata.rs b/rust/apps/cli/src/models/metadata.rsindex 96ce37779b..95a5b99ac1 100644--- a/rust/apps/cli/src/models/metadata.rs+++ b/rust/apps/cli/src/models/metadata.rs@@ -2,7 +2,6 @@ use serde::{Deserialize, Serialize};use serde_json::Value;use std::collections::HashMap;-/// Decrypted file metadata#[derive(Debug, Clone, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct FileMetadata {@@ -23,12 +22,10 @@ pub struct FileMetadata {}impl FileMetadata {- /// Get the file title/namepub fn get_title(&self) -> Option<&str> {self.title.as_deref()}- /// Get the file typepub fn get_file_type(&self) -> FileType {match self.file_type {Some(0) => FileType::Image,@@ -38,7 +35,6 @@ impl FileMetadata {}}- /// Check if this is a live photopub fn is_live_photo(&self) -> bool {matches!(self.get_file_type(), FileType::LivePhoto)}@@ -52,7 +48,6 @@ pub enum FileType {Unknown = 127,}-/// Public metadata that can override certain fields#[derive(Debug, Clone, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct PublicMetadata {@@ -63,7 +58,6 @@ pub struct PublicMetadata {pub other: HashMap<String, Value>,}-/// Private metadata#[derive(Debug, Clone, Serialize, Deserialize)]pub struct PrivateMetadata {#[serde(flatten)]diff --git a/rust/apps/cli/src/storage/account.rs b/rust/apps/cli/src/storage/account.rsindex 32e3929065..76671a469f 100644--- a/rust/apps/cli/src/storage/account.rs+++ b/rust/apps/cli/src/storage/account.rs@@ -14,7 +14,6 @@ impl<'a> AccountStore<'a> {Self { conn }}- /// Add a new accountpub fn add(&self, account: &Account) -> Result<()> {let now = current_timestamp();@@ -35,7 +34,6 @@ impl<'a> AccountStore<'a> {Ok(())}- /// Get an account by email and apppub fn get(&self, email: &str, app: App) -> Result<Option<Account>> {let mut stmt = self.conn.prepare("SELECT user_id, app, email, endpoint, export_dir FROM accounts@@ -51,7 +49,6 @@ impl<'a> AccountStore<'a> {Ok(account)}- /// List all accountspub fn list(&self) -> Result<Vec<Account>> {let mut stmt = self.conn.prepare("SELECT user_id, app, email, endpoint, export_dir FROM accounts@@ -65,7 +62,6 @@ impl<'a> AccountStore<'a> {Ok(accounts)}- /// Update account export directorypub fn update_export_dir(&self, email: &str, app: App, export_dir: &str) -> Result<()> {let now = current_timestamp();@@ -85,7 +81,6 @@ impl<'a> AccountStore<'a> {Ok(())}- /// Delete an accountpub fn delete(&self, user_id: i64, app: App) -> Result<()> {let rows_affected = self.conn.execute("DELETE FROM accounts WHERE user_id = ?1 AND app = ?2",@@ -102,7 +97,6 @@ impl<'a> AccountStore<'a> {Ok(())}- /// Store account secrets (encrypted)pub fn store_secrets(&self, user_id: i64, app: App, secrets: &AccountSecrets) -> Result<()> {let now = current_timestamp();@@ -124,7 +118,6 @@ impl<'a> AccountStore<'a> {Ok(())}- /// Get account secretspub fn get_secrets(&self, user_id: i64, app: App) -> Result<Option<AccountSecrets>> {let mut stmt = self.conn.prepare("SELECT token, master_key, secret_key, public_key FROM secretsdiff --git a/rust/apps/cli/src/storage/config.rs b/rust/apps/cli/src/storage/config.rsindex 656cc0a4dd..275fb524cf 100644--- a/rust/apps/cli/src/storage/config.rs+++ b/rust/apps/cli/src/storage/config.rs@@ -11,7 +11,6 @@ impl<'a> ConfigStore<'a> {Self { conn }}- /// Set a configuration valuepub fn set(&self, key: &str, value: &str) -> Result<()> {let now = SystemTime::now().duration_since(UNIX_EPOCH)@@ -27,7 +26,6 @@ impl<'a> ConfigStore<'a> {Ok(())}- /// Get a configuration valuepub fn get(&self, key: &str) -> Result<Option<String>> {let mut stmt = self.conn@@ -40,7 +38,6 @@ impl<'a> ConfigStore<'a> {Ok(value)}- /// Delete a configuration valuepub fn delete(&self, key: &str) -> Result<()> {self.conn.execute("DELETE FROM config WHERE key = ?1", params![key])?;@@ -48,7 +45,6 @@ impl<'a> ConfigStore<'a> {Ok(())}- /// Get all configuration valuespub fn list(&self) -> Result<Vec<(String, String)>> {let mut stmt = self.conndiff --git a/rust/apps/cli/src/storage/mod.rs b/rust/apps/cli/src/storage/mod.rsindex 437c5f2fa3..01e0307d71 100644--- a/rust/apps/cli/src/storage/mod.rs+++ b/rust/apps/cli/src/storage/mod.rs@@ -12,22 +12,18 @@ pub use account::AccountStore;pub use config::ConfigStore;pub use sync::SyncStore;-/// Main storage handler that manages the SQLite databasepub struct Storage {conn: Connection,path: Option<PathBuf>,}impl Storage {- /// Create a new storage instance with the given database pathpub fn new<P: AsRef<Path>>(path: P) -> Result<Self> {let path_buf = path.as_ref().to_path_buf();let conn = Connection::open(&path_buf)?;- // Enable foreign keysconn.execute("PRAGMA foreign_keys = ON", [])?;- // Create tablesschema::create_tables(&conn)?;Ok(Self {@@ -36,7 +32,6 @@ impl Storage {})}- /// Create an in-memory database (useful for testing)pub fn new_in_memory() -> Result<Self> {let conn = Connection::open_in_memory()?;conn.execute("PRAGMA foreign_keys = ON", [])?;@@ -44,12 +39,10 @@ impl Storage {Ok(Self { conn, path: None })}- /// Get a reference to the connectionpub fn conn(&self) -> &Connection {&self.conn}- /// Begin a transactionpub fn transaction<F, R>(&mut self, f: F) -> Result<R>whereF: FnOnce(&rusqlite::Transaction) -> Result<R>,@@ -60,28 +53,23 @@ impl Storage {Ok(result)}- /// Get account storepub fn accounts(&self) -> AccountStore<'_> {AccountStore::new(&self.conn)}- /// Get config storepub fn config(&self) -> ConfigStore<'_> {ConfigStore::new(&self.conn)}- /// Get sync storepub fn sync(&self) -> SyncStore<'_> {SyncStore::new(&self.conn)}- /// Get the database pathpub fn db_path(&self) -> Option<&Path> {self.path.as_deref()}}-/// Helper trait for JSON serialization in SQLitepub trait JsonValue: Serialize + for<'de> Deserialize<'de> {fn to_json(&self) -> Result<String> {Ok(serde_json::to_string(self)?)@@ -92,7 +80,4 @@ pub trait JsonValue: Serialize + for<'de> Deserialize<'de> {}}-// Implement for common typesimpl<T> JsonValue for T where T: Serialize + for<'de> Deserialize<'de> {}--// Rusqlite error conversion is now handled in models/error.rs via #[from]diff --git a/rust/apps/cli/src/storage/schema.rs b/rust/apps/cli/src/storage/schema.rsindex 46b8826563..022c920f5b 100644--- a/rust/apps/cli/src/storage/schema.rs+++ b/rust/apps/cli/src/storage/schema.rs@@ -1,11 +1,8 @@use crate::Result;use rusqlite::Connection;-/// Create all database tablespub fn create_tables(conn: &Connection) -> Result<()> {- // Accounts table- // Note: user_id is globally unique across all users, and each user can have multiple apps- // So we use (user_id, app) as composite primary key+ // A user can have accounts for multiple apps, so the key includes the app.conn.execute("CREATE TABLE IF NOT EXISTS accounts (user_id INTEGER NOT NULL,@@ -21,7 +18,6 @@ pub fn create_tables(conn: &Connection) -> Result<()> {[],)?;- // Secrets table (encrypted credentials)conn.execute("CREATE TABLE IF NOT EXISTS secrets (user_id INTEGER NOT NULL,@@ -37,7 +33,6 @@ pub fn create_tables(conn: &Connection) -> Result<()> {[],)?;- // Configuration tableconn.execute("CREATE TABLE IF NOT EXISTS config (key TEXT PRIMARY KEY,@@ -47,9 +42,7 @@ pub fn create_tables(conn: &Connection) -> Result<()> {[],)?;- // Collections/Albums table- // Note: collection_id is globally unique across all users, so we use it as the primary key- // owner field contains the user_id who owns this collection+ // Collection IDs are global; owner records the owning user.conn.execute("CREATE TABLE IF NOT EXISTS collections (collection_id INTEGER PRIMARY KEY,@@ -63,9 +56,7 @@ pub fn create_tables(conn: &Connection) -> Result<()> {[],)?;- // Files table (for caching remote file metadata)- // Note: file_id is globally unique across all users, so we use it as the primary key- // owner_id contains the user_id who owns this file+ // File IDs are global; owner_id records the owning user.conn.execute("CREATE TABLE IF NOT EXISTS files (file_id INTEGER PRIMARY KEY,@@ -86,7 +77,6 @@ pub fn create_tables(conn: &Connection) -> Result<()> {[],)?;- // Album files mappingconn.execute("CREATE TABLE IF NOT EXISTS album_files (album_id INTEGER NOT NULL,@@ -100,7 +90,6 @@ pub fn create_tables(conn: &Connection) -> Result<()> {[],)?;- // Sync state tableconn.execute("CREATE TABLE IF NOT EXISTS sync_state (user_id INTEGER NOT NULL,@@ -115,7 +104,6 @@ pub fn create_tables(conn: &Connection) -> Result<()> {[],)?;- // Collection sync state table - stores per-collection sync timestampsconn.execute("CREATE TABLE IF NOT EXISTS collection_sync_state (user_id INTEGER NOT NULL,@@ -128,7 +116,6 @@ pub fn create_tables(conn: &Connection) -> Result<()> {[],)?;- // Create indices for better performanceconn.execute("CREATE INDEX IF NOT EXISTS idx_files_collectionON files(collection_id)",@@ -165,7 +152,6 @@ pub fn create_tables(conn: &Connection) -> Result<()> {[],)?;- // Create index for file deduplicationconn.execute("CREATE INDEX IF NOT EXISTS idx_files_hashON files(owner_id, content_hash)diff --git a/rust/apps/cli/src/storage/sync.rs b/rust/apps/cli/src/storage/sync.rsindex a5be28d5f3..8271cab371 100644--- a/rust/apps/cli/src/storage/sync.rs+++ b/rust/apps/cli/src/storage/sync.rs@@ -14,7 +14,6 @@ impl<'a> SyncStore<'a> {Self { conn }}- /// Store a collectionpub fn upsert_collection(&self, collection: &Collection) -> Result<()> {let metadata = serde_json::to_string(&collection)?;@@ -36,7 +35,6 @@ impl<'a> SyncStore<'a> {Ok(())}- /// Get all collections for a userpub fn get_collections(&self, user_id: i64) -> Result<Vec<Collection>> {let mut stmt = self.conn.prepare("SELECT metadata FROM collections@@ -54,12 +52,10 @@ impl<'a> SyncStore<'a> {Ok(collections)}- /// Store a filepub fn upsert_file(&self, file: &RemoteFile) -> Result<()> {self.upsert_file_with_hash(file, None)}- /// Store a file with optional content hashpub fn upsert_file_with_hash(&self,file: &RemoteFile,@@ -72,7 +68,7 @@ impl<'a> SyncStore<'a> {None => None,};- // First check if file exists and preserve is_synced_locally flag+ // Refreshing remote metadata must preserve the local-sync flag.let existing_sync_status: Option<i32> = self.conn.query_row(@@ -108,7 +104,6 @@ impl<'a> SyncStore<'a> {Ok(())}- /// Get files for a collectionpub fn get_files_by_collection(&self,user_id: i64,@@ -172,11 +167,8 @@ impl<'a> SyncStore<'a> {Ok(files)}- /// Update sync statepub fn update_sync_state(&self, user_id: i64, sync_type: &str, timestamp: i64) -> Result<()> {- // For per-collection sync, store in collection_sync_state tableif sync_type.starts_with("collection_") {- // Extract collection_id from sync_type (format: "collection_{id}_files")let collection_id = sync_type.strip_prefix("collection_").and_then(|s| s.strip_suffix("_files"))@@ -212,11 +204,8 @@ impl<'a> SyncStore<'a> {Ok(())}- /// Get last sync timestamppub fn get_last_sync(&self, user_id: i64, sync_type: &str) -> Result<Option<i64>> {- // For per-collection sync, retrieve from collection_sync_state tableif sync_type.starts_with("collection_") {- // Extract collection_id from sync_type (format: "collection_{id}_files")let collection_id = sync_type.strip_prefix("collection_").and_then(|s| s.strip_suffix("_files"))@@ -257,7 +246,6 @@ impl<'a> SyncStore<'a> {Ok(timestamp)}- /// Mark album file as syncedpub fn mark_album_file_synced(&self, album_id: i64, file_id: i64) -> Result<()> {self.conn.execute("UPDATE album_files SET synced_locally = 1@@ -268,9 +256,7 @@ impl<'a> SyncStore<'a> {Ok(())}- /// Clear sync state for an account (for full sync)pub fn clear_sync_state(&self, user_id: i64) -> Result<()> {- // Clear both sync_state and collection_sync_stateself.conn.execute("DELETE FROM sync_state WHERE user_id = ?1 AND app = 'photos'",params![user_id],@@ -284,9 +270,7 @@ impl<'a> SyncStore<'a> {Ok(())}- /// Get files that need downloading (not synced locally)pub fn get_pending_downloads(&self, user_id: i64) -> Result<Vec<RemoteFile>> {- // First check how many files are already syncedlet synced_count: i64 = self.conn.query_row("SELECT COUNT(*) FROM files WHERE owner_id = ?1 AND is_synced_locally = 1",params![user_id],@@ -352,7 +336,6 @@ impl<'a> SyncStore<'a> {Ok(files)}- /// Mark file as synced locally after successful downloadpub fn mark_file_synced(&self, file_id: i64, local_path: Option<&str>) -> Result<()> {let rows_updated = if let Some(path) = local_path {self.conn.execute(@@ -373,7 +356,6 @@ impl<'a> SyncStore<'a> {Ok(())}- /// Check if a file with the same hash already exists for this userpub fn find_duplicate_by_hash(&self, owner_id: i64, content_hash: &str) -> Result<Option<i64>> {let file_id: Option<i64> = self.conn@@ -390,7 +372,6 @@ impl<'a> SyncStore<'a> {Ok(file_id)}- /// Get local path of a filepub fn get_file_local_path(&self, file_id: i64) -> Result<Option<String>> {let path: Option<String> = self.conndiff --git a/rust/apps/cli/src/sync/download.rs b/rust/apps/cli/src/sync/download.rsindex 5025ed4388..d24a8a7ab5 100644--- a/rust/apps/cli/src/sync/download.rs+++ b/rust/apps/cli/src/sync/download.rs@@ -12,7 +12,6 @@ use std::sync::Arc;use tokio::fs;use tokio::io::AsyncWriteExt;-/// Manages file downloads with parallel processing and error recoverypub struct DownloadManager {api_client: AppClient,temp_dir: PathBuf,@@ -22,7 +21,6 @@ pub struct DownloadManager {}impl DownloadManager {- /// Create a new download managerpub fn new(api_client: AppClient) -> Result<Self> {let temp_dir = std::env::temp_dir().join("ente-downloads");std::fs::create_dir_all(&temp_dir)?;@@ -31,33 +29,28 @@ impl DownloadManager {api_client,temp_dir,collection_keys: HashMap::new(),- concurrent_downloads: 4, // Default concurrent downloads+ concurrent_downloads: 4,show_progress: true,})}- /// Set collection keys for file decryptionpub fn set_collection_keys(&mut self, keys: HashMap<i64, Vec<u8>>) {self.collection_keys = keys;}- /// Set number of concurrent downloadspub fn set_concurrent_downloads(&mut self, count: usize) {- self.concurrent_downloads = count.clamp(1, 10); // Limit between 1-10+ self.concurrent_downloads = count.clamp(1, 10);}- /// Set whether to show progress indicatorspub fn set_show_progress(&mut self, show: bool) {self.show_progress = show;}- /// Download a single filepub async fn download_file(&self, file: &RemoteFile, destination: &Path) -> Result<()> {self.download_file_with_progress(file, destination, None).await}- /// Download a single file with optional progress barasync fn download_file_with_progress(&self,file: &RemoteFile,@@ -66,32 +59,25 @@ impl DownloadManager {) -> Result<()> {log::debug!("Downloading file {} to {:?}", file.id, destination);- // Ensure destination directory existsif let Some(parent) = destination.parent() {fs::create_dir_all(parent).await?;}- // Check if file already existsif destination.exists() {log::debug!("File already exists at {destination:?}, skipping download but marking as successful");- // Even though we skip downloading, we should still update the database- // This is handled by returning Ok(()) which will mark it as successful+ // Returning Ok marks the existing file as synced.return Ok(());}- // Download to temp file firstlet temp_path = self.temp_dir.join(format!("{}.tmp", file.id));- // Get file datalet api = ApiMethods::new(&self.api_client);let encrypted_data = api.download_file(file.id).await?;- // Decrypt filelet decrypted_data = self.decrypt_file_data(file, &encrypted_data)?;- // Check if this is a live photo (based on .zip extension in destination)let is_live_photo = destination.extension().and_then(|ext| ext.to_str())@@ -99,7 +85,6 @@ impl DownloadManager {.unwrap_or(false);if is_live_photo {- // Extract live photo componentsif let Err(e) = extract_live_photo(&decrypted_data, destination).await {log::warn!("Failed to extract live photo components for file {}, saving as ZIP: {}",@@ -115,13 +100,12 @@ impl DownloadManager {fs::remove_file(&temp_path).await?;}} else {- // Write regular filelet mut temp_file = fs::File::create(&temp_path).await?;temp_file.write_all(&decrypted_data).await?;temp_file.sync_all().await?;drop(temp_file);- // Move to final destination (use copy + delete to work across filesystems)+ // Copy instead of rename because the paths may be on different filesystems.fs::copy(&temp_path, destination).await?;fs::remove_file(&temp_path).await?;}@@ -129,7 +113,6 @@ impl DownloadManager {// TODO: Update storage with local path// self.storage.sync().update_file_local_path(file.id, destination.to_str().unwrap())?;- // Update progress if availableif let Some(pb) = progress {pb.inc(1);}@@ -138,7 +121,6 @@ impl DownloadManager {Ok(())}- /// Download multiple files with concurrency controlpub async fn download_files(&self, files: Vec<(RemoteFile, PathBuf)>) -> Result<DownloadStats> {use futures::stream::{self, StreamExt};@@ -150,7 +132,6 @@ impl DownloadManager {..Default::default()};- // Create progress bars if enabledlet (_multi_progress, progress_bar) = if self.show_progress && total > 0 {let mp = MultiProgress::new();let pb = mp.add(ProgressBar::new(total as u64));@@ -166,7 +147,6 @@ impl DownloadManager {(None, None)};- // Process files in parallel with concurrency limitlet pb_clone = progress_bar.clone();let results: Vec<_> = stream::iter(files).map(|(file, path)| {@@ -182,7 +162,6 @@ impl DownloadManager {.collect().await;- // Count resultsfor (file, path, result) in results {match result {Ok(_) => {@@ -196,7 +175,6 @@ impl DownloadManager {}}- // Finish progress barif let Some(pb) = progress_bar {pb.finish_with_message(format!("Downloaded {} files", stats.successful));}@@ -209,7 +187,6 @@ impl DownloadManager {Ok(stats)}- /// Download thumbnail for a filepub async fn download_thumbnail(&self, file: &RemoteFile, destination: &Path) -> Result<()> {log::debug!("Downloading thumbnail for file {} to {:?}",@@ -217,19 +194,15 @@ impl DownloadManager {destination);- // Ensure destination directory existsif let Some(parent) = destination.parent() {fs::create_dir_all(parent).await?;}- // Get thumbnail datalet api = ApiMethods::new(&self.api_client);let encrypted_data = api.download_thumbnail(file.id).await?;- // Decrypt thumbnaillet decrypted_data = self.decrypt_file_data(file, &encrypted_data)?;- // Write to filelet mut file_handle = fs::File::create(destination).await?;file_handle.write_all(&decrypted_data).await?;file_handle.sync_all().await?;@@ -238,9 +211,7 @@ impl DownloadManager {Ok(())}- /// Decrypt file data using file key and collection keyfn decrypt_file_data(&self, file: &RemoteFile, encrypted_data: &[u8]) -> Result<Vec<u8>> {- // Get collection keylet collection_key = self.collection_keys.get(&file.collection_id)@@ -248,7 +219,6 @@ impl DownloadManager {crate::Error::Crypto("Missing collection key for file decryption".into())})?;- // Decrypt file key using collection key (XSalsa20-Poly1305)let file_key = {let key_bytes = b64::decode(&file.encrypted_key)?;let nonce = b64::decode(&file.key_decryption_nonce)?;@@ -259,7 +229,6 @@ impl DownloadManager {)?};- // Decrypt file data using file key (Streaming XChaCha20-Poly1305)let file_nonce = b64::decode(&file.file.decryption_header)?;let decrypted = crypto::stream::decrypt_file_data(encrypted_data,@@ -270,7 +239,6 @@ impl DownloadManager {Ok(decrypted)}- /// Resume a partial download (for future implementation)pub async fn resume_download(&self,_file: &RemoteFile,@@ -281,7 +249,6 @@ impl DownloadManager {todo!("Resume download not yet implemented")}- /// Clean up temporary filespub async fn cleanup(&self) -> Result<()> {log::debug!("Cleaning up temporary download files");@@ -303,7 +270,6 @@ impl DownloadManager {}}-/// Statistics from download operations#[derive(Debug, Default)]pub struct DownloadStats {pub total: usize,@@ -314,12 +280,10 @@ pub struct DownloadStats {}impl DownloadStats {- /// Check if all downloads were successfulpub fn all_successful(&self) -> bool {self.failed == 0 && self.successful == self.total}- /// Get success rate as percentagepub fn success_rate(&self) -> f64 {if self.total == 0 {100.0diff --git a/rust/apps/cli/src/sync/engine.rs b/rust/apps/cli/src/sync/engine.rsindex df3aebb1ae..8dd8bac778 100644--- a/rust/apps/cli/src/sync/engine.rs+++ b/rust/apps/cli/src/sync/engine.rs@@ -4,7 +4,6 @@ use crate::api::methods::ApiMethods;use crate::models::{account::Account, file::RemoteFile};use crate::storage::Storage;-/// Core sync engine responsible for fetching and tracking remote changespub struct SyncEngine {api_client: AppClient,storage: Storage,@@ -12,7 +11,6 @@ pub struct SyncEngine {}impl SyncEngine {- /// Create a new sync engine for an accountpub fn new(api_client: AppClient, storage: Storage, account: Account) -> Self {Self {api_client,@@ -21,7 +19,6 @@ impl SyncEngine {}}- /// Run a full sync for the accountpub async fn sync(&self) -> Result<SyncStats> {log::info!("Starting sync for account: {}", self.account.email);@@ -34,13 +31,11 @@ impl SyncEngine {Ok(stats)}- /// Sync collections (albums)async fn sync_collections(&self) -> Result<SyncResult> {log::debug!("Syncing collections...");let sync_store = self.storage.sync();- // Get last sync time for collectionslet last_sync = sync_store.get_last_sync(self.account.user_id, "collections")?.unwrap_or(0);@@ -55,7 +50,6 @@ impl SyncEngine {deleted: 0,};- // Process each collectionfor collection in &collections {log::debug!("Processing collection: {:?} ({})",@@ -63,7 +57,6 @@ impl SyncEngine {collection.id);- // Convert API collection to storage collectionlet storage_collection = crate::models::collection::Collection {id: collection.id,owner: collection.owner.id,@@ -81,27 +74,21 @@ impl SyncEngine {is_deleted: collection.is_deleted,};- // Upsert collection (insert or update)sync_store.upsert_collection(&storage_collection)?;- // Count as new or updated based on updation timeif collection.updation_time > last_sync {if last_sync == 0 {- // First sync - count as newresult.new += 1;} else {- // Incremental sync - count as updatedresult.updated += 1;}}- // Track deleted collectionsif collection.is_deleted {result.deleted += 1;}}- // Update sync timestamplet now = chrono::Utc::now().timestamp_micros();sync_store.update_sync_state(self.account.user_id, "collections", now)?;@@ -113,7 +100,6 @@ impl SyncEngine {Ok(result)}- /// Sync files incrementallyasync fn sync_files(&self) -> Result<SyncResult> {log::debug!("Syncing files...");@@ -121,10 +107,8 @@ impl SyncEngine {let api = ApiMethods::new(&self.api_client);let mut result = SyncResult::default();- // Get all collections for this accountlet collections = sync_store.get_collections(self.account.user_id)?;- // Sync files for each collectionfor collection in collections {if collection.is_deleted {continue;@@ -136,7 +120,6 @@ impl SyncEngine {collection.id);- // Get last sync time for this collection's fileslet initial_sync = sync_store.get_last_sync(self.account.user_id,@@ -147,7 +130,6 @@ impl SyncEngine {let mut last_sync = initial_sync;let is_first_sync = initial_sync == 0;- // Log sync statusif is_first_sync {log::info!("Initial sync for collection: {} ({})",@@ -187,11 +169,9 @@ impl SyncEngine {result.total += files.len();- // Convert API files to RemoteFile and processfor file in files {log::trace!("Processing file: {}", file.id);- // Create RemoteFile from API responselet remote_file = RemoteFile {id: file.id,collection_id: file.collection_id,@@ -201,13 +181,13 @@ impl SyncEngine {file: crate::models::file::FileInfo {encrypted_data: file.file.encrypted_data.clone(),decryption_header: file.file.decryption_header.clone(),- object_key: None, // Not in API response+ object_key: None,size: file.file.size,},thumbnail: crate::models::file::FileInfo {encrypted_data: file.thumbnail.encrypted_data.clone(),decryption_header: file.thumbnail.decryption_header.clone(),- object_key: None, // Not in API response+ object_key: None,size: file.thumbnail.size,},metadata: crate::models::file::MetadataInfo {@@ -230,35 +210,29 @@ impl SyncEngine {}),};- // Skip deleted files on first sync+ // Ignore tombstones during the initial sync.if is_first_sync && file.is_deleted {log::trace!("Skipping deleted file {} on initial sync", file.id);continue;}- // Upsert file (insert or update)sync_store.upsert_file(&remote_file)?;- // Count as new, updated or deletedif file.is_deleted {result.deleted += 1;} else if file.updation_time > initial_sync {if initial_sync == 0 {- // First sync - count as newresult.new += 1;} else {- // Incremental sync - count as updatedresult.updated += 1;}}- // Track the latest updation time for next syncif file.updation_time > last_sync {last_sync = file.updation_time;}}- // Update sync state after each batch for this collectionsync_store.update_sync_state(self.account.user_id,&format!("collection_{}_files", collection.id),@@ -276,12 +250,9 @@ impl SyncEngine {Ok(result)}- /// Get list of files that need to be downloadedpub async fn get_pending_downloads(&self) -> Result<Vec<RemoteFile>> {let sync_store = self.storage.sync();- // Get all non-deleted files for this account- // Note: We'll need to check all collections for this accountlet collections = sync_store.get_collections(self.account.user_id)?;let mut all_files = Vec::new();@@ -290,28 +261,24 @@ impl SyncEngine {all_files.extend(files);}- // Filter out deleted fileslet pending: Vec<RemoteFile> = all_files.into_iter().filter(|f| !f.is_deleted).collect();log::info!("Found {} files pending download", pending.len());Ok(pending)}- /// Get collections for decryption keyspub async fn get_collections(&self) -> Result<Vec<crate::models::collection::Collection>> {let sync_store = self.storage.sync();sync_store.get_collections(self.account.user_id)}}-/// Statistics from a sync operation#[derive(Debug, Default)]pub struct SyncStats {pub collections: SyncResult,pub files: SyncResult,}-/// Result of syncing a specific type of data#[derive(Debug, Default)]pub struct SyncResult {pub total: usize,diff --git a/rust/apps/cli/src/utils/mod.rs b/rust/apps/cli/src/utils/mod.rsindex 45841f7d90..67b39d5632 100644--- a/rust/apps/cli/src/utils/mod.rs+++ b/rust/apps/cli/src/utils/mod.rs@@ -1,9 +1,7 @@use dirs;use std::path::PathBuf;-/// Get the CLI configuration directorypub fn get_cli_config_dir() -> crate::Result<PathBuf> {- // Check environment variable firstif let Ok(config_dir) = std::env::var("ENTE_CLI_CONFIG_DIR") {return Ok(PathBuf::from(config_dir));}@@ -17,7 +15,6 @@ pub fn get_cli_config_dir() -> crate::Result<PathBuf> {let cli_path = config_dir.join("ente-cli");- // Create directory if it doesn't existif !cli_path.exists() {std::fs::create_dir_all(&cli_path)?;}diff --git a/rust/apps/cli/tests/support/cli.rs b/rust/apps/cli/tests/support/cli.rsindex db60bf1382..9716609def 100644--- a/rust/apps/cli/tests/support/cli.rs+++ b/rust/apps/cli/tests/support/cli.rs@@ -1,4 +1,4 @@-// https://github.com/rust-lang/rust/issues/46379+// Each integration test compiles this shared support module separately.#![allow(dead_code)]use std::{diff --git a/rust/apps/ensu/src-tauri/src/commands/llm.rs b/rust/apps/ensu/src-tauri/src/commands/llm.rsindex 124ea76bd2..55a90fb3ea 100644--- a/rust/apps/ensu/src-tauri/src/commands/llm.rs+++ b/rust/apps/ensu/src-tauri/src/commands/llm.rs@@ -378,17 +378,8 @@ pub async fn llm_load_model("LLM",format!("load model requested model_path={}", params.model_path),);- // Default to offloading all layers to the GPU when the caller does not- // specify a count. Benchmarking on the Vulkan backend (RX 480, Gemma 4- // E4B) showed full offload is both fastest (no per-token CPU<->GPU- // activation transfers; partial offload was up to ~1.6x slower) and most- // robust (it sidesteps a ggml scheduler assert that can abort partial- // CPU/GPU splits). The driver spills any VRAM overflow to system memory- // instead of failing, and without a usable Vulkan device llama.cpp falls- // back to the CPU. For the rare setups where the GPU must be avoided,- // Vulkan and llama.cpp already provide runtime knobs (for example- // GGML_VK_VISIBLE_DEVICES and VK_LOADER_DRIVERS_DISABLE).- const DEFAULT_GPU_LAYERS: i32 = 999; // llama.cpp clamps to the model's layer count+ // llama.cpp clamps this to the model's layer count.+ const DEFAULT_GPU_LAYERS: i32 = 999;let mut params = params;if params.n_gpu_layers.is_none() {params.n_gpu_layers = Some(DEFAULT_GPU_LAYERS);diff --git a/rust/apps/ensu/src-tauri/src/main.rs b/rust/apps/ensu/src-tauri/src/main.rsindex 9b83d88d6b..a6dd89e1ea 100644--- a/rust/apps/ensu/src-tauri/src/main.rs+++ b/rust/apps/ensu/src-tauri/src/main.rs@@ -25,7 +25,6 @@ fn main() {app.path().app_data_dir()?,));- // Show the main window after setup is completeif let Some(window) = app.get_webview_window("main")&& let Err(err) = window.show(){diff --git a/rust/bindings/frb/ente-rust/src/api/init.rs b/rust/bindings/frb/ente-rust/src/api/init.rsindex c38134a3ec..44433ef339 100644--- a/rust/bindings/frb/ente-rust/src/api/init.rs+++ b/rust/bindings/frb/ente-rust/src/api/init.rs@@ -1,8 +1,3 @@-//! FRB initialization--/// Set up the Rust runtime.-///-/// Called when EnteRust.init() is invoked from Dart.#[flutter_rust_bridge::frb(init)]pub fn init_app() {// Install before FRB claims the process logger.diff --git a/rust/bindings/frb/ente-rust/src/api/mod.rs b/rust/bindings/frb/ente-rust/src/api/mod.rsindex 1c20b8fcfd..ffd58f3423 100644--- a/rust/bindings/frb/ente-rust/src/api/mod.rs+++ b/rust/bindings/frb/ente-rust/src/api/mod.rs@@ -1,5 +1,3 @@-//! Public API exposed to Dart via Flutter Rust Bridge.-pub mod contacts;pub mod init;#[cfg(any(feature = "flutter", frb_expand))]diff --git a/rust/bindings/frb/ente-rust/src/api/urls.rs b/rust/bindings/frb/ente-rust/src/api/urls.rsindex 4570c57883..b43caf2ea9 100644--- a/rust/bindings/frb/ente-rust/src/api/urls.rs+++ b/rust/bindings/frb/ente-rust/src/api/urls.rs@@ -1,8 +1,5 @@-//! FRB bindings for URL construction.-use flutter_rust_bridge::frb;-/// Generate the download URL for a file.#[frb(sync)]pub fn file_download_url(api_origin: String, file_id: i64) -> String {ente_core::urls::file_download_url(&api_origin, file_id)diff --git a/rust/bindings/frb/ente-rust/src/lib.rs b/rust/bindings/frb/ente-rust/src/lib.rsindex 0e484871fd..0a29e8ff92 100644--- a/rust/bindings/frb/ente-rust/src/lib.rs+++ b/rust/bindings/frb/ente-rust/src/lib.rs@@ -1,5 +1,3 @@-//! Flutter Rust Bridge bindings for Ente mobile apps.-pub mod api;#[cfg(feature = "flutter")]diff --git a/rust/bindings/frb/photos/src/api/image_processing_api.rs b/rust/bindings/frb/photos/src/api/image_processing_api.rsindex 285cc5c3c0..ba1aebce32 100644--- a/rust/bindings/frb/photos/src/api/image_processing_api.rs+++ b/rust/bindings/frb/photos/src/api/image_processing_api.rs@@ -31,8 +31,7 @@ pub fn generate_face_thumbnails(generate_face_thumbnails_impl(&decoded, &face_boxes).map_err(|e| e.to_string())}-/// Decode an image (including HEIC/HEIF) to JPEG bytes using ente_heic,-/// bypassing the platform's potentially broken image decoder.+// Use ente_heic instead of the platform decoder, which may fail on HEIC/HEIF.pub fn decode_to_jpeg(image_path: String, quality: Option<u8>) -> Result<Vec<u8>, String> {let decoded = decode_image_from_path(&image_path).map_err(|e| e.to_string())?;let quality = quality.unwrap_or(95);diff --git a/rust/bindings/frb/photos/src/api/ml_indexing_api.rs b/rust/bindings/frb/photos/src/api/ml_indexing_api.rsindex 12cf6894c3..af74b63b47 100644--- a/rust/bindings/frb/photos/src/api/ml_indexing_api.rs+++ b/rust/bindings/frb/photos/src/api/ml_indexing_api.rs@@ -75,7 +75,7 @@ pub struct RustClipResult {pub struct RustPetFaceDetectionResult {pub score: f64,pub box_xyxy: Vec<f64>,- /// 3 keypoints: [left_eye, right_eye, nose], each as [x, y]+ // [left eye, right eye, nose], each as [x, y].pub keypoints: Vec<Vec<f64>>,}@@ -90,7 +90,7 @@ pub struct RustPetAlignmentResult {pub struct RustPetFaceResult {pub detection: RustPetFaceDetectionResult,pub alignment: RustPetAlignmentResult,- /// 0 = dog, 1 = cat+ // 0 = dog, 1 = cat.pub species: u8,pub face_embedding: Vec<f64>,pub pet_face_id: String,@@ -100,7 +100,7 @@ pub struct RustPetFaceResult {pub struct RustPetBodyResult {pub box_xyxy: Vec<f64>,pub score: f64,- /// COCO class: 15 = cat, 16 = dog+ // COCO class: 15 = cat, 16 = dog.pub coco_class: u8,pub pet_body_id: String,pub body_embedding: Vec<f64>,@@ -114,8 +114,6 @@ pub struct AnalyzeImageResult {pub clip: Option<RustClipResult>,pub pet_faces: Option<Vec<RustPetFaceResult>>,pub pet_bodies: Option<Vec<RustPetBodyResult>>,- /// True when any model that contributed to this result ran on the- /// respective accelerated execution provider.pub used_coreml: bool,pub used_webgpu: bool,}@@ -132,10 +130,8 @@ pub struct RunClipTextResult {pub embedding: Vec<f64>,}-/// Configures process-wide ML execution behavior. `enable_webgpu` opts-/// Android into the WebGPU execution provider (off by default, and only-/// honored on Android 12+); it has no effect on other platforms. Call this-/// before the runtime creates its first session.+// This setting is process-wide. WebGPU is off by default and only used on+// Android 12+. Enable it before creating the first session.pub fn set_ml_execution_config(enable_webgpu: bool) {indexing::set_ml_execution_config(enable_webgpu);}@@ -186,17 +182,16 @@ pub fn tokenize_clip_text_rust(text: String, vocab_path: String) -> Result<Vec<iindexing::tokenize_clip_text(&text, &vocab_path).map_err(|e| e.to_string())}-/// A notable ML runtime event (execution provider fallback, golden self-test-/// failure) buffered by the Rust runtime for app-side logging. `severity` is-/// one of "info", "warning", or "severe".+// Execution-provider fallbacks and golden self-test failures are buffered for+// app-side logging. Severity is "info", "warning", or "severe".#[derive(Clone, Debug)]pub struct RustMlRuntimeEvent {pub severity: String,pub message: String,}-/// Drains buffered ML runtime events. The buffer is process-wide, so drain-/// after ML operations and log each event at its severity.+// Drain after ML operations and log each event at its severity. The buffer is+// process-wide.pub fn take_ml_runtime_events() -> Vec<RustMlRuntimeEvent> {ente_photos::ml::events::take_events().into_iter()diff --git a/rust/bindings/frb/photos/src/api/usearch_api.rs b/rust/bindings/frb/photos/src/api/usearch_api.rsindex e7887b1de1..b5c5f965da 100644--- a/rust/bindings/frb/photos/src/api/usearch_api.rs+++ b/rust/bindings/frb/photos/src/api/usearch_api.rs@@ -345,8 +345,6 @@ impl VectorDB {self.inner.bulk_search_keys(potential_keys, count, exact)}- /// Check if a vector with the given key exists in the index.- /// `true` if the index contains the vector with the given key, `false` otherwise.pub fn contains_vector(&self, key: u64) -> bool {self.inner.contains_vector(key)}diff --git a/rust/bindings/wasm/core/src/lib.rs b/rust/bindings/wasm/core/src/lib.rsindex 09db41fcfb..f1dc08c05f 100644--- a/rust/bindings/wasm/core/src/lib.rs+++ b/rust/bindings/wasm/core/src/lib.rs@@ -1,5 +1,3 @@-//! Wasm bindings for the `ente-core` crate.-use ente_wasm_log as _;mod crypto;diff --git a/rust/bindings/wasm/ente-wasm/src/auth.rs b/rust/bindings/wasm/ente-wasm/src/auth.rsindex 33a9edf394..bf39bc9df4 100644--- a/rust/bindings/wasm/ente-wasm/src/auth.rs+++ b/rust/bindings/wasm/ente-wasm/src/auth.rs@@ -165,8 +165,6 @@ impl GeneratedSrpSetup {}}-/// `srp_attrs` must match the shape returned by the Ente API's-/// `/users/srp/attributes` endpoint (i.e. camelCased fields).#[wasm_bindgen]pub fn auth_derive_srp_credentials(password: &str,@@ -244,8 +242,6 @@ pub fn auth_recovery_key_to_mnemonic(recovery_key_b64: &str) -> Result<String, Aauth::recovery_key_to_mnemonic(recovery_key_b64).map_err(Into::into)}-/// `key_attrs` should be the `keyAttributes` object from the auth response.-/// `encrypted_token_b64` is the `encryptedToken` string from the auth response.#[wasm_bindgen]pub fn auth_decrypt_secrets(kek_b64: &str,diff --git a/rust/bindings/wasm/ente-wasm/src/crypto.rs b/rust/bindings/wasm/ente-wasm/src/crypto.rsindex fceee070a5..8a53a407b2 100644--- a/rust/bindings/wasm/ente-wasm/src/crypto.rs+++ b/rust/bindings/wasm/ente-wasm/src/crypto.rs@@ -1,11 +1,8 @@-//! WASM bindings for pure-Rust cryptography.-use ente_core::b64;use ente_core::crypto;use md5::{Digest, Md5};use wasm_bindgen::prelude::*;-/// Crypto error.#[wasm_bindgen]pub struct CryptoError {code: String,@@ -14,13 +11,11 @@ pub struct CryptoError {#[wasm_bindgen]impl CryptoError {- /// A machine-readable error code.#[wasm_bindgen(getter)]pub fn code(&self) -> String {self.code.clone()}- /// Human-readable error message.#[wasm_bindgen(getter)]pub fn message(&self) -> String {self.message.clone()@@ -72,32 +67,22 @@ impl From<b64::DecodeError> for CryptoError {}}-/// No-op, kept only for binding compatibility.-///-/// The pure-Rust crypto needs no initialization; existing web callers invoke-/// this before using the other functions. Remove once the web callers drop it.+// Kept for existing web callers; pure Rust crypto needs no initialization.#[wasm_bindgen]pub fn crypto_init() -> Result<(), CryptoError> {Ok(())}-/// Generate a random 32-byte SecretBox key and return it as base64.#[wasm_bindgen]pub fn crypto_generate_key() -> String {b64::encode(crypto::Key::generate().as_bytes())}-/// Generate a random 32-byte SecretStream key and return it as base64.#[wasm_bindgen]pub fn crypto_generate_stream_key() -> String {b64::encode(crypto::Key::generate().as_bytes())}-/// Incremental chunk encryptor for large file uploads.-///-/// The browser reads the file in chunks and passes each chunk to this object,-/// which keeps the secretstream state in Rust and returns encrypted bytes for-/// the caller to upload.#[wasm_bindgen]pub struct CryptoStreamEncryptor {encryptor: crypto::stream::Encryptor,@@ -141,7 +126,6 @@ impl CryptoStreamEncryptor {}}-/// Incremental chunk decryptor for large file downloads.#[wasm_bindgen]pub struct CryptoStreamDecryptor {decryptor: crypto::stream::Decryptor,@@ -185,20 +169,17 @@ impl CryptoStreamDecryptor {}}-/// Generate a random 16-byte salt and return it as base64.#[wasm_bindgen]pub fn crypto_generate_salt() -> String {b64::encode(crypto::Salt::generate().as_bytes())}-/// Compute the MD5 digest of the provided bytes and return it as base64.#[wasm_bindgen]pub fn crypto_md5_base64(data: Vec<u8>) -> String {let digest = Md5::digest(&data);b64::encode(&digest)}-/// A X25519 public/secret keypair.#[wasm_bindgen]pub struct CryptoKeyPair {public_key: String,@@ -218,7 +199,6 @@ impl CryptoKeyPair {}}-/// Generate a random X25519 keypair and return it as base64.#[wasm_bindgen]pub fn crypto_generate_keypair() -> CryptoKeyPair {let secret_key = crypto::SecretKey::generate();@@ -228,9 +208,6 @@ pub fn crypto_generate_keypair() -> CryptoKeyPair {}}-/// A SecretBox encryption result.-///-/// Wire format is compatible with libsodium's `crypto_secretbox_easy`.#[wasm_bindgen]pub struct EncryptedBox {encrypted_data: String,@@ -250,9 +227,6 @@ impl EncryptedBox {}}-/// Encrypt `data_b64` using SecretBox with `key_b64`.-///-/// Returns ciphertext (`encrypted_data`) and nonce as base64.#[wasm_bindgen]pub fn crypto_encrypt_box(data_b64: &str, key_b64: &str) -> Result<EncryptedBox, CryptoError> {let data = b64::decode(data_b64)?;@@ -266,9 +240,6 @@ pub fn crypto_encrypt_box(data_b64: &str, key_b64: &str) -> Result<EncryptedBox,})}-/// Decrypt a SecretBox ciphertext using `key_b64` and `nonce_b64`.-///-/// Returns the plaintext as base64.#[wasm_bindgen]pub fn crypto_decrypt_box(encrypted_data_b64: &str,@@ -287,7 +258,6 @@ pub fn crypto_decrypt_box(Ok(b64::encode(&plaintext))}-/// A SecretStream (blob) encryption result.#[wasm_bindgen]pub struct EncryptedBlob {encrypted_data: String,@@ -307,7 +277,6 @@ impl EncryptedBlob {}}-/// Encrypt `data_b64` using SecretStream (single-message blob) with `key_b64`.#[wasm_bindgen]pub fn crypto_encrypt_blob(data_b64: &str, key_b64: &str) -> Result<EncryptedBlob, CryptoError> {let data = b64::decode(data_b64)?;@@ -320,9 +289,6 @@ pub fn crypto_encrypt_blob(data_b64: &str, key_b64: &str) -> Result<EncryptedBlo})}-/// Decrypt a SecretStream (blob) ciphertext.-///-/// Returns the plaintext as base64.#[wasm_bindgen]pub fn crypto_decrypt_blob(encrypted_data_b64: &str,@@ -341,11 +307,6 @@ pub fn crypto_decrypt_blob(Ok(b64::encode(&plaintext))}-/// Legacy decrypt for SecretStream (blob) ciphertext that may not carry-/// a final tag.-///-/// Prefer using [`crypto_decrypt_blob`]. This function exists as a migration-/// fallback for older data written without the final secretstream tag.#[wasm_bindgen]pub fn crypto_decrypt_blob_legacy(encrypted_data_b64: &str,@@ -364,13 +325,6 @@ pub fn crypto_decrypt_blob_legacy(Ok(b64::encode(&plaintext))}-/// Decrypt chunked SecretStream data (file content).-///-/// Unlike `crypto_decrypt_blob` which handles single-message blobs, this-/// function handles multi-chunk streaming data encrypted with 4 MB chunks-/// (the format used for encrypted file content).-///-/// Returns the plaintext as base64.#[wasm_bindgen]pub fn crypto_decrypt_stream(encrypted_data_b64: &str,@@ -389,9 +343,6 @@ pub fn crypto_decrypt_stream(Ok(b64::encode(&plaintext))}-/// Seal (anonymous public-key encrypt) `data_b64` for `recipient_public_key_b64`.-///-/// Wire format matches libsodium `crypto_box_seal`.#[wasm_bindgen]pub fn crypto_box_seal(data_b64: &str,@@ -403,9 +354,6 @@ pub fn crypto_box_seal(Ok(b64::encode(&sealed))}-/// Open (decrypt) a sealed box.-///-/// Returns the plaintext as base64.#[wasm_bindgen]pub fn crypto_box_seal_open(sealed_b64: &str,@@ -423,9 +371,6 @@ pub fn crypto_box_seal_open(Ok(b64::encode(&opened))}-/// Derive a 32-byte key from `password` using Argon2id.-///-/// Returns the derived key as base64.#[wasm_bindgen]pub fn crypto_derive_key(password: &str,@@ -446,9 +391,6 @@ pub fn crypto_derive_key(Ok(b64::encode(key.as_bytes()))}-/// Derive a subkey using BLAKE2b KDF (libsodium compatible).-///-/// Returns the derived subkey as base64.#[wasm_bindgen]pub fn crypto_derive_subkey(key_b64: &str,@@ -469,11 +411,6 @@ pub fn crypto_derive_subkey(Ok(b64::encode(&subkey))}-/// A chunked SecretStream encryption result (for file content).-///-/// Unlike [`EncryptedBlob`] which encrypts data as a single message, this-/// encrypts data in 4 MB chunks using the streaming API β the same format used-/// for encrypted file content throughout Ente.#[wasm_bindgen]pub struct EncryptedStreamResult {encrypted_data: String,@@ -484,41 +421,27 @@ pub struct EncryptedStreamResult {#[wasm_bindgen]impl EncryptedStreamResult {- /// The encrypted ciphertext as base64.#[wasm_bindgen(getter)]pub fn encrypted_data(&self) -> String {self.encrypted_data.clone()}- /// The decryption header as base64.#[wasm_bindgen(getter)]pub fn decryption_header(&self) -> String {self.decryption_header.clone()}- /// MD5 hash of the encrypted data as base64.#[wasm_bindgen(getter)]pub fn md5_hash(&self) -> String {self.md5_hash.clone()}- /// The file encryption key (32 bytes) as base64.- ///- /// A new random key is generated for each encryption.#[wasm_bindgen(getter)]pub fn key(&self) -> String {self.key.clone()}}-/// Encrypt file data using chunked SecretStream (4 MB chunks) and compute MD5.-///-/// Generates a new random stream key, encrypts the data in 4 MB chunks (the-/// same format produced by the mobile and desktop clients), and computes the-/// MD5 hash of the ciphertext.-///-/// Returns the encrypted data, decryption header, MD5 hash, and generated key-/// β all as base64 strings.#[wasm_bindgen]pub fn crypto_encrypt_stream(data_b64: &str) -> Result<EncryptedStreamResult, CryptoError> {let plaintext = b64::decode(data_b64)?;@@ -538,10 +461,6 @@ pub fn crypto_encrypt_stream(data_b64: &str) -> Result<EncryptedStreamResult, Cr})}-/// Encrypt data using chunked SecretStream with an existing key.-///-/// Same as [`crypto_encrypt_stream`] but uses the provided key instead of-/// generating a new one. Useful for encrypting thumbnails with the same file key.#[wasm_bindgen]pub fn crypto_encrypt_stream_with_key(data_b64: &str,@@ -564,9 +483,6 @@ pub fn crypto_encrypt_stream_with_key(})}-/// Derive the SRP login key from a 32-byte master key.-///-/// Returns the 16-byte login key as base64.#[wasm_bindgen]pub fn crypto_derive_login_key(master_key_b64: &str) -> Result<String, CryptoError> {let key = b64::decode(master_key_b64)?;diff --git a/rust/bindings/wasm/ente-wasm/src/legacy_kit.rs b/rust/bindings/wasm/ente-wasm/src/legacy_kit.rsindex b77cad7f21..088f0e7204 100644--- a/rust/bindings/wasm/ente-wasm/src/legacy_kit.rs+++ b/rust/bindings/wasm/ente-wasm/src/legacy_kit.rs@@ -1,5 +1,3 @@-//! WASM bindings for offline legacy-kit recovery.-use ente_contacts::{LegacyKitRecoveryClient, LegacyKitShare};use serde::Deserialize;use serde_wasm_bindgen as swb;@@ -18,7 +16,6 @@ struct OpenLegacyKitRecoveryInput {user_agent: Option<String>,}-/// Open a legacy-kit recovery session from two matching kit shares.#[wasm_bindgen]pub async fn legacy_kit_open_recovery(input: JsValue,@@ -36,7 +33,6 @@ pub async fn legacy_kit_open_recovery(Ok(LegacyKitRecoveryHandle { inner: handle })}-/// Handle to an opened legacy-kit recovery session.#[wasm_bindgen]pub struct LegacyKitRecoveryHandle {inner: ente_contacts::LegacyKitRecoveryHandle,@@ -44,18 +40,15 @@ pub struct LegacyKitRecoveryHandle {#[wasm_bindgen]impl LegacyKitRecoveryHandle {- /// Return the currently opened session.pub fn session(&self) -> Result<JsValue, ContactsError> {swb::to_value(self.inner.session()).map_err(Into::into)}- /// Refresh the recovery session status.pub async fn refresh_session(&self) -> Result<JsValue, ContactsError> {let session = self.inner.refresh_session().await?;swb::to_value(&session).map_err(Into::into)}- /// Complete password reset using this recovery session.pub async fn change_password(&self, new_password: String) -> Result<(), ContactsError> {self.inner.change_password(&new_password)diff --git a/rust/bindings/wasm/ente-wasm/src/lib.rs b/rust/bindings/wasm/ente-wasm/src/lib.rsindex be7626a5ce..34ccaa393f 100644--- a/rust/bindings/wasm/ente-wasm/src/lib.rs+++ b/rust/bindings/wasm/ente-wasm/src/lib.rs@@ -1,5 +1,3 @@-//! WASM bindings for Ente web apps.-use ente_wasm_log as _;mod auth;diff --git a/rust/bindings/wasm/ente-wasm/src/urls.rs b/rust/bindings/wasm/ente-wasm/src/urls.rsindex 05ef11291d..5e733e6f9e 100644--- a/rust/bindings/wasm/ente-wasm/src/urls.rs+++ b/rust/bindings/wasm/ente-wasm/src/urls.rs@@ -1,8 +1,5 @@-//! WASM bindings for URL construction.-use wasm_bindgen::prelude::*;-/// Generate the download URL for a file.#[wasm_bindgen]pub fn file_download_url(api_origin: &str, file_id: i64) -> String {ente_core::urls::file_download_url(api_origin, file_id)diff --git a/rust/bindings/wasm/space/src/lib.rs b/rust/bindings/wasm/space/src/lib.rsindex f31c1d7701..0bf401d55d 100644--- a/rust/bindings/wasm/space/src/lib.rs+++ b/rust/bindings/wasm/space/src/lib.rs@@ -1,5 +1,3 @@-//! WASM bindings for Ente Space.-use ente_wasm_log as _;mod space;diff --git a/rust/bindings/wasm/space/src/space.rs b/rust/bindings/wasm/space/src/space.rsindex 1a68bac4e6..109c3b5910 100644--- a/rust/bindings/wasm/space/src/space.rs+++ b/rust/bindings/wasm/space/src/space.rs@@ -1,5 +1,3 @@-//! WASM bindings for Space flows.-use std::collections::BTreeMap;use ente_core::{b64, http};@@ -13,7 +11,6 @@ use serde::{Deserialize, Serialize};use serde_wasm_bindgen as swb;use wasm_bindgen::prelude::*;-/// Space client error.#[wasm_bindgen]pub struct WasmSpaceError {code: String,@@ -23,25 +20,22 @@ pub struct WasmSpaceError {#[wasm_bindgen]impl WasmSpaceError {- /// Machine-readable error code.#[wasm_bindgen(getter)]pub fn code(&self) -> String {self.code.clone()}- /// Human-readable error message.#[wasm_bindgen(getter)]pub fn message(&self) -> String {self.message.clone()}- /// HTTP status code when the error came from an HTTP response.#[wasm_bindgen(getter)]pub fn status(&self) -> Option<u16> {self.status}- /// Preserve the structured error when web logging stringifies this value.+ // Preserve the structured error when web logging stringifies this value.#[wasm_bindgen(js_name = toString)]pub fn js_to_string(&self) -> String {format!("{}: {}", self.code, self.message)@@ -668,7 +662,6 @@ async fn resilient_message_conversation_activity_to_js(}}-/// Open an authenticated space context for web.#[wasm_bindgen(js_name = spaceOpenAccountCtx)]pub async fn space_open_account_ctx(input: JsValue,@@ -687,7 +680,6 @@ pub async fn space_open_account_ctx(Ok(SpaceAccountCtxHandle { inner: ctx })}-/// Open a read-only Space context from a username and fragment secret.#[wasm_bindgen(js_name = spaceOpenLinkCtx)]pub async fn space_open_link_ctx(input: JsValue) -> Result<SpaceLinkCtxHandle, WasmSpaceError> {let input: OpenSpaceLinkCtxJsInput = swb::from_value(input)?;@@ -703,7 +695,6 @@ pub async fn space_open_link_ctx(input: JsValue) -> Result<SpaceLinkCtxHandle, WOk(SpaceLinkCtxHandle { inner })}-/// Handle to a read-only Space link.#[wasm_bindgen]pub struct SpaceLinkCtxHandle {inner: SpaceLinkCtx,@@ -711,7 +702,6 @@ pub struct SpaceLinkCtxHandle {#[wasm_bindgen]impl SpaceLinkCtxHandle {- /// Return the decrypted profile bundled into this validated link.#[wasm_bindgen(js_name = getProfile)]pub fn get_profile(&self) -> Result<JsValue, WasmSpaceError> {let mut profile = profile_to_js(self.inner.profile().clone())?;@@ -719,7 +709,6 @@ impl SpaceLinkCtxHandle {swb::to_value(&profile).map_err(Into::into)}- /// List and decrypt posts exposed by this link.#[wasm_bindgen(js_name = listPosts)]pub async fn list_posts(&self) -> Result<JsValue, WasmSpaceError> {let page = self.inner.list_posts().await?;@@ -751,7 +740,6 @@ impl SpaceLinkCtxHandle {.map_err(Into::into)}- /// Subscribe this browser to new posts from the linked Space.#[wasm_bindgen(js_name = subscribeWebPush)]pub async fn subscribe_web_push(&self,@@ -765,7 +753,6 @@ impl SpaceLinkCtxHandle {.map_err(Into::into)}- /// Remove this linked Space from the browser's push targets.#[wasm_bindgen(js_name = unsubscribeWebPush)]pub async fn unsubscribe_web_push(&self, endpoint: String) -> Result<(), WasmSpaceError> {self.inner@@ -774,7 +761,6 @@ impl SpaceLinkCtxHandle {.map_err(Into::into)}- /// Download and decrypt one post photo.#[wasm_bindgen(js_name = downloadPostAsset)]pub async fn download_post_asset(&self,@@ -788,7 +774,6 @@ impl SpaceLinkCtxHandle {.map_err(Into::into)}- /// Download and decrypt the linked Space avatar.#[wasm_bindgen(js_name = downloadAvatar)]pub async fn download_avatar(&self,@@ -801,7 +786,6 @@ impl SpaceLinkCtxHandle {.map_err(Into::into)}- /// Download and decrypt the linked Space cover.#[wasm_bindgen(js_name = downloadCover)]pub async fn download_cover(&self,@@ -815,7 +799,6 @@ impl SpaceLinkCtxHandle {}}-/// Handle to an authenticated space context.#[wasm_bindgen]pub struct SpaceAccountCtxHandle {inner: AccountSpaceCtx,@@ -823,7 +806,6 @@ pub struct SpaceAccountCtxHandle {#[wasm_bindgen]impl SpaceAccountCtxHandle {- /// Return the active Space link or create it lazily.#[wasm_bindgen(js_name = getOrCreateSpaceLink)]pub async fn get_or_create_space_link(&self,@@ -838,7 +820,6 @@ impl SpaceAccountCtxHandle {.map_err(Into::into)}- /// Replace the current Space link with a new fragment secret.#[wasm_bindgen(js_name = rotateSpaceLink)]pub async fn rotate_space_link(&self, space_id: String) -> Result<JsValue, WasmSpaceError> {let value = self.inner.rotate_space_link(&space_id).await?;@@ -850,7 +831,6 @@ impl SpaceAccountCtxHandle {.map_err(Into::into)}- /// Create a space with an encrypted JSON profile payload.#[wasm_bindgen(js_name = createSpace)]pub async fn create_space(&self,@@ -870,13 +850,11 @@ impl SpaceAccountCtxHandle {.map_err(Into::into)}- /// List spaces owned by the current account.#[wasm_bindgen(js_name = listOwnedSpaces)]pub async fn list_owned_spaces(&self) -> Result<JsValue, WasmSpaceError> {swb::to_value(&self.inner.list_owned_spaces().await?).map_err(Into::into)}- /// Fetch and decrypt a space profile.#[wasm_bindgen(js_name = getSpaceProfile)]pub async fn get_space_profile(&self,@@ -891,7 +869,6 @@ impl SpaceAccountCtxHandle {.map_err(Into::into)}- /// Update a space's encrypted JSON profile payload.#[wasm_bindgen(js_name = updateSpaceProfile)]pub async fn update_space_profile(&self,@@ -907,7 +884,6 @@ impl SpaceAccountCtxHandle {.map_err(Into::into)}- /// Update a space profile and replace its encrypted avatar asset.#[wasm_bindgen(js_name = updateSpaceProfileWithAvatar)]pub async fn update_space_profile_with_avatar(&self,@@ -937,7 +913,6 @@ impl SpaceAccountCtxHandle {.map_err(Into::into)}- /// Update a space profile and replace its encrypted cover asset.#[wasm_bindgen(js_name = updateSpaceProfileWithCover)]pub async fn update_space_profile_with_cover(&self,@@ -974,7 +949,6 @@ impl SpaceAccountCtxHandle {.map_err(Into::into)}- /// Update a space's slug.#[wasm_bindgen(js_name = updateSpaceSlug)]pub async fn update_space_slug(&self,@@ -985,7 +959,6 @@ impl SpaceAccountCtxHandle {.map_err(Into::into)}- /// Lookup public space metadata by slug.#[wasm_bindgen(js_name = lookupSpaceBySlug)]pub async fn lookup_space_by_slug(&self,@@ -994,7 +967,6 @@ impl SpaceAccountCtxHandle {swb::to_value(&self.inner.lookup_space_by_slug(&space_slug).await?).map_err(Into::into)}- /// Return whether the target space is self, friend, or neither.#[wasm_bindgen(js_name = getRelationship)]pub async fn get_relationship(&self,@@ -1010,7 +982,6 @@ impl SpaceAccountCtxHandle {.map_err(Into::into)}- /// Request to add a public username as a friend.#[wasm_bindgen(js_name = requestFriendByUsername)]pub async fn request_friend_by_username(&self,@@ -1026,7 +997,6 @@ impl SpaceAccountCtxHandle {.map_err(Into::into)}- /// List the current account feed with captions decrypted.#[wasm_bindgen(js_name = listFeed)]pub async fn list_feed(&self,@@ -1063,13 +1033,11 @@ impl SpaceAccountCtxHandle {.map_err(Into::into)}- /// Return whether the current account has unread notification activity.#[wasm_bindgen(js_name = unreadStatus)]pub async fn unread_status(&self, space_id: String) -> Result<JsValue, WasmSpaceError> {swb::to_value(&self.inner.unread_status(&space_id).await?).map_err(Into::into)}- /// Mark notification activity for one friend as read.#[wasm_bindgen(js_name = markNotificationsRead)]pub async fn mark_notifications_read(&self,@@ -1085,7 +1053,6 @@ impl SpaceAccountCtxHandle {.map_err(Into::into)}- /// List posts on a space with captions decrypted.#[wasm_bindgen(js_name = listPosts)]pub async fn list_posts(&self,@@ -1106,7 +1073,6 @@ impl SpaceAccountCtxHandle {.map_err(Into::into)}- /// Fetch one post with its caption decrypted.#[wasm_bindgen(js_name = getPost)]pub async fn get_post(&self,@@ -1125,7 +1091,6 @@ impl SpaceAccountCtxHandle {swb::to_value(&account_post_to_js(&self.inner, post, decrypted).await?).map_err(Into::into)}- /// Create a single-photo post with optional caption.#[wasm_bindgen(js_name = createPhotoPost)]pub async fn create_photo_post(&self,@@ -1170,7 +1135,6 @@ impl SpaceAccountCtxHandle {swb::to_value(&account_post_to_js(&self.inner, post, decrypted).await?).map_err(Into::into)}- /// Download and decrypt one object from a space post.#[wasm_bindgen(js_name = downloadPostAsset)]pub async fn download_post_asset(&self,@@ -1185,7 +1149,6 @@ impl SpaceAccountCtxHandle {.map_err(Into::into)}- /// Download and decrypt one object from an already fetched space post.#[wasm_bindgen(js_name = downloadPostAssetWithKey)]pub async fn download_post_asset_with_key(&self,@@ -1207,7 +1170,6 @@ impl SpaceAccountCtxHandle {.map_err(Into::into)}- /// Download and decrypt a space avatar using an owned or friend space key.#[wasm_bindgen(js_name = downloadSpaceAvatar)]pub async fn download_space_avatar(&self,@@ -1228,7 +1190,6 @@ impl SpaceAccountCtxHandle {.map_err(Into::into)}- /// Download and decrypt a space cover using an owned or friend space key.#[wasm_bindgen(js_name = downloadSpaceCover)]pub async fn download_space_cover(&self,@@ -1249,7 +1210,6 @@ impl SpaceAccountCtxHandle {.map_err(Into::into)}- /// Like or unlike a post.#[wasm_bindgen(js_name = likePost)]pub async fn like_post(&self,@@ -1260,7 +1220,6 @@ impl SpaceAccountCtxHandle {swb::to_value(&self.inner.like_post(&space_id, post_id, like).await?).map_err(Into::into)}- /// Send a regular 1:1 message to a friend space.#[wasm_bindgen(js_name = sendMessage)]pub async fn send_message(&self,@@ -1279,7 +1238,6 @@ impl SpaceAccountCtxHandle {swb::to_value(&account_message_to_js(message, decrypted).await?).map_err(Into::into)}- /// Send a 1:1 reply to an existing message.#[wasm_bindgen(js_name = replyToMessage)]pub async fn reply_to_message(&self,@@ -1299,7 +1257,6 @@ impl SpaceAccountCtxHandle {swb::to_value(&account_message_to_js(message, decrypted).await?).map_err(Into::into)}- /// Send a private post reply message to the post owner.#[wasm_bindgen(js_name = replyToPost)]pub async fn reply_to_post(&self,@@ -1319,7 +1276,6 @@ impl SpaceAccountCtxHandle {swb::to_value(&account_message_to_js(message, decrypted).await?).map_err(Into::into)}- /// Like or unlike a message.#[wasm_bindgen(js_name = likeMessage)]pub async fn like_message(&self,@@ -1336,7 +1292,6 @@ impl SpaceAccountCtxHandle {.map_err(Into::into)}- /// Delete a message sent by the current account.#[wasm_bindgen(js_name = deleteMessage)]pub async fn delete_message(&self,@@ -1349,7 +1304,6 @@ impl SpaceAccountCtxHandle {.map_err(Into::into)}- /// List current friends, pending requests, and latest chat summaries.#[wasm_bindgen(js_name = listConversations)]pub async fn list_conversations(&self, space_id: String) -> Result<JsValue, WasmSpaceError> {let response = self.inner.list_conversations(&space_id).await?;@@ -1402,7 +1356,6 @@ impl SpaceAccountCtxHandle {.map_err(Into::into)}- /// List a 1:1 message thread with decrypted messages.#[wasm_bindgen(js_name = listMessageThread)]pub async fn list_message_thread(&self,@@ -1429,7 +1382,6 @@ impl SpaceAccountCtxHandle {.map_err(Into::into)}- /// Update a post caption.#[wasm_bindgen(js_name = updatePostCaption)]pub async fn update_post_caption(&self,@@ -1456,7 +1408,6 @@ impl SpaceAccountCtxHandle {.map_err(Into::into)}- /// Delete a post.#[wasm_bindgen(js_name = deletePost)]pub async fn delete_post(&self, space_id: String, post_id: i64) -> Result<(), WasmSpaceError> {self.inner@@ -1465,7 +1416,6 @@ impl SpaceAccountCtxHandle {.map_err(Into::into)}- /// List friends for a space.#[wasm_bindgen(js_name = listSpaceFriends)]pub async fn list_space_friends(&self, space_id: String) -> Result<JsValue, WasmSpaceError> {let friends = self.inner.list_space_friends(&space_id).await?;@@ -1480,7 +1430,6 @@ impl SpaceAccountCtxHandle {swb::to_value(&items).map_err(Into::into)}- /// List incoming friend requests for the current account.#[wasm_bindgen(js_name = listFriendRequests)]pub async fn list_friend_requests(&self, space_id: String) -> Result<JsValue, WasmSpaceError> {let requests = self.inner.list_friend_requests(&space_id).await?;@@ -1495,7 +1444,6 @@ impl SpaceAccountCtxHandle {swb::to_value(&items).map_err(Into::into)}- /// List outgoing friend requests for the current account.#[wasm_bindgen(js_name = listSentFriendRequests)]pub async fn list_sent_friend_requests(&self,@@ -1513,7 +1461,6 @@ impl SpaceAccountCtxHandle {swb::to_value(&items).map_err(Into::into)}- /// Confirm an incoming friend request.#[wasm_bindgen(js_name = confirmFriendRequest)]pub async fn confirm_friend_request(&self,@@ -1529,7 +1476,6 @@ impl SpaceAccountCtxHandle {.map_err(Into::into)}- /// Delete a pending friend request.#[wasm_bindgen(js_name = deleteFriendRequest)]pub async fn delete_friend_request(&self,@@ -1542,7 +1488,6 @@ impl SpaceAccountCtxHandle {.map_err(Into::into)}- /// Remove a friend by their space ID.#[wasm_bindgen(js_name = removeFriendBySpace)]pub async fn remove_friend_by_space(&self,@@ -1555,13 +1500,11 @@ impl SpaceAccountCtxHandle {.map_err(Into::into)}- /// List friend shares available to the current account.#[wasm_bindgen(js_name = listFriendShares)]pub async fn list_friend_shares(&self, space_id: String) -> Result<JsValue, WasmSpaceError> {swb::to_value(&self.inner.list_friend_shares(&space_id).await?).map_err(Into::into)}- /// Refresh friend shares for a rotated space key.#[wasm_bindgen(js_name = refreshFriendShares)]pub async fn refresh_friend_shares(&self, space_id: String) -> Result<usize, WasmSpaceError> {self.innerdiff --git a/rust/crates/accounts/src/auth/api.rs b/rust/crates/accounts/src/auth/api.rsindex b2382111ca..bd9b7b601f 100644--- a/rust/crates/accounts/src/auth/api.rs+++ b/rust/crates/accounts/src/auth/api.rs@@ -1,8 +1,3 @@-//! High-level authentication API for applications.-//!-//! This module provides the main entry points that CLI/GUI applications should use-//! for authentication flows. It wraps the lower-level crypto operations.-use std::fmt;use ente_core::b64;@@ -13,11 +8,8 @@ use srp::ClientG4096;use super::{KeyAttributes, SrpAttributes};use crate::error::{Error, Result};-/// Credentials derived from password for SRP authentication.pub struct SrpCredentials {- /// Key encryption key (32 bytes) - used to decrypt master key after auth.pub kek: SecretVec,- /// Login key (16 bytes) - used as password in SRP protocol.pub login_key: SecretVec,}@@ -30,13 +22,9 @@ impl fmt::Debug for SrpCredentials {}}-/// Decrypted secrets after successful authentication.pub struct DecryptedSecrets {- /// Master key for encrypting/decrypting data.pub master_key: SecretVec,- /// Secret key (private key) for asymmetric operations.pub secret_key: SecretVec,- /// Authentication token (decrypted).pub token: SecretVec,}@@ -50,15 +38,10 @@ impl fmt::Debug for DecryptedSecrets {}}-/// A derived key-encryption-key and the parameters used to derive it.pub struct GeneratedKek {- /// Derived KEK bytes.pub key: SecretVec,- /// Salt used for Argon2 derivation.pub salt: Vec<u8>,- /// Argon2 memory limit in bytes.pub mem_limit: u32,- /// Argon2 operations limit.pub ops_limit: u32,}@@ -73,13 +56,9 @@ impl fmt::Debug for GeneratedKek {}}-/// Attributes needed to register or update SRP for a user.pub struct GeneratedSrpSetup {- /// SRP salt bytes.pub srp_salt: Vec<u8>,- /// SRP verifier bytes.pub srp_verifier: Vec<u8>,- /// Derived 16-byte login sub-key bytes.pub login_sub_key: SecretVec,}@@ -93,17 +72,6 @@ impl fmt::Debug for GeneratedSrpSetup {}}-/// Derive SRP credentials from password.-///-/// This is the first step in the SRP login flow. Call this after password entry-/// to get the credentials needed for the SRP protocol.-///-/// # Arguments-/// * `password` - User's password-/// * `srp_attrs` - SRP attributes from the server-///-/// # Returns-/// * `SrpCredentials` containing KEK (for later decryption) and login_key (for SRP)pub fn derive_srp_credentials(password: &str, srp_attrs: &SrpAttributes) -> Result<SrpCredentials> {let kek_salt =b64::decode(&srp_attrs.kek_salt).map_err(|e| Error::Decode(format!("kek_salt: {}", e)))?;@@ -126,16 +94,6 @@ pub fn derive_srp_credentials(password: &str, srp_attrs: &SrpAttributes) -> Resu})}-/// Derive only the KEK from password.-///-/// Use this for email MFA flow where SRP is skipped. The KEK is used-/// to decrypt the master key after email/TOTP verification.-///-/// # Arguments-/// * `password` - User's password-/// * `kek_salt` - Base64-encoded salt from key attributes-/// * `mem_limit` - Argon2 memory limit-/// * `ops_limit` - Argon2 operations limitpub fn derive_kek(password: &str,kek_salt: &str,@@ -157,7 +115,6 @@ pub fn derive_kek(Ok(SecretVec::new(key.as_bytes().to_vec()))}-/// Generate a KEK using the current adaptive sensitive client policy.pub fn generate_sensitive_kek(password: &str) -> Result<GeneratedKek> {let derived = argon::derive_sensitive_key(password).map_err(|e| match e {crypto::Error::InvalidKeyDerivationParams(_) => Error::Crypto(e),@@ -167,7 +124,6 @@ pub fn generate_sensitive_kek(password: &str) -> Result<GeneratedKek> {Ok(generated_kek(derived))}-/// Generate a KEK using the current interactive web policy.pub fn generate_interactive_kek(password: &str) -> Result<GeneratedKek> {let derived = argon::derive_interactive_key(password)?;@@ -183,13 +139,11 @@ fn generated_kek(derived: argon::DerivedKey) -> GeneratedKek {}}-/// Generate the SRP setup payload for a given KEK and SRP user ID.pub fn generate_srp_setup(kek: &[u8], srp_user_id: &str) -> Result<GeneratedSrpSetup> {let login_sub_key = kdf::derive_login_key(&crypto::Key::try_from_slice(kek)?);generate_srp_setup_with_login_key(&login_sub_key, srp_user_id)}-/// Generate the SRP setup payload from an already-derived login key.pub fn generate_srp_setup_with_login_key(login_key: &[u8],srp_user_id: &str,@@ -212,10 +166,6 @@ pub fn generate_srp_setup_with_login_key(})}-/// Decrypt only the master key and secret key.-///-/// Use this when you only need access to the decrypted keys (e.g. when the-/// auth token comes from a different source than a sealed box).pub fn decrypt_keys_only(kek: &[u8], key_attrs: &KeyAttributes) -> Result<(SecretVec, SecretVec)> {let encrypted_key = b64::decode(&key_attrs.encrypted_key).map_err(|e| Error::Decode(format!("encrypted_key: {}", e)))?;@@ -248,18 +198,6 @@ pub fn decrypt_keys_only(kek: &[u8], key_attrs: &KeyAttributes) -> Result<(SecreOk((master_key, secret_key))}-/// Decrypt secrets after successful authentication.-///-/// Call this after SRP + 2FA is complete, when you have the key attributes-/// and encrypted token from the server.-///-/// # Arguments-/// * `kek` - Key encryption key (from `derive_srp_credentials` or `derive_kek`)-/// * `key_attrs` - Key attributes from the server-/// * `encrypted_token` - Base64-encoded encrypted authentication token-///-/// # Returns-/// * `DecryptedSecrets` containing master_key, secret_key, and tokenpub fn decrypt_secrets(kek: &[u8],key_attrs: &KeyAttributes,@@ -267,7 +205,6 @@ pub fn decrypt_secrets() -> Result<DecryptedSecrets> {let (master_key, secret_key) = decrypt_keys_only(kek, key_attrs)?;- // Decrypt token with sealed box (public key crypto)let public_key = b64::decode(&key_attrs.public_key).map_err(|e| Error::Decode(format!("public_key: {}", e)))?;let sealed_token = b64::decode(encrypted_token)@@ -320,7 +257,6 @@ mod tests {let gen_result =generate_keys_with_strength(password, KeyDerivationStrength::Interactive).unwrap();- // Create a sealed tokenlet token = b"auth_token_12345";let public_key = b64::decode(&gen_result.key_attributes.public_key).unwrap();let sealed_token = sealed::seal(@@ -330,7 +266,6 @@ mod tests {.unwrap();let encrypted_token = b64::encode(&sealed_token);- // Derive KEKlet kek = derive_kek(password,&gen_result.key_attributes.kek_salt,@@ -339,10 +274,8 @@ mod tests {).unwrap();- // Decrypt secretslet secrets = decrypt_secrets(&kek, &gen_result.key_attributes, &encrypted_token).unwrap();- // Verifylet original_master_key = b64::decode(&gen_result.private_key_attributes.key).unwrap();assert_eq!(secrets.master_key.as_ref(), original_master_key.as_slice());@@ -367,7 +300,6 @@ mod tests {.unwrap();let encrypted_token = b64::encode(&sealed_token);- // Derive KEK with wrong passwordlet kek = derive_kek("wrong_password",&gen_result.key_attributes.kek_salt,@@ -376,7 +308,6 @@ mod tests {).unwrap();- // Decryption should faillet result = decrypt_secrets(&kek, &gen_result.key_attributes, &encrypted_token);assert!(matches!(result, Err(Error::IncorrectPassword)));}diff --git a/rust/crates/accounts/src/auth/key_gen.rs b/rust/crates/accounts/src/auth/key_gen.rsindex 2ebcf7aa89..a12e5d4dba 100644--- a/rust/crates/accounts/src/auth/key_gen.rs+++ b/rust/crates/accounts/src/auth/key_gen.rs@@ -1,23 +1,17 @@-//! Key generation for new account sign-up.-use ente_core::b64;use ente_core::crypto::{self, Key, SecretString, SecretVec, argon, kdf, secretbox};use super::{KeyAttributes, KeyGenResult, PrivateKeyAttributes};use crate::error::Result;-/// Key derivation strength for password-based key generation.#[derive(Debug, Clone, Copy, Default)]pub enum KeyDerivationStrength {- /// Fast derivation (64MB, 2 ops) - for testing onlyInteractive,- /// Strong derivation (1GB, 4 ops) - for production#[default]Sensitive,}-/// Encrypt data and return (encrypted_data, nonce) as base64 strings.-/// The encrypted_data is MAC || ciphertext format (compatible with Dart).+// Account APIs expect the nonce separately from the encrypted data.fn encrypt_to_b64(plaintext: &[u8], key: &Key) -> Result<(String, String)> {let encrypted = secretbox::encrypt(plaintext, key);Ok((@@ -26,40 +20,31 @@ fn encrypt_to_b64(plaintext: &[u8], key: &Key) -> Result<(String, String)> {))}-/// Generate all keys needed for a new account, with the specified derivation-/// strength.pub fn generate_keys_with_strength(password: &str,strength: KeyDerivationStrength,) -> Result<KeyGenResult> {- // Create master key and recovery keylet master_key = Key::generate();let recovery_key = Key::generate();- // Encrypt master key with recovery key and vice versalet (enc_master_with_recovery, nonce_master_recovery) =encrypt_to_b64(master_key.as_bytes(), &recovery_key)?;let (enc_recovery_with_master, nonce_recovery_master) =encrypt_to_b64(recovery_key.as_bytes(), &master_key)?;- // Derive key-encryption-key from passwordlet derived = match strength {KeyDerivationStrength::Interactive => argon::derive_interactive_key(password)?,KeyDerivationStrength::Sensitive => argon::derive_sensitive_key(password)?,};let login_key = kdf::derive_login_key(&derived.key);- // Encrypt master key with derived keylet (enc_key, key_nonce) = encrypt_to_b64(master_key.as_bytes(), &derived.key)?;- // Generate X25519 keypairlet secret_key = crypto::SecretKey::generate();let public_key = secret_key.public_key();- // Encrypt secret key with master keylet (enc_secret_key, secret_key_nonce) = encrypt_to_b64(secret_key.as_bytes(), &master_key)?;- // Build key attributes for serverlet key_attributes = KeyAttributes {kek_salt: b64::encode(derived.salt.as_bytes()),kek_hash: None,@@ -76,7 +61,6 @@ pub fn generate_keys_with_strength(recovery_key_decryption_nonce: Some(nonce_recovery_master),};- // Build private key attributes for local storagelet private_key_attributes = PrivateKeyAttributes {key: SecretString::new(b64::encode(master_key.as_bytes())),recovery_key: SecretString::new(hex::encode(recovery_key.as_bytes())),@@ -91,9 +75,6 @@ pub fn generate_keys_with_strength(})}-/// Generate new key attributes when user changes password.-///-/// Preserves existing key material and recovery fields.pub fn generate_key_attributes_for_new_password(master_key: &[u8],existing_attributes: &KeyAttributes,@@ -107,23 +88,19 @@ pub fn generate_key_attributes_for_new_password()}-/// Generate new key attributes with specified derivation strength.-///-/// Preserves existing key material and recovery fields.+// Changing the password must not rotate the account or recovery keys.pub fn generate_key_attributes_for_new_password_with_strength(master_key: &[u8],existing_attributes: &KeyAttributes,password: &str,strength: KeyDerivationStrength,) -> Result<(KeyAttributes, SecretVec)> {- // Derive new KEK from new passwordlet derived = match strength {KeyDerivationStrength::Interactive => argon::derive_interactive_key(password)?,KeyDerivationStrength::Sensitive => argon::derive_sensitive_key(password)?,};let login_key = kdf::derive_login_key(&derived.key);- // Encrypt master key with new derived keylet (enc_key, key_nonce) = encrypt_to_b64(master_key, &derived.key)?;let key_attributes = KeyAttributes {@@ -149,7 +126,6 @@ pub fn generate_key_attributes_for_new_password_with_strength(Ok((key_attributes, login_key))}-/// Create a new recovery key for an existing account.pub fn create_new_recovery_key(master_key: &[u8],) -> Result<(String, String, String, String, String)> {@@ -174,7 +150,6 @@ mod tests {use super::*;use ente_core::crypto::Nonce;- // Typed-decrypt helper for byte-slice test material.fn decrypt_raw(data: &[u8], nonce: &[u8], key: &[u8]) -> Vec<u8> {secretbox::decrypt(data,@@ -184,7 +159,6 @@ mod tests {.unwrap()}- // Use Interactive strength for fast testsfn generate_test_keys(password: &str) -> Result<KeyGenResult> {generate_keys_with_strength(password, KeyDerivationStrength::Interactive)}@@ -300,7 +274,6 @@ mod tests {assert_ne!(new_attrs.kek_salt, initial.key_attributes.kek_salt);assert_ne!(new_login_key, initial.login_key);- // Verify we can decrypt with new passwordlet kek_salt = b64::decode(&new_attrs.kek_salt).unwrap();let salt = crypto::Salt::try_from_slice(&kek_salt).unwrap();let kek = argon::derive_key(diff --git a/rust/crates/accounts/src/auth/mod.rs b/rust/crates/accounts/src/auth/mod.rsindex 89f0e4cb9b..3c40a06de3 100644--- a/rust/crates/accounts/src/auth/mod.rs+++ b/rust/crates/accounts/src/auth/mod.rs@@ -1,8 +1,3 @@-//! The account key hierarchy and login protocol.-//!-//! Key generation at sign-up, secret decryption at login, recovery keys, and-//! the SRP handshake ([`SrpSession`]).-mod api;mod key_gen;mod recovery;@@ -11,7 +6,6 @@ mod types;pub use srp::SrpSession;-// High-level API (recommended for applications)pub use api::{DecryptedSecrets, GeneratedKek, GeneratedSrpSetup, SrpCredentials};pub use api::{decrypt_keys_only, decrypt_secrets, derive_kek, derive_srp_credentials,@@ -19,14 +13,11 @@ pub use api::{generate_srp_setup_with_login_key,};-// Key generation (for signup)pub use key_gen::{KeyDerivationStrength, create_new_recovery_key, generate_key_attributes_for_new_password,generate_key_attributes_for_new_password_with_strength, generate_keys_with_strength,};-// Recoverypub use recovery::{get_recovery_key, recovery_key_from_mnemonic_or_hex, recovery_key_to_mnemonic};-// Typespub use types::{KeyAttributes, KeyGenResult, PrivateKeyAttributes, SrpAttributes};diff --git a/rust/crates/accounts/src/auth/recovery.rs b/rust/crates/accounts/src/auth/recovery.rsindex 7c4d39b34e..763248ffba 100644--- a/rust/crates/accounts/src/auth/recovery.rs+++ b/rust/crates/accounts/src/auth/recovery.rs@@ -1,5 +1,3 @@-//! Account recovery using recovery key.-use bip39::{Language, Mnemonic};use ente_core::b64;@@ -8,7 +6,6 @@ use ente_core::crypto::{self, SecretVec, secretbox};use super::KeyAttributes;use crate::error::{Error, Result};-/// Get the recovery key from stored encrypted form.pub fn get_recovery_key(master_key: &[u8], attributes: &KeyAttributes) -> Result<String> {let encrypted_recovery_key = attributes.recovery_key_encrypted_with_master_key@@ -39,10 +36,7 @@ pub fn get_recovery_key(master_key: &[u8], attributes: &KeyAttributes) -> ResultOk(hex::encode(&recovery_key))}-/// Convert a user-provided recovery key mnemonic or hex string into raw bytes.-///-/// The mnemonic form must be a 24-word English BIP-39 phrase. The legacy hex-/// form is still accepted for compatibility.+// Accept 24-word English BIP-39 mnemonics and legacy hex recovery keys.pub fn recovery_key_from_mnemonic_or_hex(recovery_key_mnemonic_or_hex: &str) -> Result<SecretVec> {let trimmed_input = recovery_key_mnemonic_or_hex.split_whitespace()@@ -70,7 +64,6 @@ pub fn recovery_key_from_mnemonic_or_hex(recovery_key_mnemonic_or_hex: &str) ->Ok(recovery_key)}-/// Convert a base64-encoded recovery key into its 24-word English mnemonic.pub fn recovery_key_to_mnemonic(recovery_key_b64: &str) -> Result<String> {let recovery_key = SecretVec::new(b64::decode(recovery_key_b64).map_err(|e| Error::Decode(format!("recovery_key: {}", e)))?,diff --git a/rust/crates/accounts/src/auth/srp.rs b/rust/crates/accounts/src/auth/srp.rsindex ae0aa7d347..9cd35ca94a 100644--- a/rust/crates/accounts/src/auth/srp.rs+++ b/rust/crates/accounts/src/auth/srp.rs@@ -1,9 +1,3 @@-//! SRP (Secure Remote Password) session implementation.-//!-//! Provides a minimal SRP client state machine that avoids exposing low-level-//! step ordering (e.g. calling set_b before compute_m1). Callers only need to-//! exchange the public value and proofs with the server.-use ente_core::crypto::SecretVec;use sha2::{Digest, Sha256};use srp::ClientG4096;@@ -12,13 +6,6 @@ use zeroize::Zeroize;use crate::error::{Error, Result};-/// SRP session for password-based authentication.-///-/// Usage:-/// 1. Create session with `new()`-/// 2. Send `public_a()` to the server-/// 3. Call `compute_m1(server_b)` to get the client proof-/// 4. Optionally verify server proof with `verify_m2(server_m2)`pub struct SrpSession {inner: ClientG4096<Sha256>,identity: Vec<u8>,@@ -30,7 +17,7 @@ pub struct SrpSession {k: Option<SecretVec>,}-const SRP_N_BYTES: usize = 512; // 4096-bit group size+const SRP_N_BYTES: usize = 512;fn pad_to_n(input: &[u8]) -> Vec<u8> {if input.len() >= SRP_N_BYTES {@@ -43,12 +30,6 @@ fn pad_to_n(input: &[u8]) -> Vec<u8> {}impl SrpSession {- /// Create a new SRP session.- ///- /// # Arguments- /// * `srp_user_id` - The SRP user ID (UUID string)- /// * `srp_salt` - The SRP salt (raw bytes, not base64)- /// * `login_key` - The login key derived from password (16 bytes)pub fn new(srp_user_id: &str, srp_salt: &[u8], login_key: &[u8]) -> Result<Self> {if login_key.len() != 16 {return Err(Error::InvalidKey(format!(@@ -59,12 +40,10 @@ impl SrpSession {let client = ClientG4096::<Sha256>::new();- // Generate random ephemeral private key (64 bytes)let mut a_private = vec![0u8; 64];getrandom::getrandom(&mut a_private).map_err(|e| Error::Srp(format!("Failed to generate random bytes: {}", e)))?;- // Compute public ephemerallet a_public = client.compute_public_ephemeral(&a_private);// Use the UUID string directly as bytes (matching TypeScript)@@ -82,18 +61,11 @@ impl SrpSession {})}- /// Get the client's public ephemeral value A (padded to N length).- ///- /// This should be sent to the server to create an SRP session.- /// Returns raw bytes (caller should base64 encode for API).+ // Ente's SRP wire format pads A to the 4096-bit group size.pub fn public_a(&self) -> Vec<u8> {pad_to_n(&self.a_public)}- /// Compute the client proof M1 from the server's public value B.- ///- /// This processes the server reply and stores internal state for- /// `verify_m2()`.pub fn compute_m1(&mut self, server_b: &[u8]) -> Result<Vec<u8>> {let verifier = self.inner@@ -107,7 +79,6 @@ impl SrpSession {.map_err(|e| Error::Srp(format!("Failed to process server response: {:?}", e)))?;// The srp crate uses S directly for M2, but our server uses K = H(S).- // Compute the proof values the way the server does.let s = verifier.key();let s_padded = pad_to_n(s);let a_padded = pad_to_n(&self.a_public);@@ -128,17 +99,12 @@ impl SrpSession {self.m1 = Some(SecretVec::new(m1.clone()));self.k = Some(SecretVec::new(k));- // No longer needed after we have computed M1/K.self.login_key.zeroize();self.a_private.zeroize();Ok(m1)}- /// Verify the server's proof M2.- ///- /// # Arguments- /// * `server_m2` - The server's proof M2 (raw bytes, not base64)pub fn verify_m2(&self, server_m2: &[u8]) -> Result<()> {let m1 = self.m1@@ -191,7 +157,6 @@ mod tests {let session = SrpSession::new(srp_user_id, &srp_salt, &login_key).unwrap();- // Public value should be generatedlet a = session.public_a();assert!(!a.is_empty());assert!(a.len() >= SRP_N_BYTES);@@ -344,7 +309,6 @@ mod tests {let mut session = SrpSession::new(srp_user_id, &srp_salt, &login_key).unwrap();session.compute_m1(&b_pub).unwrap();- // Precondition: m1 and k are populated with non-zero dataassert!(session.m1.as_ref().unwrap().iter().any(|&b| b != 0),"precondition: m1 should be non-zero after compute_m1"@@ -377,7 +341,7 @@ mod tests {fn test_srp_session_invalid_login_key() {let srp_user_id = "test-user-id";let srp_salt = [0u8; 16];- let login_key = [0u8; 32]; // Wrong size+ let login_key = [0u8; 32];let result = SrpSession::new(srp_user_id, &srp_salt, &login_key);assert!(result.is_err());diff --git a/rust/crates/accounts/src/auth/types.rs b/rust/crates/accounts/src/auth/types.rsindex a833d29836..d513abb98d 100644--- a/rust/crates/accounts/src/auth/types.rs+++ b/rust/crates/accounts/src/auth/types.rs@@ -1,5 +1,3 @@-//! Data types for authentication operations.-use std::fmt;use serde::{Deserialize, Serialize};@@ -7,39 +5,26 @@ use uuid::Uuid;use ente_core::crypto::{SecretString, SecretVec};-/// Attributes stored on server for key derivation and encrypted keys.#[derive(Clone, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct KeyAttributes {- /// Salt for deriving key-encryption-key from password (base64)pub kek_salt: String,- /// Legacy KEK hash, present only on old accounts (base64)+ // Legacy KEK hash, present only on old accounts (base64).#[serde(skip_serializing_if = "Option::is_none")]pub kek_hash: Option<String>,- /// Master key encrypted with KEK (base64)pub encrypted_key: String,- /// Nonce for master key decryption (base64)pub key_decryption_nonce: String,- /// X25519 public key (base64)pub public_key: String,- /// Secret key encrypted with master key (base64)pub encrypted_secret_key: String,- /// Nonce for secret key decryption (base64)pub secret_key_decryption_nonce: String,- /// Argon2 memory limitpub mem_limit: u32,- /// Argon2 ops limitpub ops_limit: u32,- /// Master key encrypted with recovery key (base64)#[serde(skip_serializing_if = "Option::is_none")]pub master_key_encrypted_with_recovery_key: Option<String>,- /// Nonce for master key decryption with recovery key (base64)#[serde(skip_serializing_if = "Option::is_none")]pub master_key_decryption_nonce: Option<String>,- /// Recovery key encrypted with master key (base64)#[serde(skip_serializing_if = "Option::is_none")]pub recovery_key_encrypted_with_master_key: Option<String>,- /// Nonce for recovery key decryption (base64)#[serde(skip_serializing_if = "Option::is_none")]pub recovery_key_decryption_nonce: Option<String>,}@@ -88,13 +73,9 @@ impl fmt::Debug for KeyAttributes {}}-/// Private key material (never sent to server).pub struct PrivateKeyAttributes {- /// Master key (base64)pub key: SecretString,- /// Recovery key (hex for display to user)pub recovery_key: SecretString,- /// X25519 secret key (base64)pub secret_key: SecretString,}@@ -108,15 +89,10 @@ impl fmt::Debug for PrivateKeyAttributes {}}-/// Result of key generation during sign-up.pub struct KeyGenResult {- /// Attributes to send to serverpub key_attributes: KeyAttributes,- /// Private keys to store locallypub private_key_attributes: PrivateKeyAttributes,- /// Key-encryption-key used to encrypt the master key and seed SRP setup.pub key_encryption_key: SecretVec,- /// Login key for SRP registration (16 bytes)pub login_key: SecretVec,}@@ -135,22 +111,15 @@ fn default_email_mfa_enabled() -> bool {true}-/// SRP attributes received from server (`/users/srp/attributes`).#[derive(Debug, Clone, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct SrpAttributes {- /// SRP user ID#[serde(rename = "srpUserID")]pub srp_user_id: Uuid,- /// SRP salt (base64)pub srp_salt: String,- /// Argon2 memory limitpub mem_limit: u32,- /// Argon2 ops limitpub ops_limit: u32,- /// KEK salt (base64) - same as in KeyAttributespub kek_salt: String,- /// Whether email MFA is enabled (use email OTT instead of SRP)#[serde(rename = "isEmailMFAEnabled", default = "default_email_mfa_enabled")]pub is_email_mfa_enabled: bool,}diff --git a/rust/crates/accounts/src/client.rs b/rust/crates/accounts/src/client.rsindex ab34302bb6..23a8033613 100644--- a/rust/crates/accounts/src/client.rs+++ b/rust/crates/accounts/src/client.rs@@ -1,5 +1,3 @@-//! Shared low-level account client.-use ente_core::b64;use ente_core::{crypto::SecretVec,@@ -42,14 +40,12 @@ fn require_srp_m2(auth_response: &AuthResponse) -> Result<&str> {.ok_or_else(|| Error::Srp("Missing server proof".to_string()))}-/// Shared account client built on `ente_core::http::Api`.pub struct AccountsClient {api: Api,client_package: String,}impl AccountsClient {- /// Construct a client from a config.pub fn new(config: AccountsClientConfig) -> Result<Self> {let api = Api::new(Http::new()?,@@ -67,17 +63,14 @@ impl AccountsClient {})}- /// Replace the auth token used for authenticated requests.pub fn set_auth_token(&self, auth_token: Option<String>) {self.api.set_auth(auth_token.map(Auth::User));}- /// Return the client package associated with this client.pub fn client_package(&self) -> &str {&self.client_package}- /// Get SRP attributes for a user by email.pub async fn get_srp_attributes(&self, email: &str) -> Result<SrpAttributes> {let query = [("email", email.to_string())];let response: GetSrpAttributesResponse = http::retry(|| async {@@ -95,7 +88,6 @@ impl AccountsClient {Ok(response.attributes)}- /// Run the full SRP login handshake and return the auth response plus KEK.pub async fn login_with_srp(&self,email: &str,@@ -130,7 +122,6 @@ impl AccountsClient {Ok((auth_response, creds.kek))}- /// Create an SRP session.pub async fn create_srp_session(&self,srp_user_id: &uuid::Uuid,@@ -154,7 +145,6 @@ impl AccountsClient {.await?)}- /// Verify an SRP session.pub async fn verify_srp_session(&self,srp_user_id: &uuid::Uuid,@@ -178,7 +168,6 @@ impl AccountsClient {.await?)}- /// Send an OTP/OTT.pub async fn send_otp(&self, email: &str, purpose: &str) -> Result<()> {let request = SendOtpRequest {email: email.to_string(),@@ -197,7 +186,6 @@ impl AccountsClient {.await?)}- /// Verify email ownership with an OTT.pub async fn verify_email(&self,email: &str,@@ -221,7 +209,6 @@ impl AccountsClient {.await?)}- /// Upload user key attributes.pub async fn set_user_key_attributes(&self, key_attributes: KeyAttributes) -> Result<()> {let request = SetUserAttributesRequest { key_attributes };Ok(http::retry(|| async {@@ -237,7 +224,6 @@ impl AccountsClient {.await?)}- /// Upload recovery-key attributes.pub async fn set_recovery_key_attributes(&self, request: SetRecoveryKeyRequest) -> Result<()> {Ok(http::retry(|| async {self.api@@ -252,7 +238,6 @@ impl AccountsClient {.await?)}- /// Start SRP setup for an authenticated user.pub async fn setup_srp(&self, request: &SetupSrpRequest) -> Result<SetupSrpResponse> {Ok(http::retry(|| async {self.api@@ -268,7 +253,6 @@ impl AccountsClient {.await?)}- /// Complete SRP setup.pub async fn complete_srp_setup(&self,setup_id: &uuid::Uuid,@@ -290,7 +274,6 @@ impl AccountsClient {.await?)}- /// Update SRP and key attributes after a password change.pub async fn update_srp_and_key_attributes(&self,request: &UpdateSrpAndKeysRequest,@@ -307,7 +290,6 @@ impl AccountsClient {.await?)}- /// Get session validity and optional remote key attributes.pub async fn get_session_validity(&self) -> Result<SessionValidityResponse> {Ok(http::retry(|| async {self.api@@ -322,7 +304,6 @@ impl AccountsClient {.await?)}- /// Change the authenticated user's email.pub async fn change_email(&self, email: &str, ott: &str) -> Result<()> {let body = serde_json::json!({ "email": email, "ott": ott });self.api@@ -335,7 +316,6 @@ impl AccountsClient {Ok(())}- /// Logout the current authenticated session.pub async fn logout(&self) -> Result<()> {let body = serde_json::json!({});Ok(http::retry(|| async {@@ -351,7 +331,6 @@ impl AccountsClient {.await?)}- /// Return whether two-factor is enabled.pub async fn get_two_factor_status(&self) -> Result<bool> {let response: TwoFactorStatusResponse = http::retry(|| async {self.api@@ -367,7 +346,6 @@ impl AccountsClient {Ok(response.status)}- /// Start TOTP setup.pub async fn setup_two_factor(&self) -> Result<TwoFactorSecret> {let body = serde_json::json!({});Ok(self@@ -382,7 +360,6 @@ impl AccountsClient {.await?)}- /// Enable TOTP two-factor with encrypted recovery material.pub async fn enable_two_factor(&self, request: &EnableTwoFactorRequest) -> Result<()> {self.api.post("/users/two-factor/enable")@@ -394,7 +371,6 @@ impl AccountsClient {Ok(())}- /// Disable TOTP two-factor.pub async fn disable_two_factor(&self) -> Result<()> {let body = serde_json::json!({});Ok(http::retry(|| async {@@ -410,7 +386,6 @@ impl AccountsClient {.await?)}- /// Verify a TOTP code during login.pub async fn verify_totp(&self, session_id: &str, code: &str) -> Result<AuthResponse> {let request = VerifyTotpRequest {session_id: session_id.to_string(),@@ -428,7 +403,6 @@ impl AccountsClient {.await?)}- /// Fetch 2FA recovery information.pub async fn get_two_factor_recovery(&self,session_id: &str,@@ -458,7 +432,6 @@ impl AccountsClient {.await?)}- /// Remove 2FA using the decrypted recovery secret.pub async fn remove_two_factor(&self,request: &RemoveTwoFactorRequest,@@ -475,7 +448,6 @@ impl AccountsClient {.await?)}- /// Get passkey recovery status.pub async fn get_two_factor_recovery_status(&self) -> Result<TwoFactorRecoveryStatusResponse> {Ok(http::retry(|| async {self.api@@ -490,7 +462,6 @@ impl AccountsClient {.await?)}- /// Configure passkey recovery.pub async fn configure_passkey_recovery(&self,request: &ConfigurePasskeyRecoveryRequest,@@ -508,7 +479,6 @@ impl AccountsClient {.await?)}- /// Poll passkey verification completion.pub async fn check_passkey_status(&self, session_id: &str) -> Result<AuthResponse> {let query = [("sessionID", session_id.to_string())];Ok(http::retry(|| async {@@ -525,7 +495,6 @@ impl AccountsClient {.await?)}- /// Fetch accounts-app broker token and URL.pub async fn get_accounts_token(&self) -> Result<AccountsTokenResponse> {Ok(http::retry(|| async {self.apidiff --git a/rust/crates/accounts/src/flow.rs b/rust/crates/accounts/src/flow.rsindex 86eec7339b..810af7075f 100644--- a/rust/crates/accounts/src/flow.rs+++ b/rust/crates/accounts/src/flow.rs@@ -1,8 +1,3 @@-//! Shared account flow orchestration built on [`crate::client::AccountsClient`].-//!-//! This layer is intended for interactive CLI/e2e flows. Callers that need-//! raw server `code/message/status` should prefer [`crate::client::AccountsClient`].-use ente_core::b64;use ente_core::crypto::{self, SecretVec, secretbox};use std::fmt;@@ -27,12 +22,9 @@ use crate::{const SRP_A_LEN: usize = 512;-/// Purpose of an OTP prompt.#[derive(Debug, Clone, Copy, PartialEq, Eq)]pub enum OtpPurpose {- /// OTP for login/email MFA.Login,- /// OTP for signup.Signup,}@@ -45,52 +37,34 @@ impl OtpPurpose {}}-/// Purpose of a TOTP prompt.#[derive(Debug, Clone, Copy, PartialEq, Eq)]pub enum TotpPurpose {- /// TOTP during login.Login,- /// TOTP during initial setup.Setup,}-/// Supported second-factor methods during login.#[derive(Debug, Clone, Copy, PartialEq, Eq)]pub enum SecondFactorMethod {- /// TOTP auth app code.Totp,- /// Passkey verification.Passkey,}-/// UI adapter for interactive account flows.pub trait AuthFlowUi {- /// Read an email OTP from the user.fn read_email_otp(&mut self, email: &str, purpose: OtpPurpose, resent: bool) -> Result<String>;- /// Read a TOTP code from the user.fn read_totp_code(&mut self, purpose: TotpPurpose) -> Result<String>;- /// Display a retryable error and continue.fn report_retryable_error(&mut self, message: &str) -> Result<()>;- /// Let the user choose a second-factor method.fn choose_second_factor(&mut self,methods: &[SecondFactorMethod],) -> Result<SecondFactorMethod>;- /// Show a passkey verification URL.fn present_passkey_verification(&mut self, url: &str) -> Result<()>;- /// Wait until the user has attempted passkey verification.fn wait_for_passkey_verification(&mut self) -> Result<()>;- /// Present a TOTP secret to the user.fn present_totp_secret(&mut self, secret_code: &str, qr_code: &str) -> Result<()>;}-/// Parameters for account creation.pub struct CreateAccountParams {- /// Email address to register.pub email: String,- /// Password used for signup.pub password: Zeroizing<String>,- /// Optional referral source.pub source: Option<String>,}@@ -104,11 +78,8 @@ impl fmt::Debug for CreateAccountParams {}}-/// Parameters for login.pub struct LoginParams {- /// Email address to login.pub email: String,- /// Password for the account.pub password: Zeroizing<String>,}@@ -121,11 +92,8 @@ impl fmt::Debug for LoginParams {}}-/// Parameters for TOTP setup.pub struct SetupTwoFactorParams {- /// Master key for the account.pub master_key: SecretVec,- /// Optional cached key attributes.pub key_attributes: Option<KeyAttributes>,}@@ -138,17 +106,11 @@ impl fmt::Debug for SetupTwoFactorParams {}}-/// Parameters for password changes.pub struct ChangePasswordParams {- /// Email address of the account.pub email: String,- /// New password.pub password: Zeroizing<String>,- /// Current master key bytes.pub master_key: SecretVec,- /// Current key attributes.pub key_attributes: KeyAttributes,- /// Whether to logout other devices.pub log_out_other_devices: bool,}@@ -164,11 +126,8 @@ impl fmt::Debug for ChangePasswordParams {}}-/// Result of a password-change flow.pub struct ChangePasswordResult {- /// Updated key attributes.pub key_attributes: KeyAttributes,- /// Fresh SRP attributes fetched from remote.pub srp_attributes: SrpAttributes,}@@ -181,11 +140,8 @@ impl fmt::Debug for ChangePasswordResult {}}-/// Parameters for session-validity checks.pub struct CheckSessionValidityParams {- /// Email address used to fetch fresh SRP attributes.pub email: String,- /// Locally saved SRP attributes.pub local_srp_attributes: SrpAttributes,}@@ -198,32 +154,21 @@ impl fmt::Debug for CheckSessionValidityParams {}}-/// Outcome of a session-validity check.#[derive(Debug)]#[expect(clippy::large_enum_variant)]pub enum SessionValidity {- /// Token is invalid.Invalid,- /// Session is valid and password unchanged.Valid,- /// Session is valid but password was changed elsewhere.ValidButPasswordChanged {- /// Fresh key attributes from remote.updated_key_attributes: KeyAttributes,- /// Fresh SRP attributes from remote.updated_srp_attributes: SrpAttributes,},}-/// Authenticated account returned by shared flows.pub struct AuthenticatedAccount {- /// User ID.pub user_id: i64,- /// Full key attributes.pub key_attributes: KeyAttributes,- /// Decrypted account secrets.pub secrets: AccountSecrets,- /// Recovery key, if derivable.pub recovery_key: Option<String>,}@@ -238,13 +183,9 @@ impl fmt::Debug for AuthenticatedAccount {}}-/// Result of setting up TOTP.pub struct SetupTwoFactorResult {- /// Secret code shown to the user.pub secret_code: String,- /// QR code payload.pub qr_code: String,- /// Recovery key used to encrypt the TOTP secret.pub recovery_key: String,}@@ -258,11 +199,8 @@ impl fmt::Debug for SetupTwoFactorResult {}}-/// Result of creating a new recovery key for old accounts.pub struct RecoveryKeyResult {- /// Fresh recovery key in hex.pub recovery_key: String,- /// Updated key attributes including recovery-key fields.pub key_attributes: KeyAttributes,}@@ -275,7 +213,6 @@ impl fmt::Debug for RecoveryKeyResult {}}-/// Shared high-level account flow orchestration.pub struct AuthFlow<'a, U> {client: &'a AccountsClient,ui: &'a mut U,@@ -285,12 +222,10 @@ impl<'a, U> AuthFlow<'a, U>whereU: AuthFlowUi,{- /// Create a new shared account flow instance.pub fn new(client: &'a AccountsClient, ui: &'a mut U) -> Self {Self { client, ui }}- /// Create a new account.pub async fn create_account(&mut self,params: CreateAccountParams,@@ -299,7 +234,6 @@ where.await}- /// Create a new account after the caller has already sent and collected a signup OTP.pub async fn create_account_with_otp(&mut self,params: CreateAccountParams,@@ -321,7 +255,6 @@ where.await}- /// Login to an existing account.pub async fn login(&mut self, params: LoginParams) -> Result<AuthenticatedAccount> {let srp_attrs = self.client.get_srp_attributes(¶ms.email).await?;@@ -352,7 +285,6 @@ whereself.build_authenticated_account(auth_response, &kek)}- /// Setup TOTP two-factor authentication.pub async fn setup_two_factor(&mut self,params: SetupTwoFactorParams,@@ -394,7 +326,6 @@ where}}- /// Change the account password and update SRP/key attributes on remote.pub async fn change_password(&self,params: ChangePasswordParams,@@ -460,7 +391,6 @@ where})}- /// Check if the current session is still valid and whether password changed elsewhere.pub async fn check_session_validity(&self,params: CheckSessionValidityParams,@@ -484,12 +414,10 @@ whereOk(SessionValidity::Valid)}- /// Change the authenticated user's email address.pub async fn change_email(&self, email: &str, ott: &str) -> Result<()> {self.client.change_email(email, ott).await}- /// Create a new recovery key for old accounts that do not have one yet.pub async fn create_recovery_key(&self,master_key: &[u8],@@ -525,7 +453,6 @@ where})}- /// Get the server-side two-factor recovery payload for a pending second-factor session.pub async fn get_two_factor_recovery(&self,session_id: &str,@@ -536,7 +463,6 @@ where.await}- /// Remove/bypass the second factor using a recovery key input.pub async fn recover_two_factor(&self,two_factor_type: TwoFactorType,@@ -562,17 +488,14 @@ whereself.client.remove_two_factor(&request).await}- /// Return whether the authenticated user has TOTP enabled.pub async fn get_two_factor_status(&self) -> Result<bool> {self.client.get_two_factor_status().await}- /// Disable TOTP for the authenticated user.pub async fn disable_two_factor(&self) -> Result<()> {self.client.disable_two_factor().await}- /// Get passkey recovery status.pub async fn get_passkey_recovery_status(&self) -> Result<bool> {Ok(self.client@@ -581,7 +504,6 @@ where.is_passkey_recovery_enabled)}- /// Configure passkey recovery by encrypting a reset secret with the user's recovery key.pub async fn configure_passkey_recovery(&self,secret: &str,@@ -600,12 +522,10 @@ whereself.client.configure_passkey_recovery(&request).await}- /// Get the accounts-token response used to open the accounts broker.pub async fn get_accounts_token(&self) -> Result<crate::models::AccountsTokenResponse> {self.client.get_accounts_token().await}- /// Poll passkey verification status.pub async fn check_passkey_status(&self, session_id: &str) -> Result<AuthResponse> {self.client.check_passkey_status(session_id).await}@@ -903,7 +823,6 @@ where}}-/// Build the passkey verification URL for an accounts broker.pub fn build_passkey_verification_url(accounts_url: &str,passkey_session_id: &str,diff --git a/rust/crates/accounts/src/lib.rs b/rust/crates/accounts/src/lib.rsindex 3d6614d412..d6c0fa9a00 100644--- a/rust/crates/accounts/src/lib.rs+++ b/rust/crates/accounts/src/lib.rs@@ -1,14 +1,3 @@-//! Shared Rust account identity, transport, and flow orchestration for Ente-//! clients.-//!-//! Preferred usage:-//! - Use [`auth`] for the account key hierarchy: key generation, secret-//! decryption, recovery keys, and the SRP login protocol.-//! - Use [`AccountsClient`] when a caller needs raw server failures, including-//! the HTTP status and API error code.-//! - Use [`AuthFlow`] for CLI/e2e-style interactive orchestration where the-//! library drives OTP/TOTP/passkey steps via a UI adapter.-pub mod auth;pub mod client;pub mod error;diff --git a/rust/crates/accounts/src/models.rs b/rust/crates/accounts/src/models.rsindex bdd407cafa..3ed777d4ed 100644--- a/rust/crates/accounts/src/models.rs+++ b/rust/crates/accounts/src/models.rs@@ -1,5 +1,3 @@-//! Shared request and response models for account APIs.-use std::fmt;use serde::{Deserialize, Serialize};@@ -7,39 +5,27 @@ use uuid::Uuid;pub use crate::auth::{KeyAttributes, SrpAttributes};-/// Outer wrapper for SRP attributes.#[derive(Debug, Deserialize, Serialize)]#[serde(rename_all = "camelCase")]pub struct GetSrpAttributesResponse {- /// Nested attributes payload.pub attributes: SrpAttributes,}-/// Auth response emitted by login and verification endpoints.#[derive(Deserialize, Serialize, Clone)]#[serde(try_from = "AuthResponseWire")]#[serde(rename_all = "camelCase")]pub struct AuthResponse {- /// User ID.pub id: i64,- /// Optional key attributes.pub key_attributes: Option<KeyAttributes>,- /// Optional encrypted auth token.pub encrypted_token: Option<String>,- /// Optional plain auth token.pub token: Option<String>,- /// V1 two-factor session ID.#[serde(rename = "twoFactorSessionID")]pub two_factor_session_id: Option<String>,- /// V2 two-factor session ID.#[serde(rename = "twoFactorSessionIDV2")]pub two_factor_session_id_v2: Option<String>,- /// Passkey verification session ID.#[serde(rename = "passkeySessionID")]pub passkey_session_id: Option<String>,- /// Optional SRP M2 server proof.pub srp_m2: Option<String>,- /// Optional accounts broker URL.pub accounts_url: Option<String>,}@@ -119,7 +105,6 @@ impl fmt::Debug for AuthResponse {}impl AuthResponse {- /// Return either v1 or v2 two-factor session ID, if present.pub fn get_two_factor_session_id(&self) -> Option<&String> {self.two_factor_session_id.as_ref()@@ -131,12 +116,10 @@ impl AuthResponse {})}- /// Whether the response requires second-factor verification.pub fn is_mfa_required(&self) -> bool {self.get_two_factor_session_id().is_some()}- /// Whether the response requires passkey verification.pub fn is_passkey_required(&self) -> bool {self.passkey_session_id.as_ref()@@ -144,23 +127,16 @@ impl AuthResponse {}}-/// Request body for sending OTP/OTT.#[derive(Debug, Serialize)]pub struct SendOtpRequest {- /// Email address.pub email: String,- /// OTP purpose.pub purpose: String,}-/// Request body for email verification.#[derive(Serialize)]pub struct VerifyEmailRequest {- /// Email address.pub email: String,- /// One-time token.pub ott: String,- /// Optional signup referral source.#[serde(skip_serializing_if = "Option::is_none")]pub source: Option<String>,}@@ -175,127 +151,90 @@ impl fmt::Debug for VerifyEmailRequest {}}-/// Request for SRP session creation.#[derive(Debug, Serialize)]pub struct CreateSrpSessionRequest {- /// SRP user ID.#[serde(rename = "srpUserID")]pub srp_user_id: String,- /// Client A public value.#[serde(rename = "srpA")]pub srp_a: String,}-/// Response for SRP session creation.#[derive(Debug, Deserialize, Serialize)]pub struct CreateSrpSessionResponse {- /// Session ID.#[serde(rename = "sessionID")]pub session_id: Uuid,- /// Base64 SRP B value.#[serde(rename = "srpB")]pub srp_b: String,}-/// Request for SRP session verification.#[derive(Debug, Serialize)]pub struct VerifySrpSessionRequest {- /// SRP user ID.#[serde(rename = "srpUserID")]pub srp_user_id: String,- /// Session ID.#[serde(rename = "sessionID")]pub session_id: String,- /// Client M1 proof.#[serde(rename = "srpM1")]pub srp_m1: String,}-/// Request for uploading key attributes.#[derive(Debug, Serialize)]#[serde(rename_all = "camelCase")]pub struct SetUserAttributesRequest {- /// Full user key attributes.pub key_attributes: KeyAttributes,}-/// Request for uploading recovery-key attributes.#[derive(Debug, Serialize)]#[serde(rename_all = "camelCase")]pub struct SetRecoveryKeyRequest {- /// Encrypted master key with recovery key.pub master_key_encrypted_with_recovery_key: String,- /// Nonce for encrypted master key.pub master_key_decryption_nonce: String,- /// Encrypted recovery key with master key.pub recovery_key_encrypted_with_master_key: String,- /// Nonce for encrypted recovery key.pub recovery_key_decryption_nonce: String,}-/// Request for initial SRP setup.#[derive(Debug, Serialize)]pub struct SetupSrpRequest {- /// SRP user ID.#[serde(rename = "srpUserID")]pub srp_user_id: String,- /// Base64 SRP salt.#[serde(rename = "srpSalt")]pub srp_salt: String,- /// Base64 SRP verifier.#[serde(rename = "srpVerifier")]pub srp_verifier: String,- /// Base64 padded A public value.#[serde(rename = "srpA")]pub srp_a: String,}-/// Response for initial SRP setup.#[derive(Debug, Deserialize, Serialize)]pub struct SetupSrpResponse {- /// Setup ID.#[serde(rename = "setupID")]pub setup_id: Uuid,- /// Base64 SRP B.#[serde(rename = "srpB")]pub srp_b: String,}-/// Request for completing SRP setup.#[derive(Debug, Serialize)]pub struct CompleteSrpSetupRequest {- /// Setup ID.#[serde(rename = "setupID")]pub setup_id: String,- /// Base64 M1.#[serde(rename = "srpM1")]pub srp_m1: String,}-/// Response for completing SRP setup.#[derive(Debug, Deserialize, Serialize)]pub struct CompleteSrpSetupResponse {- /// Setup ID.#[serde(rename = "setupID")]pub setup_id: Uuid,- /// Base64 M2.#[serde(rename = "srpM2")]pub srp_m2: String,}-/// Mutable subset of key attributes used during password changes.#[derive(Debug, Serialize, Deserialize, Clone)]#[serde(rename_all = "camelCase")]pub struct UpdatedKeyAttr {- /// Base64 KEK salt.pub kek_salt: String,- /// Base64 encrypted master key.pub encrypted_key: String,- /// Base64 nonce.pub key_decryption_nonce: String,- /// Argon ops limit.pub ops_limit: u32,- /// Argon memory limit.pub mem_limit: u32,}@@ -311,48 +250,34 @@ impl From<&KeyAttributes> for UpdatedKeyAttr {}}-/// Request for updating SRP and key attributes.#[derive(Debug, Serialize)]#[serde(rename_all = "camelCase")]pub struct UpdateSrpAndKeysRequest {- /// Setup ID.pub setup_id: String,- /// Base64 client proof.pub srp_m1: String,- /// Updated key-attribute subset.pub updated_key_attr: UpdatedKeyAttr,- /// Whether other devices should be logged out.pub log_out_other_devices: bool,}-/// Response for SRP/key update.#[derive(Debug, Deserialize, Serialize)]pub struct UpdateSrpAndKeysResponse {- /// Base64 server proof.#[serde(rename = "srpM2")]pub srp_m2: String,- /// Setup ID.#[serde(rename = "setupID")]pub setup_id: Uuid,}-/// Session validity response.#[derive(Debug, Deserialize, Serialize)]#[serde(rename_all = "camelCase")]pub struct SessionValidityResponse {- /// Whether server-side key attributes exist.pub has_set_keys: bool,- /// Optional server-side key attributes.pub key_attributes: Option<KeyAttributes>,}-/// Two-factor setup secret response.#[derive(Deserialize, Serialize, Clone)]#[serde(rename_all = "camelCase")]pub struct TwoFactorSecret {- /// TOTP secret code.pub secret_code: String,- /// QR code image payload.pub qr_code: String,}@@ -365,15 +290,11 @@ impl fmt::Debug for TwoFactorSecret {}}-/// Request for TOTP enablement.#[derive(Serialize, Clone)]#[serde(rename_all = "camelCase")]pub struct EnableTwoFactorRequest {- /// Current TOTP code.pub code: String,- /// Encrypted TOTP secret.pub encrypted_two_factor_secret: String,- /// Nonce for encrypted TOTP secret.pub two_factor_secret_decryption_nonce: String,}@@ -387,13 +308,10 @@ impl fmt::Debug for EnableTwoFactorRequest {}}-/// Request for TOTP verification.#[derive(Serialize)]#[serde(rename_all = "camelCase")]pub struct VerifyTotpRequest {- /// Session ID.pub session_id: String,- /// TOTP code.pub code: String,}@@ -406,84 +324,59 @@ impl fmt::Debug for VerifyTotpRequest {}}-/// Response for `/users/two-factor/status`.#[derive(Debug, Deserialize, Serialize)]pub struct TwoFactorStatusResponse {- /// Whether two-factor is enabled.pub status: bool,}-/// Supported second-factor kinds.#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]#[serde(rename_all = "lowercase")]pub enum TwoFactorType {- /// TOTP second factor.Totp,- /// Passkey second factor.Passkey,}-/// Response for `/users/two-factor/recover`.#[derive(Debug, Deserialize, Serialize, Clone)]#[serde(rename_all = "camelCase")]pub struct TwoFactorRecoveryResponse {- /// Secret encrypted with the user's recovery key.pub encrypted_secret: String,- /// Nonce for the encrypted secret.pub secret_decryption_nonce: String,}-/// Request for `/users/two-factor/remove`.#[derive(Debug, Serialize)]#[serde(rename_all = "camelCase")]pub struct RemoveTwoFactorRequest {- /// Session ID.pub session_id: String,- /// Plain recovery secret.pub secret: String,- /// Factor type to remove.pub two_factor_type: TwoFactorType,}-/// Response after 2FA verification/removal/passkey completion.#[derive(Debug, Deserialize, Serialize, Clone)]#[serde(rename_all = "camelCase")]pub struct TwoFactorAuthorizationResponse {- /// User ID.pub id: i64,- /// Key attributes.pub key_attributes: KeyAttributes,- /// Encrypted auth token.pub encrypted_token: String,}-/// Response for passkey recovery status.#[derive(Debug, Deserialize, Serialize)]pub struct TwoFactorRecoveryStatusResponse {- /// Whether passkey recovery has been configured.#[serde(rename = "isPasskeyRecoveryEnabled")]pub is_passkey_recovery_enabled: bool,}-/// Request body for passkey recovery configuration.#[derive(Debug, Serialize)]#[serde(rename_all = "camelCase")]pub struct ConfigurePasskeyRecoveryRequest {- /// Plain server recovery secret.pub secret: String,- /// Encrypted user secret.pub user_secret_cipher: String,- /// Nonce for the encrypted user secret.pub user_secret_nonce: String,}-/// Response for `/users/accounts-token`.#[derive(Debug, Deserialize, Serialize)]#[serde(rename_all = "camelCase")]pub struct AccountsTokenResponse {- /// Accounts broker URL.pub accounts_url: String,- /// JWT for the accounts app.pub accounts_token: String,}diff --git a/rust/crates/accounts/src/types.rs b/rust/crates/accounts/src/types.rsindex e3e5bfe49b..f58b6e89ca 100644--- a/rust/crates/accounts/src/types.rs+++ b/rust/crates/accounts/src/types.rs@@ -1,24 +1,15 @@-//! Shared reusable types for account clients.-use ente_core::urls::PRODUCTION_API_ORIGIN;use serde::{Deserialize, Serialize};use zeroize::Zeroize;-/// Default origin for Ente's public API.pub const DEFAULT_API_ORIGIN: &str = PRODUCTION_API_ORIGIN;-/// Configuration for constructing an [`crate::client::AccountsClient`].#[derive(Clone)]pub struct AccountsClientConfig {- /// Ente API origin.pub origin: String,- /// Optional auth token for authenticated requests.pub auth_token: Option<String>,- /// Concrete client package header value.pub client_package: String,- /// Optional client version header.pub client_version: Option<String>,- /// Optional user agent.pub user_agent: Option<String>,}@@ -38,7 +29,6 @@ impl std::fmt::Debug for AccountsClientConfig {}impl AccountsClientConfig {- /// Create a config for the given client package.pub fn new(client_package: impl Into<String>) -> Self {Self {origin: DEFAULT_API_ORIGIN.to_string(),@@ -49,42 +39,33 @@ impl AccountsClientConfig {}}- /// Override the API origin.pub fn with_origin(mut self, origin: impl Into<String>) -> Self {self.origin = origin.into();self}- /// Attach an auth token.pub fn with_auth_token(mut self, auth_token: impl Into<String>) -> Self {self.auth_token = Some(auth_token.into());self}- /// Set a client version header.pub fn with_client_version(mut self, client_version: impl Into<String>) -> Self {self.client_version = Some(client_version.into());self}- /// Set a user agent.pub fn with_user_agent(mut self, user_agent: impl Into<String>) -> Self {self.user_agent = Some(user_agent.into());self}}-/// Decrypted account secrets.#[derive(Serialize, Deserialize, Zeroize)]#[zeroize(drop)]pub struct AccountSecrets {- /// Plain auth token bytes.pub token: Vec<u8>,- /// Master key bytes.pub master_key: Vec<u8>,- /// X25519 secret key bytes.pub secret_key: Vec<u8>,- /// X25519 public key bytes.pub public_key: Vec<u8>,}diff --git a/rust/crates/contacts/src/legacy_kit_models.rs b/rust/crates/contacts/src/legacy_kit_models.rsindex 7f7fc69688..c9c22054ea 100644--- a/rust/crates/contacts/src/legacy_kit_models.rs+++ b/rust/crates/contacts/src/legacy_kit_models.rs@@ -74,8 +74,7 @@ pub struct LegacyKitRecoverySession {#[serde(rename = "kitID")]pub kit_id: String,pub status: LegacyKitRecoveryStatus,- /// Remaining microseconds until recovery is ready, matching the existing- /// emergency legacy recovery API response contract.+ // Remaining microseconds, as required by the legacy recovery API.pub wait_till: i64,pub created_at: i64,}diff --git a/rust/crates/ensu/Cargo.toml b/rust/crates/ensu/Cargo.tomlindex 7d2fcb8e30..431ebb51d1 100644--- a/rust/crates/ensu/Cargo.toml+++ b/rust/crates/ensu/Cargo.toml@@ -24,32 +24,18 @@ zstd = "0.13.3"[dev-dependencies]tempfile = "3.27.0"-# llama-cpp-2's default features are "openmp" and "android-shared-stdcxx".-#-# - "openmp" enables OpenMP CPU parallelism. It requires libomp, which usually-# ships with Linux/Windows toolchains but not Apple's clang. Without it,-# llama.cpp falls back to its built-in thread pool.-#-# - "android-shared-stdcxx" is a no-op everywhere except Android (where it-# enables the NDK's shared C++ runtime).-#-# On Apple platforms, Accelerate is auto-linked by llama-cpp-sys-2 for CPU-# SIMD helpers. llama-cpp-2 additionally enables the "metal" feature on arm64,-# which causes Metal to be used for GPU inference.-#-# "mtmd" is used on all platforms for enabling multimodal support.+# Keep `mtmd` on every platform for multimodal support.+# macOS disables OpenMP because Apple's clang lacks libomp. llama.cpp uses its+# own thread pool, Accelerate, and Metal on arm64 instead.[target.'cfg(target_os = "macos")'.dependencies]llama-cpp-2 = { version = "=0.1.144", default-features = false, features = ["mtmd"] }-# Desktop Linux enables the Vulkan GPU backend, which runs on AMD, Intel and-# NVIDIA GPUs through the system Vulkan loader (no vendor SDK required). The-# build needs a Vulkan loader plus "glslc" to compile the compute shaders.+# Linux Vulkan needs a system Vulkan loader and glslc.[target.'cfg(target_os = "linux")'.dependencies]llama-cpp-2 = { version = "=0.1.144", features = ["mtmd", "vulkan"] }-# Android (and anything else that is neither macOS nor desktop Linux) stays on-# the CPU backend. Windows Vulkan additionally requires a VULKAN_SDK, so it is-# intentionally left out here.+# Other platforms stay on CPU. Android keeps the shared C++ runtime; Windows+# avoids Vulkan's VULKAN_SDK requirement.[target.'cfg(all(not(target_os = "macos"), not(target_os = "linux")))'.dependencies]llama-cpp-2 = { version = "=0.1.144", features = ["mtmd"] }diff --git a/rust/crates/ensu/src/llm/generate.rs b/rust/crates/ensu/src/llm/generate.rsindex 1c07406232..af06cb71ec 100644--- a/rust/crates/ensu/src/llm/generate.rs+++ b/rust/crates/ensu/src/llm/generate.rs@@ -240,7 +240,6 @@ struct DecodeStep {stop: bool,}-/// Incremental UTF-8 streaming decoder with stop-sequence handling.struct StreamDecoder {generated_text: String,pending_bytes: Vec<u8>,diff --git a/rust/crates/ensu/src/retrieval/index.rs b/rust/crates/ensu/src/retrieval/index.rsindex aedcabff1a..c979515050 100644--- a/rust/crates/ensu/src/retrieval/index.rs+++ b/rust/crates/ensu/src/retrieval/index.rs@@ -159,8 +159,7 @@ impl RetrievalIndex {.collect::<Vec<_>>();validate_offsets(&offsets, metadata_len)?;- // Knowledge-pack revisions are immutable while an index is open. Native callers- // synchronize swaps/deletion around this object, satisfying mmap's safety contract.+ // Native callers prevent pack swaps and deletion while these files are mapped.let vectors = unsafe { MmapOptions::new().map(&vector_file)? };let metadata = unsafe { MmapOptions::new().map(&metadata_file)? };diff --git a/rust/crates/image/src/color_management.rs b/rust/crates/image/src/color_management.rsindex 3a41df4f53..25f52ce58a 100644--- a/rust/crates/image/src/color_management.rs+++ b/rust/crates/image/src/color_management.rs@@ -311,7 +311,7 @@ fn transform_u8_out_of_place(Ok(transformed)}-/// Mirrors moxcms's crate-private `ColorProfile::has_device_to_pcs_lut`.+// Mirrors moxcms's crate-private `ColorProfile::has_device_to_pcs_lut`.fn profile_has_device_to_pcs_lut(profile: &ColorProfile) -> bool {profile.lut_a_to_b_perceptual.is_some()|| profile.lut_a_to_b_colorimetric.is_some()diff --git a/rust/crates/image/src/decode.rs b/rust/crates/image/src/decode.rsindex 04a4c44112..21b1adc75d 100644--- a/rust/crates/image/src/decode.rs+++ b/rust/crates/image/src/decode.rs@@ -440,7 +440,7 @@ fn read_exif_orientation_from_bytes(image_bytes: &[u8]) -> Option<u8> {.filter(|value| (1..=8).contains(value))}-/// jxl-oxide applies codestream orientation; ignore redundant container EXIF.+// jxl-oxide applies codestream orientation; ignore redundant container EXIF.fn bytes_look_like_jxl(image_bytes: &[u8]) -> bool {const BARE_CODESTREAM_SIGNATURE: [u8; 2] = [0xFF, 0x0A];const CONTAINER_SIGNATURE: [u8; 12] = [diff --git a/rust/crates/image/src/types.rs b/rust/crates/image/src/types.rsindex cef4bb7e29..9ea07bac27 100644--- a/rust/crates/image/src/types.rs+++ b/rust/crates/image/src/types.rs@@ -4,11 +4,11 @@ pub struct Dimensions {pub height: u32,}-/// 8-bit sRGB with EXIF orientation applied. ICC conversion is best-effort;-/// absent, unusable, or PQ/HLG profiles leave decoded values unchanged.+// 8-bit sRGB with EXIF orientation applied. ICC conversion is best-effort;+// absent, unusable, or PQ/HLG profiles leave decoded values unchanged.#[derive(Clone, Debug)]pub struct DecodedImage {pub dimensions: Dimensions,- /// Tightly packed row-major RGB triples (`3 * width * height` bytes).+ // Tightly packed row-major RGB triples (`3 * width * height` bytes).pub rgb: Vec<u8>,}diff --git a/rust/crates/photos/Cargo.toml b/rust/crates/photos/Cargo.tomlindex 9c14f14f4d..9c71c4a0a5 100644--- a/rust/crates/photos/Cargo.toml+++ b/rust/crates/photos/Cargo.toml@@ -24,10 +24,7 @@ thiserror.workspace = true# Newer usearch releases switched that implementation to numkong symbols.usearch = { version = "=2.21.4", optional = true }-# ORT source and version are pinned once in the workspace manifest; only the-# per-target feature sets are declared here.-# The iOS Cargokit build sets ORT_LIB_PATH to the directory containing the-# verified custom static archive.+# Cargokit sets ORT_LIB_PATH to Ente's verified iOS archive.[target.'cfg(target_os = "ios")'.dependencies]ort = { workspace = true, features = ["std",diff --git a/rust/crates/photos/examples/ml_goldens.rs b/rust/crates/photos/examples/ml_goldens.rsindex d2e372eb47..34aa5c6e67 100644--- a/rust/crates/photos/examples/ml_goldens.rs+++ b/rust/crates/photos/examples/ml_goldens.rs@@ -1,8 +1,3 @@-//! Developer tooling for the committed ML self-test data.-//!-//! cargo run -p ente-photos --example ml_goldens -- generate-//! cargo run -p ente-photos --example ml_goldens -- validate-zero-separation-#[allow(dead_code)]#[path = "../tests/support/mod.rs"]mod support;diff --git a/rust/crates/photos/src/ml/error.rs b/rust/crates/photos/src/ml/error.rsindex 21c701eca8..e0fc09775c 100644--- a/rust/crates/photos/src/ml/error.rs+++ b/rust/crates/photos/src/ml/error.rs@@ -8,7 +8,7 @@ pub enum MlError {InvalidRequest(String),#[error("decode error: {0}")]Decode(String),- /// A deterministic per-image failure that should not be retried.+ // A deterministic per-image failure that should not be retried.#[error("image processing error: {0}")]Image(String),#[error("preprocess error: {0}")]diff --git a/rust/crates/photos/src/ml/events.rs b/rust/crates/photos/src/ml/events.rsindex d41c523ce7..7ebdabc866 100644--- a/rust/crates/photos/src/ml/events.rs+++ b/rust/crates/photos/src/ml/events.rs@@ -1,9 +1,7 @@-//! Reports graceful ML fallbacks and quarantines that would otherwise be-//! invisible to the app because the calling operation still succeeds.+// Report ML fallbacks and quarantines even when the calling operation succeeds.use std::sync::Mutex;-/// Prefer recent, actionable events when the app has not drained the buffer.const MAX_BUFFERED_EVENTS: usize = 64;#[derive(Clone, Debug, PartialEq, Eq)]@@ -59,8 +57,8 @@ pub fn take_events() -> Vec<MlRuntimeEvent> {mod tests {use super::{MAX_BUFFERED_EVENTS, Severity, record, take_events};- /// A single test because the buffer is a process-global shared with any- /// concurrently running test that records events.+ // Keep this in one test because the process-global buffer is shared across+ // tests.#[test]fn records_in_order_drains_on_take_and_drops_oldest_when_full() {take_events();diff --git a/rust/crates/photos/src/ml/golden.rs b/rust/crates/photos/src/ml/golden.rsindex 5a7272b44d..8801ccb69e 100644--- a/rust/crates/photos/src/ml/golden.rs+++ b/rust/crates/photos/src/ml/golden.rs@@ -1,7 +1,7 @@-//! Accelerated ONNX providers must reproduce CPU-generated golden outputs-//! because drivers can return plausible but numerically corrupt results while-//! reporting success. Deterministic inputs exercise the same kernels as real-//! inputs because these models have no data-dependent control flow.+// Accelerated ONNX providers must reproduce CPU-generated golden outputs+// because drivers can return plausible but numerically corrupt results while+// reporting success. Deterministic inputs exercise the same kernels as real+// inputs because these models have no data-dependent control flow.use crate::ml::golden_data::GOLDEN_ENTRIES;@@ -21,23 +21,17 @@ pub(crate) const CONFIDENCE_RELATIVE_L2_THRESHOLD: f64 = 2.0;const MAX_REFERENCE_SAMPLES: usize = 4096;pub enum GoldenInput {- SeededF32 {- seed: u64,- },- /// Pre-tokenized CLIP text token ids.- I32 {- data: &'static [i32],- },+ SeededF32 { seed: u64 },+ I32 { data: &'static [i32] },}#[derive(Clone, Copy, Debug, PartialEq, Eq)]pub enum GoldenMetric {- /// For embedding outputs, which downstream code consumes via cosine- /// similarity; scale differences are irrelevant there.+ // Embeddings are consumed through cosine similarity, so scale is+ // irrelevant.CosineDistance,- /// For detector rows whose confidence values are much smaller than their- /// coordinates. Confidence and all remaining values are compared- /// separately so coordinate magnitudes cannot hide score corruption.+ // Compare confidence separately so larger coordinates cannot hide score+ // corruption.DetectorRelativeL2 {row_len: usize,confidence_offset: usize,@@ -61,9 +55,10 @@ impl GoldenMetric {}pub struct GoldenEntry {- /// A changed canonical name fails closed instead of reusing a stale golden.+ // A changed canonical name must fail closed instead of reusing a stale+ // golden.pub model_file: &'static str,- /// Checked against the asset lock in CI, not on device.+ // Checked against the asset lock in CI, not on device.pub model_sha256: &'static str,pub input: GoldenInput,pub input_shape: &'static [i64],@@ -79,9 +74,8 @@ pub fn lookup(model_path: &str) -> Option<&'static GoldenEntry> {.find(|entry| matches_model_file(file_name, entry.model_file))}-/// Downloaded model names include a sanitized URL prefix, so canonical names-/// match at an underscore boundary as well as exactly. This mirrors-/// `RemoteAssetsService._urlToFileName` in the photos app.+// Downloaded names include a sanitized URL prefix. Match canonical names at an+// underscore boundary, as `RemoteAssetsService._urlToFileName` does.fn matches_model_file(file_name: &str, model_file: &str) -> bool {if file_name == model_file {return true;@@ -142,9 +136,8 @@ pub fn prepare_input(entry: &GoldenEntry) -> Result<PreparedGoldenInput, String>}}-/// Deterministic uniform [0, 1) noise shared by the on-device self-test and-/// the golden generator. xorshift64*; must never change without regenerating-/// `golden_data.rs`.+// Shared by the device self-test and generator. Regenerate `golden_data.rs` if+// this sequence changes.pub fn seeded_noise(seed: u64, len: usize) -> Vec<f32> {let mut state = seed.max(1);(0..len)@@ -205,9 +198,8 @@ pub fn output_distance(entry: &GoldenEntry, output: &[f32]) -> Result<f64, Strin})}-/// Validates the properties required of the zero-input warm-up output. The-/// warm-up has no numeric golden, but it must still produce a complete finite-/// tensor before the session can proceed to the golden comparison.+// The zero-input warm-up has no numeric golden, but must return a complete+// finite tensor before the golden run.pub fn validate_output(entry: &GoldenEntry, output: &[f32]) -> Result<(), String> {if output.len() != entry.output_len {return Err(format!(diff --git a/rust/crates/photos/src/ml/golden_data.rs b/rust/crates/photos/src/ml/golden_data.rsindex 4f85f1501f..245e5f13a7 100644--- a/rust/crates/photos/src/ml/golden_data.rs+++ b/rust/crates/photos/src/ml/golden_data.rs@@ -1,11 +1,10 @@-//! GENERATED FILE β do not edit by hand.-//!-//! Regenerate with:-//! cargo run -p ente-photos --example ml_goldens -- generate-//!-//! TODO: the pet models are CPU-only and therefore have no golden entries-//! yet; they must get entries here before they are moved off CPU-only-//! execution (see `MlRuntime::new` in runtime.rs).+// Generated file. Do not edit by hand.+//+// Regenerate with:+// cargo run -p ente-photos --example ml_goldens -- generate+//+// TODO: Pet models have no golden entries because they are CPU-only. Add+// entries before moving them off CPU (see `MlRuntime::new` in runtime.rs).use crate::ml::golden::{GoldenEntry, GoldenInput, GoldenMetric};diff --git a/rust/crates/photos/src/ml/golden_tooling.rs b/rust/crates/photos/src/ml/golden_tooling.rsindex 45b33771ae..1e0adc95d1 100644--- a/rust/crates/photos/src/ml/golden_tooling.rs+++ b/rust/crates/photos/src/ml/golden_tooling.rs@@ -7,18 +7,16 @@ use crate::ml::{clip, golden, golden_data::GOLDEN_ENTRIES, onnx};pub use crate::ml::golden::GoldenMetric;-/// Each generated entry stores this seed, so devices do not depend on it.const GOLDEN_NOISE_SEED: u64 = 0x0060_1DE2_5EED_2026;const GENERATED_FILE_HEADER: &str = "\-//! GENERATED FILE β do not edit by hand.-//!-//! Regenerate with:-//! cargo run -p ente-photos --example ml_goldens -- generate-//!-//! TODO: the pet models are CPU-only and therefore have no golden entries-//! yet; they must get entries here before they are moved off CPU-only-//! execution (see `MlRuntime::new` in runtime.rs).+// Generated file. Do not edit by hand.+//+// Regenerate with:+// cargo run -p ente-photos --example ml_goldens -- generate+//+// TODO: Pet models have no golden entries because they are CPU-only. Add+// entries before moving them off CPU (see `MlRuntime::new` in runtime.rs).use crate::ml::golden::{GoldenEntry, GoldenInput, GoldenMetric};@@ -89,7 +87,7 @@ pub struct PinnedModel {pub sha256: String,}-/// Metadata-only CI guard; it does not detect numeric CPU-provider drift.+// This checks metadata only, not numeric CPU-provider drift.pub fn verify_goldens_against_pins(pins: &[PinnedModel]) -> Vec<String> {let mut failures = Vec::new();@@ -205,8 +203,8 @@ fn build_cpu_session(model_path: &str) -> Result<ort::session::Session, String>.map_err(|error| format!("building CPU session for '{model_path}': {error}"))}-/// The first input's static shape. Golden inputs require fully static shapes-/// so that device and generator tensors are identical.+// Golden inputs require a fully static shape so device and generator tensors+// match.fn static_input_shape(session: &mut ort::session::Session,file_name: &str,diff --git a/rust/crates/photos/src/ml/indexing.rs b/rust/crates/photos/src/ml/indexing.rsindex be5a34de84..3b916ec866 100644--- a/rust/crates/photos/src/ml/indexing.rs+++ b/rust/crates/photos/src/ml/indexing.rs@@ -43,8 +43,6 @@ pub struct AnalyzeImageResult {pub clip: Option<ClipResult>,pub pet_faces: Option<Vec<PetFaceResult>>,pub pet_bodies: Option<Vec<PetBodyResult>>,- /// True when any model that contributed to this result ran on the- /// respective accelerated execution provider.pub used_coreml: bool,pub used_webgpu: bool,}@@ -61,8 +59,7 @@ pub struct RunClipTextResult {pub embedding: Vec<f32>,}-/// Configures process-wide ML execution behavior. Must be called before the-/// first session is created to take effect for that session.+// Call before creating sessions; existing sessions keep their configuration.pub fn set_ml_execution_config(enable_webgpu: bool) {webgpu::set_enabled(enable_webgpu);}diff --git a/rust/crates/photos/src/ml/onnx.rs b/rust/crates/photos/src/ml/onnx.rsindex bd0e1a7c66..3f0d071557 100644--- a/rust/crates/photos/src/ml/onnx.rs+++ b/rust/crates/photos/src/ml/onnx.rs@@ -42,18 +42,16 @@ use crate::ml::webgpu;#[cfg(any(target_os = "ios", target_os = "macos", test))]const COREML_CACHE_SCHEMA: &str = "ort-1_28-mlprogram-all-default-v1";const COREML_CACHE_COMPLETE_MARKER: &str = ".ente-cache-complete";-/// The name ONNX Runtime's CoreML EP gives the compiled model it stores-/// inside each generated MLProgram package directory in the cache-/// (`model.mm` `CompileOrReadCachedModel`).+// The name ONNX Runtime's CoreML EP gives the compiled model it stores+// inside each generated MLProgram package directory in the cache+// (`model.mm` `CompileOrReadCachedModel`).const COREML_CACHE_COMPILED_MODEL: &str = "compiled_model.mlmodelc";-/// The weight blob file name inside an ORT-generated `.mlpackage`-/// (`model_builder.cc` writes `@model_path/weights/weight.bin`).+// The weight blob file name inside an ORT-generated `.mlpackage`+// (`model_builder.cc` writes `@model_path/weights/weight.bin`).const COREML_PACKAGE_WEIGHT_BLOB: &str = "weight.bin";#[cfg(any(target_os = "ios", target_os = "macos"))]const ENABLE_PERSISTENT_COREML_CACHE: bool = true;-/// The FP16 representation is created lazily and retained so that a shared-/// preprocessing result only pays the conversion cost once.pub(crate) struct PreparedF32Input {f32_data: Vec<f32>,f16_data: OnceCell<Vec<half::f16>>,@@ -114,8 +112,8 @@ pub(crate) enum ExecutionMode {CpuOnly,}-/// Identifies the successful attempt's preferred provider, not its registered-/// fallback providers, for result attribution.+// Identifies the successful attempt's preferred provider, not its registered+// fallback providers, for result attribution.#[derive(Clone, Copy, Debug, PartialEq, Eq)]#[allow(dead_code)] // Accelerated variants are constructed only on their target OS.pub(crate) enum ExecutionProvider {@@ -198,9 +196,9 @@ pub(crate) fn build_session()))}-/// A CoreML self-test failure is treated as construction failure so the caller-/// invalidates the possibly corrupt persistent cache. WebGPU validation stays-/// inside its crash-canary window instead.+// A CoreML self-test failure is treated as construction failure so the caller+// invalidates the possibly corrupt persistent cache. WebGPU validation stays+// inside its crash-canary window instead.fn build_and_validate_session(model_path: &str, attempt: ProviderAttempt) -> MlResult<Session> {#[cfg(any(target_os = "android",@@ -240,8 +238,8 @@ fn build_and_validate_session(model_path: &str, attempt: ProviderAttempt) -> MlROk(session)}-/// The durable canary remains armed through construction and self-test, so-/// crashes and soft failures both count toward quarantine.+// The durable canary remains armed through construction and self-test, so+// crashes and soft failures both count toward quarantine.#[cfg(any(target_os = "android", target_os = "linux", target_os = "windows"))]fn build_webgpu_session_with_canary(model_path: &str,@@ -450,7 +448,7 @@ fn model_file_label(model_path: &str) -> &str {.unwrap_or(model_path)}-/// Shared with the generator so its inference path stays identical to devices.+// Shared with the generator so its inference path stays identical to devices.pub(crate) fn run_golden_tensor(session: &mut Session,input_shape: &[i64],@@ -591,7 +589,7 @@ fn coreml_provider((provider.build().error_on_failure(), prepared_cache_dir)}-/// Disabling the feature must also reclaim caches created by earlier releases.+// Disabling the feature must also reclaim caches created by earlier releases.#[cfg(any(target_os = "ios", target_os = "macos"))]fn remove_persistent_coreml_cache(model_path: &str) {let Some(coreml_root) = coreml_cache_root(Path::new(model_path))@@ -661,7 +659,8 @@ fn platform_default_attempts(attempts}-/// Missing goldens fail closed, usually indicating they were not regenerated after an update.+// Missing goldens fail closed, usually indicating they were not regenerated+// after an update.#[cfg(any(target_os = "android",target_os = "ios",@@ -743,7 +742,7 @@ fn prepare_coreml_cache_directory(Ok(cache_dir)}-/// Rebuild unmarked entries so ORT cannot reuse a package interrupted mid-build.+// Rebuild unmarked entries so ORT cannot reuse a package interrupted mid-build.#[cfg(any(target_os = "ios", target_os = "macos", test))]fn prepare_coreml_cache_entry(cache_dir: &Path) -> std::io::Result<()> {if cache_dir.exists() && !coreml_cache_complete_marker(cache_dir).is_file() {@@ -752,8 +751,8 @@ fn prepare_coreml_cache_entry(cache_dir: &Path) -> std::io::Result<()> {std::fs::create_dir_all(cache_dir)}-/// Trim before marking complete so a crash mid-trim forces a clean rebuild.-/// Trim failures only waste disk space and therefore do not fail the load.+// Trim before marking complete so a crash mid-trim forces a clean rebuild.+// Trim failures only waste disk space and therefore do not fail the load.fn finalize_coreml_cache(cache_dir: &Path, model_path: &str) {match trim_coreml_cache_weights(cache_dir) {Ok(0) => {}@@ -785,10 +784,10 @@ fn finalize_coreml_cache(cache_dir: &Path, model_path: &str) {}}-/// On a warm cache hit ONNX Runtime 1.28 only checks that the generated-/// package directory and loads `compiled_model.mlmodelc`, making the package's-/// own weights redundant. Uncompiled packages remain intact; incompatible-/// future runtimes will fail construction and trigger cache invalidation.+// On a warm cache hit ONNX Runtime 1.28 only checks that the generated+// package directory and loads `compiled_model.mlmodelc`, making the package's+// own weights redundant. Uncompiled packages remain intact; incompatible+// future runtimes will fail construction and trigger cache invalidation.fn trim_coreml_cache_weights(cache_dir: &Path) -> std::io::Result<u64> {let mut reclaimed = 0;// ORT 1.28 stores the compiled MLProgram inside@@ -813,9 +812,9 @@ fn trim_coreml_cache_weights(cache_dir: &Path) -> std::io::Result<u64> {Ok(reclaimed)}-/// Truncates `weight.bin` files under `dir`, never descending into-/// `.mlmodelc` bundles: the compiled model keeps its own `weights/weight.bin`-/// copy, and that one is exactly what warm loads read, so it must survive.+// Truncates `weight.bin` files under `dir`, never descending into+// `.mlmodelc` bundles: the compiled model keeps its own `weights/weight.bin`+// copy, and that one is exactly what warm loads read, so it must survive.fn truncate_weight_blobs(dir: &Path) -> std::io::Result<u64> {let mut reclaimed = 0;for entry in std::fs::read_dir(dir)? {@@ -853,7 +852,8 @@ fn coreml_cache_complete_marker(cache_dir: &Path) -> PathBuf {cache_dir.join(COREML_CACHE_COMPLETE_MARKER)}-/// Use Library/Caches for eviction and backup exclusion, or temp for unusual layouts.+// Use Library/Caches for eviction and backup exclusion, or temp for unusual+// layouts.#[cfg(any(target_os = "ios", target_os = "macos", test))]fn coreml_cache_root(model_path: &Path) -> PathBuf {let cache_base = model_path@@ -869,9 +869,9 @@ fn coreml_cache_root(model_path: &Path) -> PathBuf {.join(COREML_CACHE_SCHEMA)}-/// Include the filename and file metadata in the directory name because ONNX-/// Runtime's internal CoreML cache key does not necessarily change when only-/// model weights change.+// Include the filename and file metadata in the directory name because ONNX+// Runtime's internal CoreML cache key does not necessarily change when only+// model weights change.#[cfg(any(target_os = "ios", target_os = "macos", test))]fn coreml_model_cache_key(model_path: &Path) -> std::io::Result<String> {use std::time::UNIX_EPOCH;@@ -909,7 +909,7 @@ fn sanitize_cache_component(value: &str) -> String {.collect()}-/// Schema bumps must not orphan the previous version's large cache trees.+// Schema bumps must not orphan the previous version's large cache trees.#[cfg(any(target_os = "ios", target_os = "macos", test))]fn prune_stale_coreml_schema_directories(coreml_root: &Path,@@ -984,9 +984,9 @@ fn build_session_with_providers(model_path: &str, attempt: ProviderAttempt) -> MOk(session)}-/// Guard against execution providers that return NaN or infinity instead of-/// failing. The error message matches `is_execution_provider_failure` so the-/// runtime advances to the next execution provider fallback.+// Guard against execution providers that return NaN or infinity instead of+// failing. The error message matches `is_execution_provider_failure` so the+// runtime advances to the next execution provider fallback.fn ensure_finite_f32(data: &[f32]) -> MlResult<()> {if data.iter().copied().all(f32::is_finite) {return Ok(());diff --git a/rust/crates/photos/src/ml/pet/detect.rs b/rust/crates/photos/src/ml/pet/detect.rsindex 0124541f2c..23095f778d 100644--- a/rust/crates/photos/src/ml/pet/detect.rs+++ b/rust/crates/photos/src/ml/pet/detect.rs@@ -9,20 +9,17 @@ use crate::ml::{use super::{COCO_CAT, COCO_DOG, PET_SPECIES_CAT, PET_SPECIES_DOG};-// Pet face detection thresholds (from Python config)+// These thresholds match the Python pipeline.const PET_FACE_IOU_THRESHOLD: f32 = 0.5;const PET_FACE_MIN_SCORE: f32 = 0.3;const BODY_IOU_THRESHOLD: f32 = 0.5;const BODY_MIN_SCORE: f32 = 0.3;-// Species IDs used across both Rust and Dart:-// 0 = dog (face detection class_id=0, COCO_DOG=16)-// 1 = cat (face detection class_id=1, COCO_CAT=15)-// Dart maps COCO β species via: cocoClass == 15 ? 1 : 0+// Species IDs must match Dart: 0 = dog, 1 = cat.-/// Output format per row: [x, y, w, h, obj_conf, lx, ly, rx, ry, nx, ny, ...]-/// 3 keypoints: left_eye, right_eye, nose (6 values for coords).+// Rows store x, y, width, height, score, three x/y keypoints, then class scores.+// Keypoint order is left eye, right eye, nose.pub(crate) fn run_pet_face_detection(runtime: &MlRuntimeView<'_>,input: &YoloInput,@@ -143,10 +140,7 @@ fn postprocess_pet_face_tensor<T: onnx::FloatTensorData>(input.correct_box_and_keypoints(&mut box_xyxy, &mut keypoints);- // For a 2-class model (row_len >= 13): row[11] = cat score,- // row[12] = dog score. Pick argmax and map to 0=dog, 1=cat.- // For a 1-class model (row_len == 12): row[11] is the single class- // score; class is always 0 (dog).+ // Two-class rows store cat at 11 and dog at 12. One-class rows are dog-only.let class_id: u8 = if row_len >= 13 {if output_data.value(start + 12) > output_data.value(start + 11) {PET_SPECIES_DOGdiff --git a/rust/crates/photos/src/ml/pet/preprocess.rs b/rust/crates/photos/src/ml/pet/preprocess.rsindex 2e7fc23d9f..8ea35f0794 100644--- a/rust/crates/photos/src/ml/pet/preprocess.rs+++ b/rust/crates/photos/src/ml/pet/preprocess.rs@@ -5,7 +5,6 @@ use crate::ml::{use super::{PET_EMBEDDING_CHANNELS, PET_EMBEDDING_INPUT_SIZE, PET_SPECIES_CAT};-// ImageNet normalization constantsconst IMAGENET_MEAN: [f32; 3] = [0.485, 0.456, 0.406];const IMAGENET_STD: [f32; 3] = [0.229, 0.224, 0.225];@@ -59,7 +58,7 @@ pub(super) struct PixelCrop {pub(super) height: u32,}-/// Mirrors the Python pet pipeline's ImageNet-normalized CHW preprocessing.+// Keep this aligned with the Python pet pipeline's ImageNet-normalized CHW input.pub(super) struct PetEmbeddingPreprocessor {crop_resizer: RgbCropResizer,}diff --git a/rust/crates/photos/src/ml/runtime.rs b/rust/crates/photos/src/ml/runtime.rsindex 3ecf718480..2ad45a88a8 100644--- a/rust/crates/photos/src/ml/runtime.rs+++ b/rust/crates/photos/src/ml/runtime.rs@@ -64,9 +64,6 @@ struct ModelSlot {state: Mutex<ModelSlotState>,}-/// Which accelerated execution providers were behind the sessions used through-/// a [`MlRuntimeView`]. ORed over successful model executions so a result can be-/// attributed to the providers that actually computed it.#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]pub(crate) struct UsedProviders {pub(crate) coreml: bool,@@ -375,8 +372,6 @@ impl MlRuntime {}impl<'a> MlRuntimeView<'a> {- /// The accelerated providers behind every successful model execution- /// through this view so far.pub(crate) fn used_providers(&self) -> UsedProviders {self.used_providers.get()}diff --git a/rust/crates/photos/src/ml/types.rs b/rust/crates/photos/src/ml/types.rsindex 194b8803de..27fd8323ae 100644--- a/rust/crates/photos/src/ml/types.rs+++ b/rust/crates/photos/src/ml/types.rs@@ -50,9 +50,9 @@ pub(crate) fn to_face_id(file_id: i64, box_xyxy: [f32; 4]) -> String {pub struct PetFaceDetection {pub score: f32,pub box_xyxy: [f32; 4],- /// 3 keypoints: [left_eye, right_eye, nose]+ // [left eye, right eye, nose].pub keypoints: [[f32; 2]; 3],- /// 0 = dog, 1 = cat (from class scores in detector output)+ // 0 = dog, 1 = cat.pub class_id: u8,}@@ -66,7 +66,7 @@ pub struct PetAlignmentResult {#[derive(Clone, Debug)]pub struct PetFaceResult {pub detection: PetFaceDetection,- /// 0 = dog, 1 = cat+ // 0 = dog, 1 = cat.pub species: u8,pub face_embedding: Vec<f32>,pub pet_face_id: String,@@ -77,7 +77,7 @@ pub struct PetFaceResult {pub struct PetBodyDetection {pub score: f32,pub box_xyxy: [f32; 4],- /// COCO class: 15 = cat, 16 = dog+ // COCO class: 15 = cat, 16 = dog.pub coco_class: u8,}diff --git a/rust/crates/photos/src/ml/vector_db.rs b/rust/crates/photos/src/ml/vector_db.rsindex 87bbd034f7..31ba177d49 100644--- a/rust/crates/photos/src/ml/vector_db.rs+++ b/rust/crates/photos/src/ml/vector_db.rs@@ -30,9 +30,6 @@ impl VectorDB {dimensions,metric: MetricKind::IP,quantization: ScalarKind::F32,- connectivity: 0, // auto- expansion_add: 0, // auto- expansion_search: 0, // auto..IndexOptions::default()};diff --git a/rust/crates/photos/src/ml/webgpu.rs b/rust/crates/photos/src/ml/webgpu.rsindex a164b72154..93fac9ae94 100644--- a/rust/crates/photos/src/ml/webgpu.rs+++ b/rust/crates/photos/src/ml/webgpu.rs@@ -1,7 +1,7 @@-//! Durable WebGPU crash canary: arm before touching the driver and disarm only-//! after session construction and warm-up. Three recorded failures quarantine-//! the model directory across restarts. The caller's model-slot lock serializes-//! access.+// Arm the durable canary before touching the driver and disarm it only after+// session construction and warm-up. Three recorded failures quarantine the+// model directory across restarts. The caller's model-slot lock serializes+// access.#[cfg(all(not(target_os = "windows"),@@ -24,7 +24,7 @@ use std::{path::{Path, PathBuf},};-/// Bump to retry quarantined devices after major ONNX Runtime or Dawn changes.+// Bump to retry quarantined devices after major ONNX Runtime or Dawn changes.#[cfg(any(target_os = "android",target_os = "linux",@@ -51,15 +51,15 @@ pub(crate) fn set_enabled(enabled: bool) {let _ = enabled;}-/// Adapter probing touches Vulkan and therefore happens after arming, not here.+// Adapter probing touches Vulkan and therefore happens after arming, not here.#[cfg(any(target_os = "android", target_os = "linux", target_os = "windows"))]pub(crate) fn attempt_permitted(model_path: &str) -> bool {WEBGPU_ENABLED.load(Ordering::Relaxed)&& model_dir(model_path).is_some_and(|dir| !quarantined(&dir))}-/// Mirrors Chromium's `gpu/config/webgpu_blocklist_impl.cc` Android 12+ policy-/// as of 2026-07; revisit with pinned ONNX Runtime or Dawn upgrades.+// Mirrors Chromium's `gpu/config/webgpu_blocklist_impl.cc` Android 12+ policy+// as of 2026-07; revisit with pinned ONNX Runtime or Dawn upgrades.#[cfg(any(target_os = "android", test))]const ALLOWLISTED_VULKAN_VENDOR_IDS: [u32; 3] = [0x13B5, // ARM (Mali, Immortalis)@@ -67,7 +67,7 @@ const ALLOWLISTED_VULKAN_VENDOR_IDS: [u32; 3] = [0x8086, // Intel];-/// Dawn chooses independently, so every enumerated adapter must be allowlisted.+// Dawn chooses independently, so every enumerated adapter must be allowlisted.#[cfg(any(target_os = "android", test))]fn vendors_allowlisted(vendor_ids: &[u32]) -> bool {!vendor_ids.is_empty()@@ -81,11 +81,12 @@ fn vendors_allowlisted(vendor_ids: &[u32]) -> bool {pub(crate) enum AdapterCheck {Allowed,Denied,- /// Probe failures count toward quarantine; policy denials do not.+ // Probe failures count toward quarantine; policy denials do not.Failed,}-/// Must run inside an armed canary because this is the first Vulkan driver access.+// Must run inside an armed canary because this is the first Vulkan driver+// access.#[cfg(target_os = "android")]pub(crate) fn check_adapter() -> AdapterCheck {static VERDICT: OnceLock<AdapterCheck> = OnceLock::new();@@ -134,7 +135,7 @@ fn probe_vulkan_vendor_ids() -> Result<Vec<u32>, String> {vendor_ids}-/// Dropping without disarming intentionally preserves the failed-attempt record.+// Dropping without disarming intentionally preserves the failed-attempt record.#[cfg(any(target_os = "android",target_os = "linux",diff --git a/rust/crates/photos/src/motion_photo/ftyp.rs b/rust/crates/photos/src/motion_photo/ftyp.rsindex fa7977e44e..fd2c240db1 100644--- a/rust/crates/photos/src/motion_photo/ftyp.rs+++ b/rust/crates/photos/src/motion_photo/ftyp.rs@@ -1,39 +1,25 @@use super::VideoIndex;-/// Minimum valid ftyp box size: 4 (size) + 4 (type) = 8 bytes.const FTYP_BOX_MIN_SIZE: u32 = 8;-/// Maximum ftyp box size we consider plausible for an embedded motion video.-/// Real ftyp boxes are typically 16-32 bytes. We use a generous ceiling to-/// handle exotic compatible-brand lists while rejecting garbage matches.+// Real ftyp boxes are usually 16-32 bytes. The larger ceiling allows unusual+// brand lists while rejecting accidental matches in image data.const FTYP_BOX_MAX_SIZE: u32 = 1024;-/// Known major brands for MP4, QuickTime, and related video container formats.-/// Image-only brands (heic, heif, mif1, avif) are intentionally excluded.+// Image-only brands are intentionally excluded.const KNOWN_VIDEO_BRANDS: &[[u8; 4]] = &[*b"isom", *b"iso2", *b"iso5", *b"iso6", *b"mp41", *b"mp42", *b"mp71", *b"M4V ", *b"M4VP",*b"avc1", *b"mmp4", *b"3gp4", *b"3gp5", *b"3gp6", *b"qt ", *b"MSNV", *b"dash", *b"f4v ",];-/// Finds all valid embedded MP4/QuickTime ftyp boxes and returns the bounds of-/// the **largest** individual segment.-///-/// Some motion photos embed two MP4s: a short preview clip and the full-/// video. The ordering varies by device, so we cannot simply pick the first-/// or last. Instead we measure each segment from one ftyp to the next-/// candidate, or to EOF for the last one, and return the largest slice.-///-/// A candidate ftyp is accepted when:-/// 1. The 4 bytes before `ftyp` encode a box size in [8, 1024].-/// 2. The 4 bytes after `ftyp` are a recognised video brand.-/// 3. The box does not start at byte 0 (that would be a standalone MP4).+// Some phones embed preview and full MP4s in either order. Return the largest+// valid segment.pub(super) fn find_largest_ftyp_segment(bytes: &[u8]) -> Option<VideoIndex> {let len = bytes.len();if len < 12 {return None;}- // Collect all valid ftyp box starts.let mut starts: Vec<usize> = Vec::new();let last = len.saturating_sub(8);let mut i = 4;@@ -47,6 +33,7 @@ pub(super) fn find_largest_ftyp_segment(bytes: &[u8]) -> Option<VideoIndex> {bytes[box_start + 2],bytes[box_start + 3],]);+ // An ftyp box at byte 0 belongs to a standalone MP4.if (FTYP_BOX_MIN_SIZE..=FTYP_BOX_MAX_SIZE).contains(&box_size) && box_start > 0 {let brand: [u8; 4] = [bytes[i + 4], bytes[i + 5], bytes[i + 6], bytes[i + 7]];if KNOWN_VIDEO_BRANDS.contains(&brand) {@@ -67,8 +54,6 @@ pub(super) fn find_largest_ftyp_segment(bytes: &[u8]) -> Option<VideoIndex> {});}- // Pick the segment with the most bytes.- // Segment size = next_ftyp_start - this_ftyp_start (or EOF for last).let mut best_index = VideoIndex {start: starts[0],end: starts[1],diff --git a/rust/crates/photos/src/motion_photo/mod.rs b/rust/crates/photos/src/motion_photo/mod.rsindex 7976c07226..cd7419ab0b 100644--- a/rust/crates/photos/src/motion_photo/mod.rs+++ b/rust/crates/photos/src/motion_photo/mod.rs@@ -173,13 +173,12 @@ mod tests {use std::fs;use tempfile::tempdir;- /// Build a minimal ftyp box with the given major brand (16 bytes).fn make_ftyp_box(brand: &[u8; 4]) -> Vec<u8> {let mut buf = Vec::with_capacity(16);- buf.extend_from_slice(&16u32.to_be_bytes()); // box size+ buf.extend_from_slice(&16u32.to_be_bytes());buf.extend_from_slice(b"ftyp");buf.extend_from_slice(brand);- buf.extend_from_slice(&0u32.to_be_bytes()); // minor version+ buf.extend_from_slice(&0u32.to_be_bytes());buf}@@ -213,14 +212,13 @@ mod tests {#[test]fn picks_largest_segment_when_multiple_ftyp_exist() {- // Scenario 1: first segment is larger (full video first, preview second)let mut bytes = b"jpeg-prefix".to_vec();let first_start = bytes.len();bytes.extend_from_slice(&make_ftyp_box(b"mp42"));- bytes.extend_from_slice(&[0xAA; 500]); // large segment+ bytes.extend_from_slice(&[0xAA; 500]);let second_start = bytes.len();bytes.extend_from_slice(&make_ftyp_box(b"isom"));- bytes.extend_from_slice(&[0xBB; 50]); // small segment+ bytes.extend_from_slice(&[0xBB; 50]);let index = get_motion_video_index(&bytes).expect("video index should exist");assert_eq!(index.start, first_start);@@ -229,13 +227,12 @@ mod tests {extract_motion_video(&bytes, Some(index)).expect("video bytes should extract");assert_eq!(extracted.len(), second_start - first_start);- // Scenario 2: second segment is larger (preview first, full video second)let mut bytes2 = b"jpeg-prefix".to_vec();bytes2.extend_from_slice(&make_ftyp_box(b"mp42"));- bytes2.extend_from_slice(&[0xCC; 50]); // small segment+ bytes2.extend_from_slice(&[0xCC; 50]);let second_start = bytes2.len();bytes2.extend_from_slice(&make_ftyp_box(b"isom"));- bytes2.extend_from_slice(&[0xDD; 500]); // large segment+ bytes2.extend_from_slice(&[0xDD; 500]);let index2 = get_motion_video_index(&bytes2).expect("video index should exist");assert_eq!(index2.start, second_start);@@ -275,7 +272,6 @@ mod tests {fn detects_ftyp_with_larger_box_size() {let mut bytes = b"jpeg-prefix-data".to_vec();let box_start = bytes.len();- // 28-byte ftyp box (like Pixel 6): size + "ftyp" + brand + version + compat brandsbytes.extend_from_slice(&28u32.to_be_bytes());bytes.extend_from_slice(b"ftyp");bytes.extend_from_slice(b"isom");@@ -297,7 +293,7 @@ mod tests {#[test]fn rejects_ftyp_with_implausible_box_size() {let mut bytes = b"jpeg-prefix-data".to_vec();- bytes.extend_from_slice(&0u32.to_be_bytes()); // box size 0 (invalid)+ bytes.extend_from_slice(&0u32.to_be_bytes());bytes.extend_from_slice(b"ftyp");bytes.extend_from_slice(b"mp42");bytes.extend_from_slice(&0u32.to_be_bytes());diff --git a/rust/crates/photos/tests/motion_photos_assets_test.rs b/rust/crates/photos/tests/motion_photos_assets_test.rsindex a5fe4f47a0..81854a23c4 100644--- a/rust/crates/photos/tests/motion_photos_assets_test.rs+++ b/rust/crates/photos/tests/motion_photos_assets_test.rs@@ -1,17 +1,14 @@use ente_photos::{extract_motion_video_from_path, get_motion_video_index_from_path};use std::path::{Path, PathBuf};+// External fixtures live beside the repository unless overridden.fn fixture_dir() -> Option<PathBuf> {- // Optional override for CI or custom local layouts.if let Some(path) = std::env::var_os("ENTE_TEST_FIXTURES_DIR") {return Some(PathBuf::from(path).join("media/motion-photos/v1/files"));}- // CARGO_MANIFEST_DIR points to `<repo>/rust/crates/photos`.- // We resolve `<repo>/..../test-fixtures/media/motion-photos/v1/files`,- // where `test-fixtures` is expected to be a sibling of the main repo root.let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));- let repo_root = manifest_dir.parent()?.parent()?.parent()?; // photos -> crates -> rust -> <repo root>+ let repo_root = manifest_dir.parent()?.parent()?.parent()?;let parent_of_repo = repo_root.parent()?;Some(parent_of_repo@@ -85,7 +82,6 @@ fn validates_known_motion_photo_indices_when_fixtures_present() {.expect("video present");assert!(motion_heic_video.len() > 1_000_000);- // Dual-MP4 motion photo: two embedded MP4s, full video is the second (larger) one.let Some(dual_mp4) = fixture("dual_mp4_video_last.jpg") else {eprintln!("Skipping: external fixture dual_mp4_video_last.jpg not present");return;@@ -101,7 +97,6 @@ fn validates_known_motion_photo_indices_when_fixtures_present() {.expect("video present");assert!(dual_video.len() > 1_000_000);- // Dual-MP4 motion photo: two embedded MP4s, full video is the first (larger) one.let Some(dual_mp4_first) = fixture("dual_mp4_video_first.jpg") else {eprintln!("Skipping: external fixture dual_mp4_video_first.jpg not present");return;diff --git a/rust/crates/photos/tests/support/ml_indexing.rs b/rust/crates/photos/tests/support/ml_indexing.rsindex 0e73ff30f3..1a97886fbc 100644--- a/rust/crates/photos/tests/support/ml_indexing.rs+++ b/rust/crates/photos/tests/support/ml_indexing.rs@@ -356,16 +356,12 @@ impl MlIndexingTestContext {}}-/// A downloaded production model together with its content hash as pinned in-/// the asset lock, for embedding into generated golden entries.#[allow(dead_code)]pub(crate) struct GoldenModelAsset {pub(crate) path: PathBuf,pub(crate) sha256: String,}-/// Downloaded production model assets for the golden self-test tooling, with-/// ONNX Runtime already initialized. Used by the ml_goldens developer tool only.#[allow(dead_code)]pub(crate) struct GoldenTestAssets {pub(crate) face_detection: GoldenModelAsset,@@ -461,7 +457,6 @@ struct ModelAssets {face_detection: ModelAsset,face_embedding: ModelAsset,clip_image: ModelAsset,- // Used by the ml_goldens developer tool only.#[allow(dead_code)]clip_text: ModelAsset,#[allow(dead_code)]diff --git a/rust/crates/space/src/client/assets.rs b/rust/crates/space/src/client/assets.rsindex 6b02da0fc2..86201319ed 100644--- a/rust/crates/space/src/client/assets.rs+++ b/rust/crates/space/src/client/assets.rs@@ -1,11 +1,3 @@-//! Space asset upload and download.-//!-//! Posts and profiles store their media in an object store fronted by presigned-//! URLs. These methods presign an upload, push the encrypted bytes, and fetch-//! and decrypt them back. Post assets are keyed by a per-post key; profile-//! avatar/cover assets by the Space key. Photo bytes are validated before-//! upload (posts are photo-only).-use super::{AccountSpaceCtx, PostPhotoAssetOptions, UPLOAD_PURPOSE_AVATAR, UPLOAD_PURPOSE_COVER,encrypt_post_object_metadata, ensure_space_upload_size, ensure_supported_photo_bytes,diff --git a/rust/crates/space/src/client/entity_keys.rs b/rust/crates/space/src/client/entity_keys.rsindex dbdb2c90a2..d54b86d235 100644--- a/rust/crates/space/src/client/entity_keys.rs+++ b/rust/crates/space/src/client/entity_keys.rs@@ -1,11 +1,3 @@-//! Space entity keys.-//!-//! Entity keys are small wrapped keys the server stores per account under a-//! string type tag (for example the Space root key). These methods read and-//! write them through the generic `/user-entity/key` endpoints. Space callers-//! keep using a combined secretbox payload; this layer splits and joins the-//! nonce/header required by the generic API.-use super::AccountSpaceCtx;use crate::error::{Result, SpaceError};use crate::transport::{CreateEntityKeyRequest, EntityKeyPayload, EntityKeyResponse};@@ -76,6 +68,8 @@ impl AccountSpaceCtx {}}+// Space uses a combined secretbox payload, but this API stores its 24-byte+// nonce separately.fn split_entity_key_payload(payload: &EntityKeyPayload) -> Result<(String, String)> {let combined = b64::decode(&payload.encrypted_key)?;if combined.len() <= SPACE_ENTITY_KEY_HEADER_BYTES {diff --git a/rust/crates/space/src/client/friends.rs b/rust/crates/space/src/client/friends.rsindex 6e729e5df9..76695bed21 100644--- a/rust/crates/space/src/client/friends.rs+++ b/rust/crates/space/src/client/friends.rs@@ -1,10 +1,3 @@-//! Space friends.-//!-//! Friendship in Spaces is a mutual share of each owner's Space key, sealed to-//! the other's public key. These methods send and accept friend requests by-//! username, list and remove friends, query a relationship, and re-seal shares-//! to friends after a Space key rotation.-use super::AccountSpaceCtx;use crate::crypto::seal_with_public_key;use crate::error::{Result, SpaceError};diff --git a/rust/crates/space/src/client/keys.rs b/rust/crates/space/src/client/keys.rsindex 353a9a6ea7..88fa223aad 100644--- a/rust/crates/space/src/client/keys.rs+++ b/rust/crates/space/src/client/keys.rs@@ -1,11 +1,3 @@-//! Space key versions and rotation.-//!-//! Each Space key has a version; older posts and profiles stay readable by-//! walking the wrapped key chain back from the current version. These methods-//! list versions, reconstruct the version-to-key history, and rotate the Space-//! key (re-wrapping the profile and previous key under the new one). The private-//! key-resolution spine lives in [`super`](super::AccountSpaceCtx).-use std::collections::BTreeMap;use super::{AccountSpaceCtx, build_space_key_history_map};@@ -112,6 +104,8 @@ impl AccountSpaceCtx {&space_root_key,&next_space_key,)?),+ // Keep old posts and profiles readable through the wrapped key+ // chain.wrapped_prev_key: b64::encode(&encrypt_secretbox_payload(&next_space_key,¤t.space_key,diff --git a/rust/crates/space/src/client/media.rs b/rust/crates/space/src/client/media.rsindex 3a1ffb0fc1..fc2f00e177 100644--- a/rust/crates/space/src/client/media.rs+++ b/rust/crates/space/src/client/media.rs@@ -1,15 +1,6 @@-//! Photo media-type validation for Space uploads.-//!-//! Space posts accept photos only. These helpers normalize a client-declared-//! media type and sniff raw bytes by magic number, so a caller can reject-//! non-photo uploads before they reach the object store.-use super::ONLY_PHOTOS_UPLOAD_MESSAGE;use crate::error::{Result, SpaceError};-/// Normalize a client-declared photo media type, rejecting anything that is not-/// a supported still image. `image/jpg` is folded to `image/jpeg`. Returns-/// `Ok(None)` when no media type was provided.pub(crate) fn ensure_supported_photo_media_type(media_type: Option<&str>,) -> Result<Option<String>> {@@ -31,8 +22,6 @@ pub(crate) fn ensure_supported_photo_media_type(Err(SpaceError::InvalidInput(ONLY_PHOTOS_UPLOAD_MESSAGE.into()))}-/// Infer the media type of `bytes` from its magic number, erroring if it is not-/// a supported photo format.pub(crate) fn ensure_supported_photo_bytes(bytes: &[u8]) -> Result<&'static str> {if let Some(media_type) = supported_photo_media_type_for_bytes(bytes) {return Ok(media_type);@@ -41,8 +30,6 @@ pub(crate) fn ensure_supported_photo_bytes(bytes: &[u8]) -> Result<&'static str>Err(SpaceError::InvalidInput(ONLY_PHOTOS_UPLOAD_MESSAGE.into()))}-/// Sniff `bytes` and return the matching photo media type, or `None` if the-/// leading bytes match no supported format.pub(crate) fn supported_photo_media_type_for_bytes(bytes: &[u8]) -> Option<&'static str> {if bytes.starts_with(&[0xff, 0xd8, 0xff]) {return Some("image/jpeg");@@ -59,8 +46,6 @@ pub(crate) fn supported_photo_media_type_for_bytes(bytes: &[u8]) -> Option<&'staNone}-/// Whether `bytes` is an ISOBMFF/HEIF container with a still-image brand we-/// accept (HEIC/HEIF and the related single-image and sequence brands).fn is_supported_heif_bytes(bytes: &[u8]) -> bool {if bytes.len() < 12 || &bytes[4..8] != b"ftyp" {return false;diff --git a/rust/crates/space/src/client/messages.rs b/rust/crates/space/src/client/messages.rsindex 9278c2f6ef..c72ff226d1 100644--- a/rust/crates/space/src/client/messages.rs+++ b/rust/crates/space/src/client/messages.rs@@ -1,10 +1,3 @@-//! Space direct messages.-//!-//! Messages are sealed to a per-message key that is in turn sealed to both the-//! sender's and recipient's Space identity public keys, so either party can-//! open them. These methods list conversations and threads, send and reply to-//! messages (including replies to a post), and decrypt, like, and delete them.-use super::{AccountSpaceCtx, MESSAGE_KIND_POST_REPLY, MESSAGE_KIND_REGULAR, validate_message_payload,};@@ -262,6 +255,8 @@ impl AccountSpaceCtx {let plaintext = serde_json::to_vec(payload).map_err(|err| SpaceError::InvalidInput(format!("invalid message payload: {err}")))?;validate_message_payload(payload, plaintext.len())?;+ // Seal the message key to both identities so either party can decrypt+ // it.let sender_key = seal_with_public_key(&message_key, &identity.public_key)?;let recipient_key = seal_with_public_key(&message_key, &recipient_public_key)?;Ok(CreateMessageRequest {diff --git a/rust/crates/space/src/client/posts.rs b/rust/crates/space/src/client/posts.rsindex 25e5bff2b1..e36b4acfd3 100644--- a/rust/crates/space/src/client/posts.rs+++ b/rust/crates/space/src/client/posts.rs@@ -1,11 +1,3 @@-//! Space posts and feed.-//!-//! Posts carry a per-post key (wrapped to the Space key) plus an encrypted-//! caption and photo objects. These methods create and list posts, page the-//! cross-Space feed, decrypt post keys/captions/objects, and handle likes,-//! notifications, and post asset downloads. Key resolution and caching are-//! delegated to the spine in [`super`](super::AccountSpaceCtx).-use super::{AccountSpaceCtx, decrypt_post_object_metadata, ensure_post_objects_are_photos,post_response_from_feed_item,diff --git a/rust/crates/space/src/client/profiles.rs b/rust/crates/space/src/client/profiles.rsindex f3a7dbe0c5..9ae3938ad3 100644--- a/rust/crates/space/src/client/profiles.rs+++ b/rust/crates/space/src/client/profiles.rs@@ -1,11 +1,3 @@-//! Space profiles.-//!-//! A Space profile is an encrypted blob (display name, bio, and the like) plus-//! optional avatar and cover assets, all keyed by the Space key for its-//! version. These methods fetch the raw or decrypted profile and update it,-//! re-using the cached owned-Space key via the spine in-//! [`super`](super::AccountSpaceCtx).-use super::{AccountSpaceCtx, decrypt_space_profile, space_profile_without_payload};use crate::crypto::encrypt_secretbox_payload;use crate::error::{Result, SpaceError};diff --git a/rust/crates/space/src/client/test_support.rs b/rust/crates/space/src/client/test_support.rsindex 96defadf31..53047ba8cb 100644--- a/rust/crates/space/src/client/test_support.rs+++ b/rust/crates/space/src/client/test_support.rs@@ -1,9 +1,3 @@-//! Shared test fixtures for the `client` modules.-//!-//! Helpers for constructing test contexts and canned server responses, used by-//! the per-module `#[cfg(test)] mod tests`. Gated on `cfg(test)`, so none of-//! this is compiled into the library.-use serde_json::json;use super::{AccountSpaceCtx, SpaceIdentity, cache_lock, generate_key, generate_keypair};@@ -11,20 +5,13 @@ use crate::crypto::encrypt_secretbox_payload;use crate::models::OpenAccountSpaceCtxInput;use ente_core::{b64, crypto::SecretVec};-/// A WEBP magic-number header, enough for the media sniffer to accept the bytes-/// as a photo.pub(crate) const TEST_WEBP_BYTES: &[u8] = b"RIFF0000WEBP";-/// An MP4 `ftyp` header, used to assert that video bytes are rejected.pub(crate) const TEST_MP4_BYTES: &[u8] = b"\0\0\0\x18ftypmp42";-/// Open an [`AccountSpaceCtx`] against `base_url` with a random Space root key-/// and a pre-seeded Space identity, so tests skip the identity round-trip.pub(crate) fn test_account_ctx(base_url: &str) -> AccountSpaceCtx {test_account_ctx_with_space_root_key(base_url, generate_key())}-/// Like [`test_account_ctx`] but with a caller-supplied Space root key, for-/// tests that need to wrap keys under a known root.pub(crate) fn test_account_ctx_with_space_root_key(base_url: &str,space_root_key: Vec<u8>,@@ -52,7 +39,6 @@ pub(crate) fn test_account_ctx_with_space_root_key(ctx}-/// The public key of the identity seeded by [`test_account_ctx_with_space_root_key`].pub(crate) fn test_public_key(ctx: &AccountSpaceCtx) -> Vec<u8> {cache_lock(&ctx.space_identity_cache, "space identity").expect("space identity cache")@@ -63,8 +49,6 @@ pub(crate) fn test_public_key(ctx: &AccountSpaceCtx) -> Vec<u8> {.clone()}-/// A canned `/space` owned-spaces list response wrapping `space_key` under-/// `space_root_key`.pub(crate) fn owned_space_response(space_root_key: &[u8],space_key: &[u8],diff --git a/rust/crates/space/src/client/tests.rs b/rust/crates/space/src/client/tests.rsindex e8a5bed962..1c703de132 100644--- a/rust/crates/space/src/client/tests.rs+++ b/rust/crates/space/src/client/tests.rs@@ -1,10 +1,3 @@-//! Integration tests for the Space client.-//!-//! Black-box tests over the public `AccountSpaceCtx` API, driven by a mock HTTP server.-//! Shared fixtures live in-//! [`test_support`](super::test_support). Kept in-crate (rather than `tests/`)-//! because a few fixtures need crate-internal crypto and constructors.-use super::test_support::*;use super::*;use crate::crypto::{encrypt_asset_payload, seal_with_public_key};diff --git a/rust/crates/test-support/src/lib.rs b/rust/crates/test-support/src/lib.rsindex 19428e8651..0dcc760c1a 100644--- a/rust/crates/test-support/src/lib.rs+++ b/rust/crates/test-support/src/lib.rs@@ -1,8 +1,3 @@-//! A live Museum for integration tests.-//!-//! [`Museum`] spins up a local Museum server backed by temporary Postgres and-//! object storage. See the crate README for requirements.-mod museum;mod net;mod object_store;@@ -14,15 +9,10 @@ pub use museum::Museum;pub type TestResult<T = ()> = Result<T, Box<dyn std::error::Error>>;-/// Museum accepts [`HARDCODED_OTT`] as the email verification code for any-/// address ending in [`HARDCODED_OTT_EMAIL_SUFFIX`], so tests can sign up and-/// log in without an email inbox.pub const HARDCODED_OTT: &str = "123456";-/// See [`HARDCODED_OTT`].pub const HARDCODED_OTT_EMAIL_SUFFIX: &str = "@example.org";-/// Precomputed sensitive KDF fixture for Museum accounts.pub mod account_fixture {pub const PASSWORD: &str = "museum-account-fixture-password";// Argon2id(PASSWORD, 16 Γ 0x4d, 256 MiB, 16 ops).diff --git a/rust/crates/test-support/src/museum.rs b/rust/crates/test-support/src/museum.rsindex 8242df22a5..c121c7687e 100644--- a/rust/crates/test-support/src/museum.rs+++ b/rust/crates/test-support/src/museum.rs@@ -15,11 +15,6 @@ use crate::{server,};-/// A running Museum for integration tests, backed by a temporary Postgres.-///-/// Created with [`Museum::run`], which boots both, runs the test, and tears-/// everything down on drop. The temporary directory is removed unless the test-/// fails, in which case it is retained for inspection.pub struct Museum {_server: ChildProcess,_postgres: postgres::Postgres,@@ -29,10 +24,6 @@ pub struct Museum {}impl Museum {- /// Boot a Museum, run `test` against it, then tear everything down.- ///- /// On failure the temporary directory is retained (its path is printed to- /// stderr) so the museum and Postgres logs can be inspected.pub fn run(test: impl FnOnce(&Self) -> TestResult) -> TestResult {let mut museum = Self::start()?;match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| test(&museum))) {@@ -48,7 +39,6 @@ impl Museum {}}- /// Boot a Museum and run an asynchronous test on a Tokio runtime.pub fn run_async<F, Fut>(test: F) -> TestResultwhereF: FnOnce(String) -> Fut,@@ -99,18 +89,15 @@ impl Museum {})}- /// The base URL of the running Museum, e.g. `http://127.0.0.1:1234`.pub fn endpoint(&self) -> &str {&self.endpoint}- /// A scratch directory tied to this Museum's lifetime, for test-local files.pub fn temp_dir(&self) -> &Path {self.temp_dir.path()}}-/// The repository's `server/` directory, which Museum is run from.fn server_dir() -> TestResult<PathBuf> {let crate_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));let repo_dir = crate_dirdiff --git a/rust/crates/test-support/src/net.rs b/rust/crates/test-support/src/net.rsindex 20cd8e7d3a..d25fbeb8c0 100644--- a/rust/crates/test-support/src/net.rs+++ b/rust/crates/test-support/src/net.rs@@ -2,10 +2,7 @@ use crate::TestResult;pub const LOCAL_HOST: &str = "127.0.0.1";-/// An unused local TCP port.-///-/// Racy: the port is free when returned, not reserved, so the caller should-/// bind it promptly.+// The port is free when returned, not reserved; bind it immediately.pub fn free_port() -> TestResult<u16> {Ok(std::net::TcpListener::bind((LOCAL_HOST, 0))?.local_addr()?diff --git a/rust/crates/test-support/src/postgres.rs b/rust/crates/test-support/src/postgres.rsindex 34a053f075..552e1ef954 100644--- a/rust/crates/test-support/src/postgres.rs+++ b/rust/crates/test-support/src/postgres.rs@@ -10,7 +10,6 @@ use crate::{const DATABASE: &str = "ente_test";-/// A temporary local Postgres, torn down on drop.pub struct Postgres {inner: PostgreSQL,}