Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Merge auth::Error into a typed accounts::Error

Manav Rathic46f2217b941
diff --git a/rust/apps/cli/src/auth_flow.rs b/rust/apps/cli/src/auth_flow.rs
index 7265ee8de8..13ea76c589 100644
--- a/rust/apps/cli/src/auth_flow.rs
+++ b/rust/apps/cli/src/auth_flow.rs
@@ -35,19 +35,9 @@ fn shared_client(
fn to_shared_error(error: Error) -> ente_accounts::Error {
match error {
- Error::Io(source) => ente_accounts::Error::Generic(source.to_string()),
- Error::Serialization(source) => ente_accounts::Error::Serialization(source),
- Error::Database(source) => ente_accounts::Error::Generic(source.to_string()),
- Error::Crypto(message) => ente_accounts::Error::Crypto(message),
- Error::AuthenticationFailed(message) => ente_accounts::Error::AuthenticationFailed(message),
- Error::InvalidConfig(message) => ente_accounts::Error::Generic(message),
- Error::NotFound(message) => ente_accounts::Error::Generic(message),
- Error::InvalidInput(message) => ente_accounts::Error::InvalidInput(message),
- Error::Srp(message) => ente_accounts::Error::Srp(message),
- Error::Base64Decode(source) => ente_accounts::Error::Base64Decode(source),
- Error::Zip(source) => ente_accounts::Error::Generic(source.to_string()),
Error::Http(source) => ente_accounts::Error::Http(source),
- Error::Generic(message) => ente_accounts::Error::Generic(message),
+ Error::Accounts(source) => source,
+ other => ente_accounts::Error::Ui(Box::new(other)),
}
}
diff --git a/rust/apps/cli/src/commands/account.rs b/rust/apps/cli/src/commands/account.rs
index ec3cafe9d7..cd6cd608be 100644
--- a/rust/apps/cli/src/commands/account.rs
+++ b/rust/apps/cli/src/commands/account.rs
@@ -586,10 +586,7 @@ fn new_accounts_client(endpoint: &str, app: App) -> Result<AccountsClient> {
}
fn is_retryable_password_error(error: &ente_accounts::Error) -> bool {
- matches!(
- error,
- ente_accounts::Error::AuthenticationFailed(message) if message == "Incorrect password"
- ) || error.is_http_status(&[401])
+ matches!(error, ente_accounts::Error::IncorrectPassword) || error.is_http_status(&[401])
}
fn can_open_automatically(url: &str) -> bool {
diff --git a/rust/apps/cli/src/models/error.rs b/rust/apps/cli/src/models/error.rs
index 04b6677002..5f97823d49 100644
--- a/rust/apps/cli/src/models/error.rs
+++ b/rust/apps/cli/src/models/error.rs
@@ -1,4 +1,3 @@
-use ente_accounts::auth;
use ente_core::{b64, crypto};
use thiserror::Error;
@@ -40,6 +39,9 @@ pub enum Error {
#[error(transparent)]
Http(#[from] ente_core::http::Error),
+ #[error(transparent)]
+ Accounts(#[from] ente_accounts::Error),
+
#[error("{0}")]
Generic(String),
}
@@ -68,39 +70,4 @@ impl From<crypto::Error> for Error {
}
}
-impl From<auth::Error> for Error {
- fn from(err: auth::Error) -> Self {
- use auth::Error as E;
- match err {
- E::IncorrectPassword => Error::AuthenticationFailed("Incorrect password".to_string()),
- E::IncorrectRecoveryKey => {
- Error::AuthenticationFailed("Incorrect recovery key".to_string())
- }
- E::InvalidKeyAttributes => Error::Crypto(err.to_string()),
- E::InsufficientMemory => Error::Crypto(err.to_string()),
- E::MissingField(field) => Error::Crypto(format!("Missing field: {field}")),
- E::Crypto(source) => source.into(),
- E::Decode(msg) => Error::Crypto(msg),
- E::InvalidKey(msg) => Error::Crypto(msg),
- E::Srp(msg) => Error::Srp(msg),
- }
- }
-}
-
-impl From<ente_accounts::Error> for Error {
- fn from(err: ente_accounts::Error) -> Self {
- use ente_accounts::Error as E;
- match err {
- E::Http(error) => Error::from(error),
- E::Serialization(source) => Error::Serialization(source),
- E::Crypto(message) => Error::Crypto(message),
- E::AuthenticationFailed(message) => Error::AuthenticationFailed(message),
- E::InvalidInput(message) => Error::InvalidInput(message),
- E::Srp(message) => Error::Srp(message),
- E::Base64Decode(source) => Error::Base64Decode(source),
- E::Generic(message) => Error::Generic(message),
- }
- }
-}
-
pub type Result<T> = std::result::Result<T, Error>;
diff --git a/rust/bindings/wasm/ente-wasm/src/auth.rs b/rust/bindings/wasm/ente-wasm/src/auth.rs
index 154d628dfe..62730f3ff5 100644
--- a/rust/bindings/wasm/ente-wasm/src/auth.rs
+++ b/rust/bindings/wasm/ente-wasm/src/auth.rs
@@ -27,20 +27,29 @@ impl AuthError {
}
}
-impl From<auth::Error> for AuthError {
- fn from(e: auth::Error) -> Self {
- use auth::Error as E;
+impl From<ente_accounts::Error> for AuthError {
+ fn from(e: ente_accounts::Error) -> Self {
+ use ente_accounts::Error as E;
let code = match &e {
+ E::Http(_) => "http",
+ E::Serialization(_) => "serialization",
+ E::Crypto(_) => "crypto",
+ E::Decode(_) => "decode",
E::IncorrectPassword => "incorrect_password",
E::IncorrectRecoveryKey => "incorrect_recovery_key",
E::InvalidKeyAttributes => "invalid_key_attributes",
E::InsufficientMemory => "insufficient_memory",
E::MissingField(_) => "missing_field",
- E::Crypto(_) => "crypto",
- E::Decode(_) => "decode",
E::InvalidKey(_) => "invalid_key",
E::Srp(_) => "srp",
+ E::InvalidInput(_) => "invalid_input",
+ E::RateLimited => "rate_limited",
+ E::SecondFactorSessionExpired => "second_factor_session_expired",
+ E::MissingKeyAttributes => "missing_key_attributes",
+ E::AccountAlreadyExists => "account_already_exists",
+ E::Protocol(_) => "protocol",
+ E::Ui(_) => "ui",
}
.to_string();
@@ -359,9 +368,9 @@ impl SrpSession {
login_key_b64: &str,
) -> Result<SrpSession, AuthError> {
let srp_salt = b64::decode(srp_salt_b64)
- .map_err(|e| auth::Error::Decode(format!("srp_salt: {}", e)))?;
+ .map_err(|e| ente_accounts::Error::Decode(format!("srp_salt: {}", e)))?;
let login_key = b64::decode(login_key_b64)
- .map_err(|e| auth::Error::Decode(format!("login_key: {}", e)))?;
+ .map_err(|e| ente_accounts::Error::Decode(format!("login_key: {}", e)))?;
let inner = auth::SrpSession::new(srp_user_id, &srp_salt, &login_key)?;
Ok(Self { inner })
@@ -374,16 +383,16 @@ impl SrpSession {
/// 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> {
- let srp_b =
- b64::decode(srp_b_b64).map_err(|e| auth::Error::Decode(format!("srpB: {}", e)))?;
+ 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> {
- let srp_m2 =
- b64::decode(srp_m2_b64).map_err(|e| auth::Error::Decode(format!("srpM2: {}", e)))?;
+ let srp_m2 = b64::decode(srp_m2_b64)
+ .map_err(|e| ente_accounts::Error::Decode(format!("srpM2: {}", e)))?;
self.inner.verify_m2(&srp_m2)?;
Ok(())
}
diff --git a/rust/crates/accounts/src/auth/api.rs b/rust/crates/accounts/src/auth/api.rs
index 7c618c1d65..b2382111ca 100644
--- a/rust/crates/accounts/src/auth/api.rs
+++ b/rust/crates/accounts/src/auth/api.rs
@@ -10,7 +10,8 @@ use ente_core::crypto::{self, Salt, SecretVec, argon, kdf, sealed, secretbox};
use sha2::Sha256;
use srp::ClientG4096;
-use super::{Error, KeyAttributes, Result, SrpAttributes};
+use super::{KeyAttributes, SrpAttributes};
+use crate::error::{Error, Result};
/// Credentials derived from password for SRP authentication.
pub struct SrpCredentials {
diff --git a/rust/crates/accounts/src/auth/key_gen.rs b/rust/crates/accounts/src/auth/key_gen.rs
index 51304f686d..2ebcf7aa89 100644
--- a/rust/crates/accounts/src/auth/key_gen.rs
+++ b/rust/crates/accounts/src/auth/key_gen.rs
@@ -3,7 +3,8 @@
use ente_core::b64;
use ente_core::crypto::{self, Key, SecretString, SecretVec, argon, kdf, secretbox};
-use super::{KeyAttributes, KeyGenResult, PrivateKeyAttributes, Result};
+use super::{KeyAttributes, KeyGenResult, PrivateKeyAttributes};
+use crate::error::Result;
/// Key derivation strength for password-based key generation.
#[derive(Debug, Clone, Copy, Default)]
diff --git a/rust/crates/accounts/src/auth/mod.rs b/rust/crates/accounts/src/auth/mod.rs
index c161bb3755..89f0e4cb9b 100644
--- a/rust/crates/accounts/src/auth/mod.rs
+++ b/rust/crates/accounts/src/auth/mod.rs
@@ -29,4 +29,4 @@ pub use key_gen::{
pub use recovery::{get_recovery_key, recovery_key_from_mnemonic_or_hex, recovery_key_to_mnemonic};
// Types
-pub use types::{Error, KeyAttributes, KeyGenResult, PrivateKeyAttributes, Result, SrpAttributes};
+pub use types::{KeyAttributes, KeyGenResult, PrivateKeyAttributes, SrpAttributes};
diff --git a/rust/crates/accounts/src/auth/recovery.rs b/rust/crates/accounts/src/auth/recovery.rs
index 27fc840a87..7c4d39b34e 100644
--- a/rust/crates/accounts/src/auth/recovery.rs
+++ b/rust/crates/accounts/src/auth/recovery.rs
@@ -5,7 +5,8 @@ use bip39::{Language, Mnemonic};
use ente_core::b64;
use ente_core::crypto::{self, SecretVec, secretbox};
-use super::{Error, KeyAttributes, Result};
+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> {
diff --git a/rust/crates/accounts/src/auth/srp.rs b/rust/crates/accounts/src/auth/srp.rs
index d64177f7c6..ae0aa7d347 100644
--- a/rust/crates/accounts/src/auth/srp.rs
+++ b/rust/crates/accounts/src/auth/srp.rs
@@ -10,7 +10,7 @@ use srp::ClientG4096;
use subtle::ConstantTimeEq;
use zeroize::Zeroize;
-use super::{Error, Result};
+use crate::error::{Error, Result};
/// SRP session for password-based authentication.
///
diff --git a/rust/crates/accounts/src/auth/types.rs b/rust/crates/accounts/src/auth/types.rs
index a66e49c1fe..a833d29836 100644
--- a/rust/crates/accounts/src/auth/types.rs
+++ b/rust/crates/accounts/src/auth/types.rs
@@ -155,49 +155,6 @@ pub struct SrpAttributes {
pub is_email_mfa_enabled: bool,
}
-/// Error types for auth operations.
-#[derive(Debug, thiserror::Error)]
-pub enum Error {
- /// Password verification failed.
- #[error("Incorrect password")]
- IncorrectPassword,
-
- /// Recovery key verification failed.
- #[error("Incorrect recovery key")]
- IncorrectRecoveryKey,
-
- /// Key attributes are invalid or corrupted.
- #[error("Invalid key attributes")]
- InvalidKeyAttributes,
-
- /// The device could not derive a sensitive key with the required policy.
- #[error("Failed to derive key (insufficient memory)")]
- InsufficientMemory,
-
- /// A required field is missing from the key attributes.
- #[error("Missing required field: {0}")]
- MissingField(&'static str),
-
- /// Underlying cryptographic operation failed.
- #[error("Crypto error: {0}")]
- Crypto(#[from] ente_core::crypto::Error),
-
- /// Failed to decode base64 or hex data.
- #[error("Decode error: {0}")]
- Decode(String),
-
- /// Invalid key format or length.
- #[error("Invalid key: {0}")]
- InvalidKey(String),
-
- /// SRP protocol error.
- #[error("SRP error: {0}")]
- Srp(String),
-}
-
-/// Result type for auth operations.
-pub type Result<T> = std::result::Result<T, Error>;
-
#[cfg(test)]
mod tests {
use super::*;
diff --git a/rust/crates/accounts/src/client.rs b/rust/crates/accounts/src/client.rs
index a769175e19..ab34302bb6 100644
--- a/rust/crates/accounts/src/client.rs
+++ b/rust/crates/accounts/src/client.rs
@@ -39,7 +39,7 @@ fn require_srp_m2(auth_response: &AuthResponse) -> Result<&str> {
.srp_m2
.as_deref()
.filter(|srp_m2| !srp_m2.is_empty())
- .ok_or_else(|| Error::AuthenticationFailed("Missing server proof".to_string()))
+ .ok_or_else(|| Error::Srp("Missing server proof".to_string()))
}
/// Shared account client built on `ente_core::http::Api`.
@@ -123,9 +123,9 @@ impl AccountsClient {
let srp_m2 = require_srp_m2(&auth_response)?;
let server_proof = b64::decode(srp_m2)?;
- srp_session.verify_m2(&server_proof).map_err(|_| {
- Error::AuthenticationFailed("Server proof verification failed".to_string())
- })?;
+ srp_session
+ .verify_m2(&server_proof)
+ .map_err(|_| Error::Srp("Server proof verification failed".to_string()))?;
Ok((auth_response, creds.kek))
}
diff --git a/rust/crates/accounts/src/error.rs b/rust/crates/accounts/src/error.rs
index 59f26574b8..c5910c493b 100644
--- a/rust/crates/accounts/src/error.rs
+++ b/rust/crates/accounts/src/error.rs
@@ -1,51 +1,66 @@
-//! Shared error types for account flows.
-
use ente_core::{b64, crypto, http};
use thiserror::Error;
-use crate::auth;
-
-/// Result alias for the shared account crate.
pub type Result<T> = std::result::Result<T, Error>;
-/// Errors emitted by the shared account crate.
#[derive(Error, Debug)]
pub enum Error {
- /// HTTP/transport or server error.
#[error(transparent)]
Http(#[from] http::Error),
- /// Serialization/deserialization error.
#[error("Serialization error: {0}")]
Serialization(#[from] serde_json::Error),
- /// Wrapped cryptographic error.
- #[error("Crypto error: {0}")]
- Crypto(String),
+ #[error(transparent)]
+ Crypto(#[from] crypto::Error),
+
+ #[error("Decode error: {0}")]
+ Decode(String),
- /// Account/authentication failure.
- #[error("Authentication failed: {0}")]
- AuthenticationFailed(String),
+ #[error("Incorrect password")]
+ IncorrectPassword,
- /// Invalid input.
- #[error("Invalid input: {0}")]
- InvalidInput(String),
+ #[error("Incorrect recovery key")]
+ IncorrectRecoveryKey,
+
+ #[error("Invalid key attributes")]
+ InvalidKeyAttributes,
+
+ #[error("Failed to derive key (insufficient memory)")]
+ InsufficientMemory,
+
+ #[error("Missing required field: {0}")]
+ MissingField(&'static str),
+
+ #[error("Invalid key: {0}")]
+ InvalidKey(String),
- /// SRP-specific failure.
#[error("SRP error: {0}")]
Srp(String),
- /// Base64 decode error.
- #[error("Base64 decode error: {0}")]
- Base64Decode(#[from] b64::DecodeError),
+ #[error("Invalid input: {0}")]
+ InvalidInput(String),
+
+ #[error("Too many attempts, please wait before retrying")]
+ RateLimited,
+
+ #[error("Second factor session expired, restart login")]
+ SecondFactorSessionExpired,
+
+ #[error("Account key attributes are not available")]
+ MissingKeyAttributes,
+
+ #[error("Email already has server-side key state; log in to the existing account instead")]
+ AccountAlreadyExists,
- /// Fallback catch-all.
#[error("{0}")]
- Generic(String),
+ Protocol(String),
+
+ #[error(transparent)]
+ Ui(Box<dyn std::error::Error + Send + Sync>),
}
impl Error {
- /// Return the HTTP status code if the error came from the API.
pub fn status_code(&self) -> Option<u16> {
match self {
Error::Http(error) => error.status_code(),
@@ -53,37 +68,14 @@ impl Error {
}
}
- /// Convenience helper for matching one of several HTTP status codes.
pub fn is_http_status(&self, statuses: &[u16]) -> bool {
self.status_code()
.is_some_and(|status| statuses.contains(&status))
}
}
-impl From<crypto::Error> for Error {
- fn from(err: crypto::Error) -> Self {
- match err {
- crypto::Error::Io(source) => Error::Generic(source.to_string()),
- other => Error::Crypto(other.to_string()),
- }
- }
-}
-
-impl From<auth::Error> for Error {
- fn from(err: auth::Error) -> Self {
- use auth::Error as E;
- match err {
- E::IncorrectPassword => Error::AuthenticationFailed("Incorrect password".to_string()),
- E::IncorrectRecoveryKey => {
- Error::AuthenticationFailed("Incorrect recovery key".to_string())
- }
- E::InvalidKeyAttributes => Error::Crypto(err.to_string()),
- E::InsufficientMemory => Error::Crypto(err.to_string()),
- E::MissingField(field) => Error::Crypto(format!("Missing field: {field}")),
- E::Crypto(source) => source.into(),
- E::Decode(msg) => Error::Crypto(msg),
- E::InvalidKey(msg) => Error::Crypto(msg),
- E::Srp(msg) => Error::Srp(msg),
- }
+impl From<b64::DecodeError> for Error {
+ fn from(err: b64::DecodeError) -> Self {
+ Error::Decode(err.to_string())
}
}
diff --git a/rust/crates/accounts/src/flow.rs b/rust/crates/accounts/src/flow.rs
index 2d5a738d4f..ae3c86d23e 100644
--- a/rust/crates/accounts/src/flow.rs
+++ b/rust/crates/accounts/src/flow.rs
@@ -364,11 +364,7 @@ where
.get_session_validity()
.await?
.key_attributes
- .ok_or_else(|| {
- Error::AuthenticationFailed(
- "Account keys are not available for two-factor setup".into(),
- )
- })?
+ .ok_or(Error::MissingKeyAttributes)?
};
let recovery_key =
@@ -453,7 +449,7 @@ where
mismatches.push("opsLimit");
}
if !mismatches.is_empty() {
- return Err(Error::AuthenticationFailed(format!(
+ return Err(Error::Protocol(format!(
"Remote SRP attributes mismatched after password change: {}",
mismatches.join(", ")
)));
@@ -557,11 +553,11 @@ where
&crypto::Nonce::try_from_slice(&nonce)?,
&crypto::Key::try_from_slice(&recovery_key)?,
)
- .map_err(|_| Error::AuthenticationFailed("Incorrect recovery key".into()))?;
+ .map_err(|_| Error::IncorrectRecoveryKey)?;
let request = RemoveTwoFactorRequest {
session_id: session_id.to_string(),
secret: String::from_utf8(secret)
- .map_err(|e| Error::Crypto(format!("invalid recovery secret: {e}")))?,
+ .map_err(|e| Error::Protocol(format!("invalid recovery secret: {e}")))?,
two_factor_type,
};
self.client.remove_two_factor(&request).await
@@ -623,7 +619,7 @@ where
let key_attributes = auth_response
.key_attributes
.clone()
- .ok_or_else(|| Error::AuthenticationFailed("No key attributes".into()))?;
+ .ok_or(Error::MissingKeyAttributes)?;
let secrets = decrypt_auth_response(&auth_response, &key_attributes, kek)?;
let public_key = b64::decode(&key_attributes.public_key)?;
let recovery_key = get_recovery_key(&secrets.master_key, &key_attributes).ok();
@@ -669,7 +665,7 @@ where
key_derivation_strength: KeyDerivationStrength,
) -> Result<AuthenticatedAccount> {
let token = verification.token.clone().ok_or_else(|| {
- Error::AuthenticationFailed("Signup verification did not return a session token".into())
+ Error::Protocol("Signup verification did not return a session token".into())
})?;
self.client.set_auth_token(Some(token.clone()));
@@ -681,9 +677,7 @@ where
|| session_validity.has_set_keys
|| session_validity.key_attributes.is_some()
{
- return Err(Error::AuthenticationFailed(
- "Email already has server-side key state; use the existing account or recover the incomplete signup instead of creating a new account.".into(),
- ));
+ return Err(Error::AccountAlreadyExists);
}
let key_gen_result = generate_keys_with_strength(&password, key_derivation_strength)?;
@@ -743,9 +737,7 @@ where
resent = false;
}
Err(error) if error.is_http_status(&[429]) => {
- return Err(Error::AuthenticationFailed(
- "Too many incorrect email verification attempts. Please wait and request a new code.".into(),
- ));
+ return Err(Error::RateLimited);
}
Err(error) if error.is_http_status(&[410]) => {
self.client
@@ -780,7 +772,7 @@ where
async fn verify_totp(&mut self, auth_response: &AuthResponse) -> Result<AuthResponse> {
let session_id = auth_response
.get_two_factor_session_id()
- .ok_or_else(|| Error::AuthenticationFailed("No 2FA session ID".into()))?;
+ .ok_or_else(|| Error::Protocol("No 2FA session ID".into()))?;
loop {
let code = self.ui.read_totp_code(TotpPurpose::Login)?;
@@ -791,14 +783,10 @@ where
.report_retryable_error("Incorrect TOTP code. Try again.")?;
}
Err(error) if error.is_http_status(&[429]) => {
- return Err(Error::AuthenticationFailed(
- "Too many incorrect TOTP attempts. Please restart login.".into(),
- ));
+ return Err(Error::RateLimited);
}
Err(error) if error.is_http_status(&[404, 410]) => {
- return Err(Error::AuthenticationFailed(
- "TOTP session expired. Please restart login.".into(),
- ));
+ return Err(Error::SecondFactorSessionExpired);
}
Err(error) => return Err(error),
}
@@ -810,7 +798,7 @@ where
.passkey_session_id
.as_ref()
.filter(|session_id| !session_id.is_empty())
- .ok_or_else(|| Error::AuthenticationFailed("No passkey session ID".into()))?;
+ .ok_or_else(|| Error::Protocol("No passkey session ID".into()))?;
let accounts_url = auth_response
.accounts_url
@@ -833,9 +821,7 @@ where
Ok(result) => return Ok(result),
Err(error) if error.is_http_status(&[400]) => {}
Err(error) if error.is_http_status(&[404, 410]) => {
- return Err(Error::AuthenticationFailed(
- "Passkey session expired. Please restart login.".into(),
- ));
+ return Err(Error::SecondFactorSessionExpired);
}
Err(error) => return Err(error),
}
@@ -957,7 +943,7 @@ fn pad_left(data: &[u8], len: usize) -> Vec<u8> {
fn decode_plain_token(token: &str) -> Result<SecretVec> {
let bytes = b64::decode_url_safe(token)
.or_else(|_| b64::decode(token))
- .map_err(|e| Error::Crypto(format!("token: {e}")))?;
+ .map_err(|e| Error::Decode(format!("token: {e}")))?;
Ok(SecretVec::new(bytes))
}
@@ -976,7 +962,7 @@ fn decrypt_auth_response(
token: decode_plain_token(token)?,
})
} else {
- Err(Error::AuthenticationFailed("No token in response".into()))
+ Err(Error::Protocol("No token in response".into()))
}
}
@@ -1006,7 +992,7 @@ fn validate_remote_srp_attributes(
}
if !mismatches.is_empty() {
- return Err(Error::AuthenticationFailed(format!(
+ return Err(Error::Protocol(format!(
"Remote SRP attributes mismatched after signup: {}",
mismatches.join(", ")
)));
@@ -1021,7 +1007,7 @@ fn encrypt_two_factor_secret(
code: &str,
) -> Result<EnableTwoFactorRequest> {
let recovery_key =
- hex::decode(recovery_key_hex).map_err(|e| Error::Crypto(format!("recovery_key: {e}")))?;
+ hex::decode(recovery_key_hex).map_err(|e| Error::Decode(format!("recovery_key: {e}")))?;
let encrypted = secretbox::encrypt(
secret_code.as_bytes(),
&crypto::Key::try_from_slice(&recovery_key)?,
@@ -1372,12 +1358,7 @@ mod tests {
.unwrap_err();
match error {
- Error::AuthenticationFailed(message) => {
- assert_eq!(
- message,
- "Too many incorrect email verification attempts. Please wait and request a new code."
- );
- }
+ Error::RateLimited => {}
other => panic!("unexpected error: {other:?}"),
}
assert!(ui.retryable_errors.is_empty());
@@ -1461,9 +1442,7 @@ mod tests {
.unwrap_err();
match error {
- Error::AuthenticationFailed(message) => {
- assert_eq!(message, "TOTP session expired. Please restart login.");
- }
+ Error::SecondFactorSessionExpired => {}
other => panic!("unexpected error: {other:?}"),
}
@@ -1547,12 +1526,7 @@ mod tests {
.unwrap_err();
match error {
- Error::AuthenticationFailed(message) => {
- assert_eq!(
- message,
- "Too many incorrect TOTP attempts. Please restart login."
- );
- }
+ Error::RateLimited => {}
other => panic!("unexpected error: {other:?}"),
}
assert!(ui.retryable_errors.is_empty());
@@ -1742,9 +1716,7 @@ mod tests {
.unwrap_err();
match error {
- Error::AuthenticationFailed(message) => {
- assert_eq!(message, "Passkey session expired. Please restart login.");
- }
+ Error::SecondFactorSessionExpired => {}
other => panic!("unexpected error: {other:?}"),
}
assert!(ui.passkey_presented);
diff --git a/rust/crates/contacts/src/error.rs b/rust/crates/contacts/src/error.rs
index 4a6c71f590..0f7226e598 100644
--- a/rust/crates/contacts/src/error.rs
+++ b/rust/crates/contacts/src/error.rs
@@ -1,4 +1,3 @@
-use ente_accounts::auth;
use ente_core::{b64, crypto, http};
use thiserror::Error;
@@ -14,7 +13,7 @@ pub enum ContactsError {
Base64Decode(#[from] b64::DecodeError),
#[error(transparent)]
- Auth(#[from] auth::Error),
+ Accounts(#[from] ente_accounts::Error),
#[error("invalid input: {0}")]
InvalidInput(String),
@@ -54,7 +53,7 @@ impl ContactsError {
ContactsError::Http(_) => ErrorKind::Http,
ContactsError::Crypto(_) => ErrorKind::Crypto,
ContactsError::Base64Decode(_) => ErrorKind::Crypto,
- ContactsError::Auth(_) => ErrorKind::Auth,
+ ContactsError::Accounts(_) => ErrorKind::Auth,
ContactsError::InvalidInput(_) => ErrorKind::InvalidInput,
ContactsError::MissingEncryptedData => ErrorKind::MissingEncryptedData,
ContactsError::MissingEncryptedKey => ErrorKind::MissingEncryptedKey,
diff --git a/rust/crates/contacts/tests/contacts.rs b/rust/crates/contacts/tests/contacts.rs
index de2aa66c23..2af48bf07c 100644
--- a/rust/crates/contacts/tests/contacts.rs
+++ b/rust/crates/contacts/tests/contacts.rs
@@ -275,9 +275,7 @@ async fn run_legacy_reset_stage(endpoint: &str, pair: &mut legacy::LegacyPair) {
.unwrap();
match auth::login_without_totp(endpoint, &pair.owner.email, &previous_password).await {
- Err(ente_accounts::Error::AuthenticationFailed(message)) => {
- assert_eq!(message, "Incorrect password");
- }
+ Err(ente_accounts::Error::IncorrectPassword) => {}
Err(error) if error.is_http_status(&[401]) => {}
other => panic!("expected old password login to fail, got {other:?}"),
}
@@ -637,9 +635,7 @@ async fn run_legacy_kit_stage(endpoint: &str, owner: &mut legacy_kit::LegacyKitO
.expect("legacy kit password reset failed");
match auth::login_without_totp(endpoint, &owner.owner.email, &previous_password).await {
- Err(ente_accounts::Error::AuthenticationFailed(message)) => {
- assert_eq!(message, "Incorrect password");
- }
+ Err(ente_accounts::Error::IncorrectPassword) => {}
Err(error) if error.is_http_status(&[401]) => {}
other => panic!("expected old legacy kit password login to fail, got {other:?}"),
}