π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Rename contacts and wasm error types, drop binding doc slop
Manav Rathif34491b8b12f
diff --git a/rust/bindings/frb/ente-rust/src/api/contacts.rs b/rust/bindings/frb/ente-rust/src/api/contacts.rsindex 0574cf1ea2..9949ec5eee 100644--- a/rust/bindings/frb/ente-rust/src/api/contacts.rs+++ b/rust/bindings/frb/ente-rust/src/api/contacts.rs@@ -1,5 +1,3 @@-//! FRB bindings for contacts APIs.-use std::sync::Arc;use ente_contacts::{LegacyKitOwnerRecoverySession, LegacyKitRecoveryInitiator};@@ -19,8 +17,8 @@ pub enum ContactsError {ActiveRecoverySession { message: String },}-impl From<ente_contacts::ContactsError> for ContactsError {- fn from(e: ente_contacts::ContactsError) -> Self {+impl From<ente_contacts::Error> for ContactsError {+ fn from(e: ente_contacts::Error) -> Self {use ente_contacts::ErrorKind as K;let message = ente_core::error::chain(&e);match e.kind() {@@ -43,11 +41,8 @@ impl From<ente_contacts::ContactsError> for ContactsError {#[frb]#[derive(Clone)]-/// Persistable wrapped root contact key returned from Rust.pub struct WrappedRootContactKey {- /// Wrapped root contact key bytes encoded as base64.pub encrypted_key: String,- /// Blob header used to unwrap the root contact key.pub header: String,}@@ -71,31 +66,18 @@ impl From<WrappedRootContactKey> for ente_contacts::WrappedRootContactKey {#[frb]#[derive(Clone)]-/// Account key attributes required to decrypt the owner's recovery key.pub struct AccountKeyAttributes {- /// Salt for deriving key-encryption-key from password (base64).pub kek_salt: 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 limit.pub mem_limit: u32,- /// Argon2 ops limit.pub ops_limit: u32,- /// Master key encrypted with recovery key (base64).pub master_key_encrypted_with_recovery_key: Option<String>,- /// Nonce for master key decryption with recovery key (base64).pub master_key_decryption_nonce: Option<String>,- /// Recovery key encrypted with master key (base64).pub recovery_key_encrypted_with_master_key: Option<String>,- /// Nonce for recovery key decryption (base64).pub recovery_key_decryption_nonce: Option<String>,}@@ -121,11 +103,8 @@ impl From<AccountKeyAttributes> for ente_accounts::auth::KeyAttributes {#[frb]#[derive(Clone)]-/// Encrypted contact payload fields managed by the client.pub struct ContactData {- /// User id of the contact being referenced.pub contact_user_id: i64,- /// User-chosen display name for the contact.pub name: String,}@@ -140,23 +119,14 @@ impl From<ContactData> for ente_contacts::ContactData {#[frb]#[derive(Clone)]-/// Fully decoded contact record returned by Rust.pub struct ContactRecord {- /// Stable contact entity id.pub id: String,- /// User id of the referenced contact.pub contact_user_id: i64,- /// Server-resolved mutable email for the referenced user.pub email: Option<String>,- /// Client-managed display name from the encrypted payload.pub name: Option<String>,- /// Current profile picture attachment id, if any.pub profile_picture_attachment_id: Option<String>,- /// Whether this record is a tombstone.pub is_deleted: bool,- /// Contact creation timestamp in microseconds.pub created_at: i64,- /// Last update timestamp in microseconds.pub updated_at: i64,}@@ -177,9 +147,7 @@ impl From<ente_contacts::ContactRecord> for ContactRecord {#[frb]#[derive(Clone, Copy)]-/// Offline legacy kit split variant.pub enum LegacyKitVariant {- /// Any two of three sheets can recover the account.TwoOfThree,}@@ -193,17 +161,11 @@ impl From<ente_contacts::LegacyKitVariant> for LegacyKitVariant {#[frb]#[derive(Clone, Copy)]-/// Owner-visible recovery session status for an offline legacy kit.pub enum LegacyKitRecoveryStatus {- /// Waiting for the selected recovery time.Waiting,- /// Recovery bundle is available.Ready,- /// Owner blocked this recovery attempt.Blocked,- /// Recovery was cancelled.Cancelled,- /// Recovery completed.Recovered,}@@ -221,17 +183,11 @@ impl From<ente_contacts::LegacyKitRecoveryStatus> for LegacyKitRecoveryStatus {#[frb]#[derive(Clone)]-/// Owner-visible recovery session for an offline legacy kit.pub struct LegacyKitRecoverySession {- /// Recovery session id.pub id: String,- /// Kit id being recovered.pub kit_id: String,- /// Current recovery status.pub status: LegacyKitRecoveryStatus,- /// Remaining microseconds until the recovery becomes usable.pub wait_till: i64,- /// Session creation timestamp.pub created_at: i64,}@@ -249,13 +205,9 @@ impl From<ente_contacts::LegacyKitRecoverySession> for LegacyKitRecoverySession#[frb]#[derive(Clone)]-/// Owner-facing audit hint for a successful legacy kit recovery open.pub struct LegacyKitRecoveryInitiatorHint {- /// Client-reported sheet indexes used by the recovery flow.pub used_part_indexes: Vec<u8>,- /// Server-observed IP address.pub ip: String,- /// Server-observed user agent.pub user_agent: String,}@@ -271,11 +223,8 @@ impl From<LegacyKitRecoveryInitiator> for LegacyKitRecoveryInitiatorHint {#[frb]#[derive(Clone)]-/// Owner-facing recovery session details for a legacy kit.pub struct LegacyKitOwnerRecoverySessionDetails {- /// Active session, if one exists.pub session: Option<LegacyKitRecoverySession>,- /// Server-captured audit hints for successful recovery opens.pub initiators: Vec<LegacyKitRecoveryInitiatorHint>,}@@ -290,11 +239,8 @@ impl From<LegacyKitOwnerRecoverySession> for LegacyKitOwnerRecoverySessionDetail#[frb]#[derive(Clone)]-/// One named part of an offline legacy kit.pub struct LegacyKitPart {- /// One-based part index encoded in the recovery sheet.pub index: u8,- /// Human-readable part holder/storage name.pub name: String,}@@ -309,9 +255,7 @@ impl From<ente_contacts::LegacyKitPart> for LegacyKitPart {#[frb]#[derive(Clone)]-/// Decrypted owner metadata for an offline legacy kit.pub struct LegacyKitMetadata {- /// Named recovery parts.pub parts: Vec<LegacyKitPart>,}@@ -325,23 +269,14 @@ impl From<ente_contacts::LegacyKitMetadata> for LegacyKitMetadata {#[frb]#[derive(Clone)]-/// Offline legacy kit record visible to the owner.pub struct LegacyKit {- /// Stable kit id.pub id: String,- /// Split variant.pub variant: LegacyKitVariant,- /// Configured notice period in hours.pub notice_period_in_hours: i32,- /// Public URL of the legacy recovery web app for this server.pub legacy_url: String,- /// Decrypted owner metadata.pub metadata: LegacyKitMetadata,- /// Kit creation timestamp.pub created_at: i64,- /// Kit update timestamp.pub updated_at: i64,- /// Active owner-visible recovery session, if any.pub active_recovery_session: Option<LegacyKitRecoverySession>,}@@ -362,21 +297,13 @@ impl From<ente_contacts::LegacyKit> for LegacyKit {#[frb]#[derive(Clone)]-/// One offline legacy kit recovery share to encode into a recovery sheet.pub struct LegacyKitShare {- /// Payload version.pub payload_version: u8,- /// Split variant.pub variant: LegacyKitVariant,- /// Kit id.pub kit_id: String,- /// One-based share index.pub share_index: u8,- /// Encoded share bytes.pub share: String,- /// Share checksum.pub checksum: String,- /// Human-readable part name.pub part_name: String,}@@ -396,11 +323,8 @@ impl From<ente_contacts::LegacyKitShare> for LegacyKitShare {#[frb]#[derive(Clone)]-/// Result of creating an offline legacy kit.pub struct LegacyKitCreateResult {- /// Created kit record.pub kit: LegacyKit,- /// Recovery shares that must be exported immediately.pub shares: Vec<LegacyKitShare>,}@@ -415,11 +339,8 @@ impl From<ente_contacts::LegacyKitCreateResult> for LegacyKitCreateResult {#[frb]#[derive(Clone)]-/// Source used to obtain the root contact key during open.pub enum RootKeySource {- /// Reused the caller-provided cached wrapped root key.Cache,- /// Opened without a cached wrapped root key; Rust will resolve it lazily.Unresolved,}@@ -434,9 +355,7 @@ impl From<ente_contacts::RootKeySource> for RootKeySource {#[frb]#[derive(Clone, Copy)]-/// Attachment types supported by the contacts subsystem.pub enum AttachmentType {- /// Current contact profile picture.ProfilePicture,}@@ -449,46 +368,31 @@ impl From<AttachmentType> for ente_contacts::AttachmentType {}#[frb]-/// Input required to open an account-scoped contacts context.pub struct OpenContactsCtxInput {- /// Base Ente API URL.pub base_url: String,- /// Auth token for Ente API requests.pub auth_token: String,- /// Logged-in owner user id.pub user_id: i64,- /// Logged-in account key used to unwrap or create the root contact key.pub master_key: Vec<u8>,- /// Optional cached wrapped root key for the current user.pub cached_wrapped_root_contact_key: Option<WrappedRootContactKey>,- /// Optional user agent to send to Ente API endpoints.pub user_agent: Option<String>,- /// Optional client package header to send to Ente API endpoints.pub client_package: Option<String>,- /// Optional client version header to send to Ente API endpoints.pub client_version: Option<String>,}#[frb]-/// Result returned when opening a contacts context.pub struct OpenContactsCtxResult {- /// Opaque contacts context bound to the current account/session.pub ctx: ContactsCtx,- /// Current wrapped root key that the caller may persist, if already resolved.pub wrapped_root_contact_key: Option<WrappedRootContactKey>,- /// State of the root key during open.pub root_key_source: RootKeySource,}#[frb(opaque)]#[derive(Clone)]-/// Opaque account-scoped contacts context exposed to Flutter.pub struct ContactsCtx {inner: Arc<ente_contacts::ContactsCtx>,}#[frb]-/// Open a contacts context for the current account.pub async fn open_contacts_ctx(input: OpenContactsCtxInput,) -> Result<OpenContactsCtxResult, ContactsError> {@@ -516,25 +420,21 @@ pub async fn open_contacts_ctx(impl ContactsCtx {#[frb(sync)]- /// Return the owner user id for this contacts context.pub fn user_id(&self) -> i64 {self.inner.user_id()}- /// Replace the auth token used for subsequent API requests.pub fn update_auth_token(&self, auth_token: String) {self.inner.update_auth_token(auth_token);}#[frb(sync)]- /// Return the current wrapped root key for caller-managed persistence, if resolved.pub fn current_wrapped_root_contact_key(&self) -> Option<WrappedRootContactKey> {self.inner.current_wrapped_root_contact_key().map(Into::into)}- /// Create a contact for the referenced user.pub async fn create_contact(&self, data: ContactData) -> Result<ContactRecord, ContactsError> {self.inner.create_contact(&data.into())@@ -543,7 +443,6 @@ impl ContactsCtx {.map_err(Into::into)}- /// Fetch a single contact by id.pub async fn get_contact(&self, contact_id: String) -> Result<ContactRecord, ContactsError> {self.inner.get_contact(&contact_id)@@ -552,7 +451,6 @@ impl ContactsCtx {.map_err(Into::into)}- /// Fetch a contacts diff since the provided timestamp.pub async fn get_diff(&self,since_time: i64,@@ -565,7 +463,6 @@ impl ContactsCtx {.map_err(Into::into)}- /// Update the encrypted payload for an existing contact.pub async fn update_contact(&self,contact_id: String,@@ -578,7 +475,6 @@ impl ContactsCtx {.map_err(Into::into)}- /// Tombstone a contact by id.pub async fn delete_contact(&self, contact_id: String) -> Result<(), ContactsError> {self.inner.delete_contact(&contact_id)@@ -586,7 +482,6 @@ impl ContactsCtx {.map_err(Into::into)}- /// Encrypt and upload a new attachment for the contact.pub async fn set_attachment(&self,contact_id: String,@@ -600,7 +495,6 @@ impl ContactsCtx {.map_err(Into::into)}- /// Download an encrypted attachment by type and attachment id.pub async fn get_attachment_encrypted(&self,attachment_type: AttachmentType,@@ -612,7 +506,6 @@ impl ContactsCtx {.map_err(Into::into)}- /// Remove the current attachment for a contact and type.pub async fn delete_attachment(&self,contact_id: String,@@ -625,7 +518,6 @@ impl ContactsCtx {.map_err(Into::into)}- /// Encrypt and upload a new contact profile picture.pub async fn set_profile_picture(&self,contact_id: String,@@ -635,7 +527,6 @@ impl ContactsCtx {.await}- /// Download and decrypt the current contact profile picture.pub async fn get_profile_picture(&self, contact_id: String) -> Result<Vec<u8>, ContactsError> {self.inner.get_profile_picture(&contact_id)@@ -643,7 +534,6 @@ impl ContactsCtx {.map_err(Into::into)}- /// Remove the current contact profile picture.pub async fn delete_profile_picture(&self,contact_id: String,@@ -652,7 +542,6 @@ impl ContactsCtx {.await}- /// List owner-created offline legacy kits.pub async fn legacy_kits(&self) -> Result<Vec<LegacyKit>, ContactsError> {self.inner.legacy_kits()@@ -661,7 +550,6 @@ impl ContactsCtx {.map_err(Into::into)}- /// Create an offline legacy kit and return the printable recovery shares.pub async fn legacy_kit_create(&self,current_user_key_attrs: AccountKeyAttributes,@@ -685,7 +573,6 @@ impl ContactsCtx {.map_err(Into::into)}- /// Download the printable recovery shares for an existing offline legacy kit.pub async fn legacy_kit_download_shares(&self,kit_id: String,@@ -697,7 +584,6 @@ impl ContactsCtx {.map_err(Into::into)}- /// Fetch owner-visible active recovery session details for a legacy kit.pub async fn legacy_kit_recovery_session(&self,kit_id: String,@@ -709,7 +595,6 @@ impl ContactsCtx {.map_err(Into::into)}- /// Update the recovery wait time for a legacy kit.pub async fn legacy_kit_update_recovery_notice(&self,kit_id: String,@@ -721,7 +606,6 @@ impl ContactsCtx {.map_err(Into::into)}- /// Block the active recovery session for a legacy kit.pub async fn legacy_kit_block_recovery(&self, kit_id: String) -> Result<(), ContactsError> {self.inner.legacy_kit_block_recovery(&kit_id)@@ -729,7 +613,6 @@ impl ContactsCtx {.map_err(Into::into)}- /// Delete an offline legacy kit.pub async fn legacy_kit_delete(&self, kit_id: String) -> Result<(), ContactsError> {self.inner.legacy_kit_delete(&kit_id)diff --git a/rust/bindings/wasm/ente-wasm/src/auth.rs b/rust/bindings/wasm/ente-wasm/src/auth.rsindex 62730f3ff5..ad1fcba5f4 100644--- a/rust/bindings/wasm/ente-wasm/src/auth.rs+++ b/rust/bindings/wasm/ente-wasm/src/auth.rs@@ -1,33 +1,28 @@-//! WASM bindings for authentication and account crypto.-use ente_accounts::auth;use ente_core::b64;use serde_wasm_bindgen as swb;use wasm_bindgen::prelude::*;-/// Auth error.#[wasm_bindgen]-pub struct AuthError {+pub struct AccountsError {code: String,message: String,}#[wasm_bindgen]-impl AuthError {- /// A machine-readable error code.+impl AccountsError {#[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()}}-impl From<ente_accounts::Error> for AuthError {+impl From<ente_accounts::Error> for AccountsError {fn from(e: ente_accounts::Error) -> Self {use ente_accounts::Error as E;@@ -60,7 +55,7 @@ impl From<ente_accounts::Error> for AuthError {}}-impl From<swb::Error> for AuthError {+impl From<swb::Error> for AccountsError {fn from(e: swb::Error) -> Self {Self {code: "serde".to_string(),@@ -69,7 +64,6 @@ impl From<swb::Error> for AuthError {}}-/// SRP credentials derived from a password.#[wasm_bindgen]pub struct SrpCredentials {kek: String,@@ -78,20 +72,17 @@ pub struct SrpCredentials {#[wasm_bindgen]impl SrpCredentials {- /// Key-encryption-key (base64).#[wasm_bindgen(getter)]pub fn kek(&self) -> String {self.kek.clone()}- /// SRP login key (base64, 16 bytes).#[wasm_bindgen(getter)]pub fn login_key(&self) -> String {self.login_key.clone()}}-/// Decrypted secrets after successful authentication.#[wasm_bindgen]pub struct DecryptedSecrets {master_key: String,@@ -101,26 +92,22 @@ pub struct DecryptedSecrets {#[wasm_bindgen]impl DecryptedSecrets {- /// Master key (base64).#[wasm_bindgen(getter)]pub fn master_key(&self) -> String {self.master_key.clone()}- /// Secret key (base64).#[wasm_bindgen(getter)]pub fn secret_key(&self) -> String {self.secret_key.clone()}- /// Auth token (URL-safe base64).#[wasm_bindgen(getter)]pub fn token(&self) -> String {self.token.clone()}}-/// A generated KEK and its derivation parameters.#[wasm_bindgen]pub struct GeneratedKek {key: String,@@ -131,32 +118,27 @@ pub struct GeneratedKek {#[wasm_bindgen]impl GeneratedKek {- /// Derived KEK (base64).#[wasm_bindgen(getter)]pub fn key(&self) -> String {self.key.clone()}- /// Salt used for derivation (base64).#[wasm_bindgen(getter)]pub fn salt(&self) -> String {self.salt.clone()}- /// Argon2 memory limit in bytes.#[wasm_bindgen(getter)]pub fn mem_limit(&self) -> u32 {self.mem_limit}- /// Argon2 operations limit.#[wasm_bindgen(getter)]pub fn ops_limit(&self) -> u32 {self.ops_limit}}-/// SRP setup payload generated from a KEK.#[wasm_bindgen]pub struct GeneratedSrpSetup {srp_salt: String,@@ -166,34 +148,27 @@ pub struct GeneratedSrpSetup {#[wasm_bindgen]impl GeneratedSrpSetup {- /// SRP salt (base64).#[wasm_bindgen(getter)]pub fn srp_salt(&self) -> String {self.srp_salt.clone()}- /// SRP verifier (base64).#[wasm_bindgen(getter)]pub fn srp_verifier(&self) -> String {self.srp_verifier.clone()}- /// SRP login sub-key (base64, 16 bytes).#[wasm_bindgen(getter)]pub fn login_sub_key(&self) -> String {self.login_sub_key.clone()}}-/// Derive SRP credentials (KEK + login key) from a password and SRP attributes.-///-/// `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,srp_attrs: JsValue,-) -> Result<SrpCredentials, AuthError> {+) -> Result<SrpCredentials, AccountsError> {let srp_attrs: auth::SrpAttributes = swb::from_value(srp_attrs)?;let creds = auth::derive_srp_credentials(password, &srp_attrs)?;@@ -204,23 +179,19 @@ pub fn auth_derive_srp_credentials(})}-/// Derive the key-encryption-key (KEK) from password and KEK parameters.-///-/// Returns the KEK as base64.#[wasm_bindgen]pub fn auth_derive_kek(password: &str,kek_salt_b64: &str,mem_limit: u32,ops_limit: u32,-) -> Result<String, AuthError> {+) -> Result<String, AccountsError> {let kek = auth::derive_kek(password, kek_salt_b64, mem_limit, ops_limit)?;Ok(b64::encode(&kek))}-/// Generate a KEK using the current sensitive web derivation policy.#[wasm_bindgen]-pub fn auth_generate_sensitive_kek(password: &str) -> Result<GeneratedKek, AuthError> {+pub fn auth_generate_sensitive_kek(password: &str) -> Result<GeneratedKek, AccountsError> {let generated = auth::generate_sensitive_kek(password)?;Ok(GeneratedKek {key: b64::encode(&generated.key),@@ -230,9 +201,8 @@ pub fn auth_generate_sensitive_kek(password: &str) -> Result<GeneratedKek, AuthE})}-/// Generate a KEK using the current interactive web derivation policy.#[wasm_bindgen]-pub fn auth_generate_interactive_kek(password: &str) -> Result<GeneratedKek, AuthError> {+pub fn auth_generate_interactive_kek(password: &str) -> Result<GeneratedKek, AccountsError> {let generated = auth::generate_interactive_kek(password)?;Ok(GeneratedKek {key: b64::encode(&generated.key),@@ -242,13 +212,12 @@ pub fn auth_generate_interactive_kek(password: &str) -> Result<GeneratedKek, Aut})}-/// Generate the SRP setup payload for a given KEK and SRP user ID.#[wasm_bindgen]pub fn auth_generate_srp_setup(kek_b64: &str,srp_user_id: &str,-) -> Result<GeneratedSrpSetup, AuthError> {- let kek = b64::decode(kek_b64).map_err(|e| AuthError {+) -> Result<GeneratedSrpSetup, AccountsError> {+ let kek = b64::decode(kek_b64).map_err(|e| AccountsError {code: "decode".to_string(),message: format!("kek: {}", e),})?;@@ -261,30 +230,24 @@ pub fn auth_generate_srp_setup(})}-/// Convert a recovery key mnemonic or legacy hex string into base64 bytes.#[wasm_bindgen]-pub fn auth_recovery_key_from_mnemonic_or_hex(input: &str) -> Result<String, AuthError> {+pub fn auth_recovery_key_from_mnemonic_or_hex(input: &str) -> Result<String, AccountsError> {let recovery_key = auth::recovery_key_from_mnemonic_or_hex(input)?;Ok(b64::encode(&recovery_key))}-/// Convert a base64-encoded recovery key into its English mnemonic.#[wasm_bindgen]-pub fn auth_recovery_key_to_mnemonic(recovery_key_b64: &str) -> Result<String, AuthError> {+pub fn auth_recovery_key_to_mnemonic(recovery_key_b64: &str) -> Result<String, AccountsError> {auth::recovery_key_to_mnemonic(recovery_key_b64).map_err(Into::into)}-/// Decrypt the master key, secret key and auth token.-///-/// `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,key_attrs: JsValue,encrypted_token_b64: &str,-) -> Result<DecryptedSecrets, AuthError> {- let kek = b64::decode(kek_b64).map_err(|e| AuthError {+) -> Result<DecryptedSecrets, AccountsError> {+ let kek = b64::decode(kek_b64).map_err(|e| AccountsError {code: "decode".to_string(),message: format!("kek: {}", e),})?;@@ -300,7 +263,6 @@ pub fn auth_decrypt_secrets(})}-/// Result of decrypting only the master key and secret key.#[wasm_bindgen]pub struct DecryptedKeys {master_key: String,@@ -309,28 +271,23 @@ pub struct DecryptedKeys {#[wasm_bindgen]impl DecryptedKeys {- /// Master key (base64).#[wasm_bindgen(getter)]pub fn master_key(&self) -> String {self.master_key.clone()}- /// Secret key (base64).#[wasm_bindgen(getter)]pub fn secret_key(&self) -> String {self.secret_key.clone()}}-/// Decrypt only the master key and secret key.-///-/// Useful when the auth token is obtained separately.#[wasm_bindgen]pub fn auth_decrypt_keys_only(kek_b64: &str,key_attrs: JsValue,-) -> Result<DecryptedKeys, AuthError> {- let kek = b64::decode(kek_b64).map_err(|e| AuthError {+) -> Result<DecryptedKeys, AccountsError> {+ let kek = b64::decode(kek_b64).map_err(|e| AccountsError {code: "decode".to_string(),message: format!("kek: {}", e),})?;@@ -344,13 +301,6 @@ pub fn auth_decrypt_keys_only(})}-/// SRP (Secure Remote Password) session.-///-/// This is a small state machine:-/// - Create session-/// - Send `public_a()` to server-/// - Receive `srpB` from server, compute `srpM1`-/// - Receive `srpM2` from server, verify#[wasm_bindgen]pub struct SrpSession {inner: auth::SrpSession,@@ -358,15 +308,12 @@ pub struct SrpSession {#[wasm_bindgen]impl SrpSession {- /// Create a new SRP session.- ///- /// All inputs are base64 strings except `srp_user_id`.#[wasm_bindgen(constructor)]pub fn new(srp_user_id: &str,srp_salt_b64: &str,login_key_b64: &str,- ) -> Result<SrpSession, AuthError> {+ ) -> Result<SrpSession, AccountsError> {let srp_salt = b64::decode(srp_salt_b64).map_err(|e| ente_accounts::Error::Decode(format!("srp_salt: {}", e)))?;let login_key = b64::decode(login_key_b64)@@ -376,21 +323,18 @@ impl SrpSession {Ok(Self { inner })}- /// Get the public ephemeral value A as base64.pub fn public_a(&self) -> String {b64::encode(&self.inner.public_a())}- /// Compute the client proof M1 from the server's public value B (base64).- pub fn compute_m1(&mut self, srp_b_b64: &str) -> Result<String, AuthError> {+ pub fn compute_m1(&mut self, srp_b_b64: &str) -> Result<String, AccountsError> {let srp_b = b64::decode(srp_b_b64).map_err(|e| ente_accounts::Error::Decode(format!("srpB: {}", e)))?;let m1 = self.inner.compute_m1(&srp_b)?;Ok(b64::encode(&m1))}- /// Verify the server proof M2 (base64).- pub fn verify_m2(&self, srp_m2_b64: &str) -> Result<(), AuthError> {+ pub fn verify_m2(&self, srp_m2_b64: &str) -> Result<(), AccountsError> {let srp_m2 = b64::decode(srp_m2_b64).map_err(|e| ente_accounts::Error::Decode(format!("srpM2: {}", e)))?;self.inner.verify_m2(&srp_m2)?;diff --git a/rust/bindings/wasm/ente-wasm/src/contacts.rs b/rust/bindings/wasm/ente-wasm/src/contacts.rsindex 15249f88df..060255b400 100644--- a/rust/bindings/wasm/ente-wasm/src/contacts.rs+++ b/rust/bindings/wasm/ente-wasm/src/contacts.rs@@ -1,5 +1,3 @@-//! WASM bindings for contacts sync and attachment reads.-use ente_accounts::auth::KeyAttributes;use ente_contacts::{ContactsCtx, LegacyContactState, OpenContactsCtxInput, RootKeySource, WrappedRootContactKey,@@ -43,8 +41,8 @@ impl From<ContactsError> for JsValue {}}-impl From<ente_contacts::ContactsError> for ContactsError {- fn from(e: ente_contacts::ContactsError) -> Self {+impl From<ente_contacts::Error> for ContactsError {+ fn from(e: ente_contacts::Error) -> Self {use ente_contacts::ErrorKind as K;let message = ente_core::error::chain(&e);match e.kind() {@@ -122,7 +120,6 @@ impl From<ente_contacts::ContactRecord> for ContactRecordJs {}}-/// Open contacts context for web.#[wasm_bindgen]pub async fn contacts_open_ctx(input: JsValue) -> Result<JsValue, ContactsError> {let input: OpenContactsCtxJsInput = swb::from_value(input)?;@@ -168,7 +165,6 @@ pub async fn contacts_open_ctx(input: JsValue) -> Result<JsValue, ContactsError>Ok(output.into())}-/// Handle to an open contacts context.#[wasm_bindgen]pub struct ContactsCtxHandle {inner: ContactsCtx,@@ -176,17 +172,14 @@ pub struct ContactsCtxHandle {#[wasm_bindgen]impl ContactsCtxHandle {- /// Update auth token without rebuilding the contacts context.pub fn update_auth_token(&self, auth_token: String) {self.inner.update_auth_token(auth_token);}- /// Return the wrapped root key currently held by this context, if resolved.pub fn current_wrapped_root_contact_key(&self) -> Result<JsValue, ContactsError> {swb::to_value(&self.inner.current_wrapped_root_contact_key()).map_err(Into::into)}- /// Pull a diff page of contacts.pub async fn get_diff(&self, since_time: i64, limit: u16) -> Result<JsValue, ContactsError> {let diff: Vec<ContactRecordJs> = self.inner@@ -198,7 +191,6 @@ impl ContactsCtxHandle {swb::to_value(&diff).map_err(Into::into)}- /// Fetch and decrypt the profile picture bytes for a contact.pub async fn get_profile_picture(&self, contact_id: &str) -> Result<Vec<u8>, ContactsError> {self.inner.get_profile_picture(contact_id)@@ -206,26 +198,22 @@ impl ContactsCtxHandle {.map_err(Into::into)}- /// Fetch legacy/emergency contact info for the current user.pub async fn legacy_get_info(&self) -> Result<JsValue, ContactsError> {let info = self.inner.legacy_info().await?;swb::to_value(&info).map_err(Into::into)}- /// Lookup a user's public key by email for legacy verify/add flows.pub async fn legacy_public_key(&self, email: String) -> Result<JsValue, ContactsError> {let public_key = self.inner.legacy_public_key(&email).await?;swb::to_value(&public_key).map_err(Into::into)}- /// Generate the mnemonic-style verification ID for a public key.pub fn legacy_verification_id(&self, public_key_b64: String) -> Result<String, ContactsError> {self.inner.legacy_verification_id(&public_key_b64).map_err(Into::into)}- /// Add a trusted legacy contact after sealing the current user's recovery key in Rust.pub async fn legacy_add_contact(&self,email: String,@@ -239,7 +227,6 @@ impl ContactsCtxHandle {.map_err(Into::into)}- /// Update a legacy contact relationship state.pub async fn legacy_update_contact(&self,user_id: i64,@@ -253,7 +240,6 @@ impl ContactsCtxHandle {.map_err(Into::into)}- /// Update the notice period for an existing trusted contact.pub async fn legacy_update_recovery_notice(&self,emergency_contact_id: i64,@@ -265,7 +251,6 @@ impl ContactsCtxHandle {.map_err(Into::into)}- /// Start a recovery flow as the trusted contact.pub async fn legacy_start_recovery(&self,user_id: i64,@@ -277,7 +262,6 @@ impl ContactsCtxHandle {.map_err(Into::into)}- /// Stop a recovery flow as the trusted contact.pub async fn legacy_stop_recovery(&self,recovery_id: String,@@ -290,7 +274,6 @@ impl ContactsCtxHandle {.map_err(Into::into)}- /// Reject a recovery flow as the account owner.pub async fn legacy_reject_recovery(&self,recovery_id: String,@@ -303,7 +286,6 @@ impl ContactsCtxHandle {.map_err(Into::into)}- /// Approve a recovery flow as the account owner.pub async fn legacy_approve_recovery(&self,recovery_id: String,@@ -316,7 +298,6 @@ impl ContactsCtxHandle {.map_err(Into::into)}- /// Fetch and decrypt the recovery payload for a ready session.pub async fn legacy_recovery_bundle(&self,recovery_id: String,@@ -334,7 +315,6 @@ impl ContactsCtxHandle {.map_err(Into::into)}- /// Complete the legacy password reset flow fully in Rust.pub async fn legacy_change_password(&self,recovery_id: String,diff --git a/rust/crates/contacts/src/client.rs b/rust/crates/contacts/src/client.rsindex 4042b3b3fb..d3fdec0bd4 100644--- a/rust/crates/contacts/src/client.rs+++ b/rust/crates/contacts/src/client.rs@@ -8,7 +8,7 @@ use sha2::{Digest, Sha256};use uuid::Uuid;use crate::crypto as contacts_crypto;-use crate::error::{ContactsError, Result};+use crate::error::{Error, Result};use crate::legacy_kit::{create_legacy_kit_request, decode_download_content, decode_legacy_kit_record,validate_notice_period,@@ -163,9 +163,9 @@ impl ContactsCtx {.root_contact_key.read().expect("root contact key lock poisoned");- let root_contact_key = root_contact_key_guard.as_ref().ok_or_else(|| {- ContactsError::InvalidInput("contacts root key is unresolved".into())- })?;+ let root_contact_key = root_contact_key_guard+ .as_ref()+ .ok_or_else(|| Error::InvalidInput("contacts root key is unresolved".into()))?;contacts_crypto::wrap_contact_key(&contact_key, root_contact_key)?};let encrypted_data = contacts_crypto::encrypt_contact_data(data, &contact_key)?;@@ -244,15 +244,15 @@ impl ContactsCtx {let encrypted_key = current.encrypted_key.as_deref()- .ok_or(ContactsError::MissingEncryptedKey)?;+ .ok_or(Error::MissingEncryptedKey)?;let contact_key = {let root_contact_key_guard = self.root_contact_key.read().expect("root contact key lock poisoned");- let root_contact_key = root_contact_key_guard.as_ref().ok_or_else(|| {- ContactsError::InvalidInput("contacts root key is unresolved".into())- })?;+ let root_contact_key = root_contact_key_guard+ .as_ref()+ .ok_or_else(|| Error::InvalidInput("contacts root key is unresolved".into()))?;contacts_crypto::unwrap_contact_key(encrypted_key, root_contact_key)?};let encrypted_data = contacts_crypto::encrypt_contact_data(data, &contact_key)?;@@ -301,15 +301,15 @@ impl ContactsCtx {let encrypted_key = current.encrypted_key.as_deref()- .ok_or(ContactsError::MissingEncryptedKey)?;+ .ok_or(Error::MissingEncryptedKey)?;let contact_key = {let root_contact_key_guard = self.root_contact_key.read().expect("root contact key lock poisoned");- let root_contact_key = root_contact_key_guard.as_ref().ok_or_else(|| {- ContactsError::InvalidInput("contacts root key is unresolved".into())- })?;+ let root_contact_key = root_contact_key_guard+ .as_ref()+ .ok_or_else(|| Error::InvalidInput("contacts root key is unresolved".into()))?;contacts_crypto::unwrap_contact_key(encrypted_key, root_contact_key)?};let encrypted_attachment =@@ -398,22 +398,22 @@ impl ContactsCtx {.json::<ContactEntityResponse>().await?;if current.is_deleted || current.profile_picture_attachment_id.is_none() {- return Err(ContactsError::ProfilePictureNotFound);+ return Err(Error::ProfilePictureNotFound);}self.ensure_confirmed_root_contact_key().await?;let encrypted_key = current.encrypted_key.as_deref()- .ok_or(ContactsError::MissingEncryptedKey)?;+ .ok_or(Error::MissingEncryptedKey)?;let contact_key = {let root_contact_key_guard = self.root_contact_key.read().expect("root contact key lock poisoned");- let root_contact_key = root_contact_key_guard.as_ref().ok_or_else(|| {- ContactsError::InvalidInput("contacts root key is unresolved".into())- })?;+ let root_contact_key = root_contact_key_guard+ .as_ref()+ .ok_or_else(|| Error::InvalidInput("contacts root key is unresolved".into()))?;contacts_crypto::unwrap_contact_key(encrypted_key, root_contact_key)?};let encrypted_picture = self@@ -502,7 +502,7 @@ impl ContactsCtx {let public_key = self.legacy_public_key(email).await?- .ok_or_else(|| ContactsError::InvalidInput("legacy contact is not on Ente".into()))?;+ .ok_or_else(|| Error::InvalidInput("legacy contact is not on Ente".into()))?;let recovery_key = self.current_recovery_key(current_user_key_attrs)?;let recipient_public_key = b64::decode(&public_key)?;let encrypted_key = sealed::seal(@@ -790,7 +790,7 @@ impl ContactsCtx {.await?;if response.status() == 400 {return if response.text().await?.contains("active recovery session") {- Err(ContactsError::ActiveRecoverySession)+ Err(Error::ActiveRecoverySession)} else {Err(http::Error::Http {status: 400,@@ -841,18 +841,18 @@ impl ContactsCtx {let encrypted_key = entity.encrypted_key.as_deref()- .ok_or(ContactsError::MissingEncryptedKey)?;+ .ok_or(Error::MissingEncryptedKey)?;let encrypted_data = entity.encrypted_data.as_deref()- .ok_or(ContactsError::MissingEncryptedData)?;+ .ok_or(Error::MissingEncryptedData)?;let root_contact_key_guard = self.root_contact_key.read().expect("root contact key lock poisoned");let root_contact_key = root_contact_key_guard.as_ref()- .ok_or_else(|| ContactsError::InvalidInput("contacts root key is unresolved".into()))?;+ .ok_or_else(|| Error::InvalidInput("contacts root key is unresolved".into()))?;let contact_key = contacts_crypto::unwrap_contact_key(encrypted_key, root_contact_key)?;let data = contacts_crypto::decrypt_contact_data(encrypted_data, &contact_key)?;@@ -1026,7 +1026,7 @@ fn decrypt_master_key_with_recovery_key(.master_key_encrypted_with_recovery_key.as_ref().ok_or_else(|| {- ContactsError::InvalidInput(+ Error::InvalidInput("target key attributes missing masterKeyEncryptedWithRecoveryKey".into(),)})?;@@ -1034,9 +1034,7 @@ fn decrypt_master_key_with_recovery_key(.master_key_decryption_nonce.as_ref().ok_or_else(|| {- ContactsError::InvalidInput(- "target key attributes missing masterKeyDecryptionNonce".into(),- )+ Error::InvalidInput("target key attributes missing masterKeyDecryptionNonce".into())})?;let encrypted_master_key = b64::decode(encrypted_master_key)?;let master_key_nonce = b64::decode(master_key_nonce)?;diff --git a/rust/crates/contacts/src/crypto.rs b/rust/crates/contacts/src/crypto.rsindex 7abca723c7..7bf73e98fc 100644--- a/rust/crates/contacts/src/crypto.rs+++ b/rust/crates/contacts/src/crypto.rs@@ -3,7 +3,7 @@ use md5::{Digest, Md5};use ente_core::b64;use ente_core::crypto::{self, blob, secretbox};-use crate::error::{ContactsError, Result};+use crate::error::{Error, Result};use crate::models::{ContactData, WrappedRootContactKey};pub fn encrypt_root_contact_key(@@ -78,12 +78,12 @@ pub fn content_md5_base64(bytes: &[u8]) -> String {pub fn validate_contact_data(data: &ContactData) -> Result<()> {if data.contact_user_id <= 0 {- return Err(ContactsError::InvalidInput(+ return Err(Error::InvalidInput("contact_user_id must be greater than 0".to_string(),));}if data.name.trim().is_empty() {- return Err(ContactsError::InvalidInput("name is required".to_string()));+ return Err(Error::InvalidInput("name is required".to_string()));}Ok(())}diff --git a/rust/crates/contacts/src/error.rs b/rust/crates/contacts/src/error.rsindex 0f7226e598..9ea5346598 100644--- a/rust/crates/contacts/src/error.rs+++ b/rust/crates/contacts/src/error.rs@@ -2,7 +2,7 @@ use ente_core::{b64, crypto, http};use thiserror::Error;#[derive(Debug, Error)]-pub enum ContactsError {+pub enum Error {#[error(transparent)]Http(#[from] http::Error),@@ -45,30 +45,29 @@ pub enum ErrorKind {ActiveRecoverySession,}-impl ContactsError {+impl Error {pub fn kind(&self) -> ErrorKind {match self {- ContactsError::Http(http::Error::Network(_)) => ErrorKind::Network,- ContactsError::Http(http::Error::Parse(_)) => ErrorKind::Parse,- ContactsError::Http(_) => ErrorKind::Http,- ContactsError::Crypto(_) => ErrorKind::Crypto,- ContactsError::Base64Decode(_) => ErrorKind::Crypto,- ContactsError::Accounts(_) => ErrorKind::Auth,- ContactsError::InvalidInput(_) => ErrorKind::InvalidInput,- ContactsError::MissingEncryptedData => ErrorKind::MissingEncryptedData,- ContactsError::MissingEncryptedKey => ErrorKind::MissingEncryptedKey,- ContactsError::ProfilePictureNotFound => ErrorKind::ProfilePictureNotFound,- ContactsError::ActiveRecoverySession => ErrorKind::ActiveRecoverySession,+ Error::Http(http::Error::Network(_)) => ErrorKind::Network,+ Error::Http(http::Error::Parse(_)) => ErrorKind::Parse,+ Error::Http(_) => ErrorKind::Http,+ Error::Crypto(_) => ErrorKind::Crypto,+ Error::Base64Decode(_) => ErrorKind::Crypto,+ Error::Accounts(_) => ErrorKind::Auth,+ Error::InvalidInput(_) => ErrorKind::InvalidInput,+ Error::MissingEncryptedData => ErrorKind::MissingEncryptedData,+ Error::MissingEncryptedKey => ErrorKind::MissingEncryptedKey,+ Error::ProfilePictureNotFound => ErrorKind::ProfilePictureNotFound,+ Error::ActiveRecoverySession => ErrorKind::ActiveRecoverySession,}}- /// The HTTP status, when the server answered with one.pub fn status(&self) -> Option<u16> {match self {- ContactsError::Http(error) => error.status_code(),+ Error::Http(error) => error.status_code(),_ => None,}}}-pub type Result<T> = std::result::Result<T, ContactsError>;+pub type Result<T> = std::result::Result<T, Error>;diff --git a/rust/crates/contacts/src/legacy_kit/mod.rs b/rust/crates/contacts/src/legacy_kit/mod.rsindex aceda0ef72..4bb88a3c67 100644--- a/rust/crates/contacts/src/legacy_kit/mod.rs+++ b/rust/crates/contacts/src/legacy_kit/mod.rs@@ -12,7 +12,7 @@ use ente_core::{use uuid::Uuid;use crate::{- ContactsError, Result,+ Error, Result,legacy_kit_models::{LEGACY_KIT_PAYLOAD_VERSION, LegacyKit, LegacyKitRecoveryBundle, LegacyKitRecoverySession,LegacyKitShare, LegacyKitVariant,@@ -41,7 +41,7 @@ pub(crate) fn create_legacy_kit_request() -> Result<(CreateLegacyKitRequest, Vec<LegacyKitShare>)> {validate_notice_period(notice_period_in_hours)?;if part_names.iter().any(|name| name.trim().is_empty()) {- return Err(ContactsError::InvalidInput(+ return Err(Error::InvalidInput("legacy kit part names must be non-empty".into(),));}@@ -175,7 +175,7 @@ impl LegacyKitRecoveryClient {email: Option<&str>,) -> Result<LegacyKitRecoveryHandle> {let first_share = shares.first().ok_or_else(|| {- ContactsError::InvalidInput("at least two legacy kit shares are required".into())+ Error::InvalidInput("at least two legacy kit shares are required".into())})?;let challenge = self.api@@ -200,7 +200,7 @@ impl LegacyKitRecoveryClient {) -> Result<LegacyKitRecoveryHandle> {let kit_secret = reconstruct_secret_2_of_3(shares)?;let first_share = shares.first().ok_or_else(|| {- ContactsError::InvalidInput("at least two legacy kit shares are required".into())+ Error::InvalidInput("at least two legacy kit shares are required".into())})?;let used_part_indexes = used_part_indexes(shares)?;self.open_with_kit_secret(@@ -355,7 +355,7 @@ pub(crate) fn validate_notice_period(hours: i32) -> Result<()> {if LEGACY_KIT_NOTICE_OPTIONS.contains(&hours) {Ok(())} else {- Err(ContactsError::InvalidInput(+ Err(Error::InvalidInput("legacy kit notice period must be one of 0, 24, 168, 360, 720 hours".into(),))}@@ -363,12 +363,12 @@ pub(crate) fn validate_notice_period(hours: i32) -> Result<()> {fn derive_kit_enc_key(kit_secret: &[u8]) -> Result<SecretVec> {let kit_key = crypto::Key::try_from_slice(kit_secret)?;- kdf::derive_subkey(&kit_key, 32, 1, b"lgkenc01").map_err(ContactsError::from)+ kdf::derive_subkey(&kit_key, 32, 1, b"lgkenc01").map_err(Error::from)}fn derive_kit_auth_keypair(kit_secret: &[u8]) -> Result<(crypto::PublicKey, crypto::SecretKey)> {let kit_key = crypto::Key::try_from_slice(kit_secret)?;- let seed = kdf::derive_subkey(&kit_key, 32, 2, b"lgkauth1").map_err(ContactsError::from)?;+ let seed = kdf::derive_subkey(&kit_key, 32, 2, b"lgkauth1").map_err(Error::from)?;let sk = crypto::SecretKey::from_seed(seed.as_ref())?;Ok((sk.public_key(), sk))}@@ -381,7 +381,7 @@ fn decrypt_challenge(let encrypted_challenge = b64::decode(encrypted_challenge_b64)?;let plaintext = sealed::open(&encrypted_challenge, auth_public_key, auth_secret_key)?;String::from_utf8(plaintext).map_err(|error| {- ContactsError::InvalidInput(format!("legacy kit challenge was not valid UTF-8: {error}"))+ Error::InvalidInput(format!("legacy kit challenge was not valid UTF-8: {error}"))})}@@ -393,7 +393,7 @@ fn decrypt_master_key_with_recovery_key(.master_key_encrypted_with_recovery_key.as_ref().ok_or_else(|| {- ContactsError::InvalidInput(+ Error::InvalidInput("target key attributes missing masterKeyEncryptedWithRecoveryKey".into(),)})?;@@ -401,9 +401,7 @@ fn decrypt_master_key_with_recovery_key(.master_key_decryption_nonce.as_ref().ok_or_else(|| {- ContactsError::InvalidInput(- "target key attributes missing masterKeyDecryptionNonce".into(),- )+ Error::InvalidInput("target key attributes missing masterKeyDecryptionNonce".into())})?;let encrypted_master_key = b64::decode(encrypted_master_key)?;let master_key_nonce = b64::decode(master_key_nonce)?;diff --git a/rust/crates/contacts/src/legacy_kit/owner_blob.rs b/rust/crates/contacts/src/legacy_kit/owner_blob.rsindex 14c925cc34..ca1a0d5809 100644--- a/rust/crates/contacts/src/legacy_kit/owner_blob.rs+++ b/rust/crates/contacts/src/legacy_kit/owner_blob.rs@@ -3,7 +3,7 @@ use ente_core::crypto::{self, secretbox};use serde::{Deserialize, Serialize, de::DeserializeOwned};use crate::{- ContactsError, Result,+ Error, Result,legacy_kit_models::{LegacyKitMetadata, LegacyKitPart, LegacyKitShare},};@@ -50,7 +50,7 @@ pub(super) fn decrypt_owner_blob(fn encrypt_blob<T: Serialize>(payload: &T, master_key: &[u8], label: &str) -> Result<String> {let payload = serde_json::to_vec(payload).map_err(|error| {- ContactsError::InvalidInput(format!("failed to encode {label} payload: {error}"))+ Error::InvalidInput(format!("failed to encode {label} payload: {error}"))})?;let encrypted =secretbox::encrypt_combined(&payload, &crypto::Key::try_from_slice(master_key)?);@@ -65,9 +65,8 @@ fn decrypt_blob<T: DeserializeOwned>(let encrypted_blob = b64::decode(encrypted_blob_b64)?;let plaintext =secretbox::decrypt_combined(&encrypted_blob, &crypto::Key::try_from_slice(master_key)?)?;- serde_json::from_slice(&plaintext).map_err(|error| {- ContactsError::InvalidInput(format!("failed to decode {label} payload: {error}"))- })+ serde_json::from_slice(&plaintext)+ .map_err(|error| Error::InvalidInput(format!("failed to decode {label} payload: {error}")))}pub(super) fn metadata_from_owner_blob(owner_blob: &StoredOwnerBlob) -> LegacyKitMetadata {diff --git a/rust/crates/contacts/src/legacy_kit/shares.rs b/rust/crates/contacts/src/legacy_kit/shares.rsindex 571c13d60d..386eba086d 100644--- a/rust/crates/contacts/src/legacy_kit/shares.rs+++ b/rust/crates/contacts/src/legacy_kit/shares.rs@@ -3,7 +3,7 @@ use ente_core::crypto::{self, SecretVec};use sha2::{Digest, Sha256};use crate::{- ContactsError, Result,+ Error, Result,legacy_kit_models::{LEGACY_KIT_PAYLOAD_VERSION, LegacyKitShare, LegacyKitVariant},};@@ -23,7 +23,7 @@ pub(super) fn checksum(pub(super) fn split_secret_2_of_3(secret: &[u8]) -> Result<Vec<Vec<u8>>> {if secret.len() != 32 {- return Err(ContactsError::InvalidInput(+ return Err(Error::InvalidInput("legacy kit secret must be 32 bytes".into(),));}@@ -43,7 +43,7 @@ pub(super) fn split_secret_2_of_3(secret: &[u8]) -> Result<Vec<Vec<u8>>> {pub(super) fn reconstruct_secret_2_of_3(shares: &[LegacyKitShare]) -> Result<SecretVec> {if shares.len() < 2 {- return Err(ContactsError::InvalidInput(+ return Err(Error::InvalidInput("at least two legacy kit shares are required".into(),));}@@ -52,27 +52,27 @@ pub(super) fn reconstruct_secret_2_of_3(shares: &[LegacyKitShare]) -> Result<Secvalidate_share_header(first)?;validate_share_header(second)?;if first.payload_version != second.payload_version {- return Err(ContactsError::InvalidInput(+ return Err(Error::InvalidInput("legacy kit share payload version mismatch".into(),));}if first.variant != second.variant {- return Err(ContactsError::InvalidInput(+ return Err(Error::InvalidInput("legacy kit share variant mismatch".into(),));}if first.kit_id != second.kit_id {- return Err(ContactsError::InvalidInput(+ return Err(Error::InvalidInput("legacy kit shares must belong to the same kit".into(),));}if first.checksum != second.checksum {- return Err(ContactsError::InvalidInput(+ return Err(Error::InvalidInput("legacy kit share checksum mismatch".into(),));}if first.share_index == second.share_index {- return Err(ContactsError::InvalidInput(+ return Err(Error::InvalidInput("legacy kit shares must use different indices".into(),));}@@ -80,7 +80,7 @@ pub(super) fn reconstruct_secret_2_of_3(shares: &[LegacyKitShare]) -> Result<Seclet y1 = b64::decode(&first.share)?;let y2 = b64::decode(&second.share)?;if y1.len() != 32 || y2.len() != 32 {- return Err(ContactsError::InvalidInput(+ return Err(Error::InvalidInput("legacy kit shares must be 32 bytes".into(),));}@@ -89,7 +89,7 @@ pub(super) fn reconstruct_secret_2_of_3(shares: &[LegacyKitShare]) -> Result<Seclet x2 = second.share_index;let denom = x1 ^ x2;if denom == 0 {- return Err(ContactsError::InvalidInput(+ return Err(Error::InvalidInput("legacy kit shares must use different x coordinates".into(),));}@@ -100,7 +100,7 @@ pub(super) fn reconstruct_secret_2_of_3(shares: &[LegacyKitShare]) -> Result<Sec}let expected = checksum(first.payload_version, first.variant, &first.kit_id, &secret);if expected != first.checksum {- return Err(ContactsError::InvalidInput(+ return Err(Error::InvalidInput("legacy kit shares failed checksum verification".into(),));}@@ -108,12 +108,12 @@ pub(super) fn reconstruct_secret_2_of_3(shares: &[LegacyKitShare]) -> Result<Sec}pub(super) fn used_part_indexes(shares: &[LegacyKitShare]) -> Result<Vec<u8>> {- let first = shares.first().ok_or_else(|| {- ContactsError::InvalidInput("at least two legacy kit shares are required".into())- })?;+ let first = shares+ .first()+ .ok_or_else(|| Error::InvalidInput("at least two legacy kit shares are required".into()))?;validate_share_header(first)?;if shares.len() < first.variant.threshold() {- return Err(ContactsError::InvalidInput(+ return Err(Error::InvalidInput("at least two legacy kit shares are required".into(),));}@@ -122,17 +122,17 @@ pub(super) fn used_part_indexes(shares: &[LegacyKitShare]) -> Result<Vec<u8>> {fn validate_share_header(share: &LegacyKitShare) -> Result<()> {if share.payload_version != LEGACY_KIT_PAYLOAD_VERSION {- return Err(ContactsError::InvalidInput(+ return Err(Error::InvalidInput("unsupported legacy kit share payload version".into(),));}if share.variant != LegacyKitVariant::TwoOfThree {- return Err(ContactsError::InvalidInput(+ return Err(Error::InvalidInput("unsupported legacy kit share variant".into(),));}if share.share_index == 0 || share.share_index as usize > share.variant.part_count() {- return Err(ContactsError::InvalidInput(+ return Err(Error::InvalidInput("legacy kit share index is out of range".into(),));}@@ -169,9 +169,7 @@ fn gf_pow(mut base: u8, mut exp: u8) -> u8 {fn gf_inv(value: u8) -> Result<u8> {if value == 0 {- return Err(ContactsError::InvalidInput(- "cannot invert zero in GF(256)".into(),- ));+ return Err(Error::InvalidInput("cannot invert zero in GF(256)".into()));}Ok(gf_pow(value, 254))}diff --git a/rust/crates/contacts/src/lib.rs b/rust/crates/contacts/src/lib.rsindex e83783b5dd..d1defe8467 100644--- a/rust/crates/contacts/src/lib.rs+++ b/rust/crates/contacts/src/lib.rs@@ -10,7 +10,7 @@ pub mod models;pub mod transport;pub use client::{ContactsCtx, OpenContactsCtxInput, OpenContactsCtxResult, RootKeySource};-pub use error::{ContactsError, ErrorKind, Result};+pub use error::{Error, ErrorKind, Result};pub use legacy_kit::{LegacyKitRecoveryClient, LegacyKitRecoveryHandle};pub use legacy_kit_models::{LEGACY_KIT_PAYLOAD_VERSION, LegacyKit, LegacyKitCreateResult, LegacyKitMetadata,diff --git a/rust/crates/contacts/tests/contacts.rs b/rust/crates/contacts/tests/contacts.rsindex 2af48bf07c..a9733bf979 100644--- a/rust/crates/contacts/tests/contacts.rs+++ b/rust/crates/contacts/tests/contacts.rs@@ -123,7 +123,7 @@ async fn run_contacts_stage(pair: &legacy::LegacyPair) {assert!(diff.iter().any(|entry| entry.id == contact.id));match pair.trusted_ctx.get_contact(&contact.id).await {- Err(ente_contacts::ContactsError::Http(http::Error::Http { status: 404, .. })) => {}+ Err(ente_contacts::Error::Http(http::Error::Http { status: 404, .. })) => {}other => panic!("expected trusted account to get 404 for owner contact, got {other:?}"),}