Fix clippy warnings

This commit is contained in:
Valentin Tolmer
2021-06-23 10:57:34 +02:00
parent eec0903052
commit 2f7019433d
11 changed files with 34 additions and 35 deletions

View File

@@ -1,7 +1,8 @@
use thiserror::Error;
#[allow(clippy::enum_variant_names)]
#[derive(Error, Debug)]
pub enum Error {
pub enum DomainError {
#[error("Authentication error for `{0}`")]
AuthenticationError(String),
#[error("Database error: `{0}`")]
@@ -12,4 +13,4 @@ pub enum Error {
InternalError(String),
}
pub type Result<T> = std::result::Result<T, Error>;
pub type Result<T> = std::result::Result<T, DomainError>;

View File

@@ -173,8 +173,8 @@ impl BackendHandler for SqlBackendHandler {
// Transform it into a single result (the first error if any), and group the group_ids
// into a HashSet.
.collect::<sqlx::Result<HashSet<_>>>()
// Map the sqlx::Error into a domain::Error.
.map_err(Error::DatabaseError)
// Map the sqlx::Error into a DomainError.
.map_err(DomainError::DatabaseError)
}
async fn create_user(&self, request: CreateUserRequest) -> Result<()> {

View File

@@ -52,7 +52,7 @@ impl LoginHandler for SqlBackendHandler {
return Ok(());
} else {
debug!(r#"Invalid password for LDAP bind user"#);
return Err(Error::AuthenticationError(request.name));
return Err(DomainError::AuthenticationError(request.name));
}
}
let query = Query::select()
@@ -65,7 +65,7 @@ impl LoginHandler for SqlBackendHandler {
row.get::<Option<Vec<u8>>, _>(&*Users::PasswordHash.to_string())
{
if let Err(e) = passwords_match(
&&password_hash,
&password_hash,
&request.password,
self.config.get_server_keys().private(),
) {
@@ -79,7 +79,7 @@ impl LoginHandler for SqlBackendHandler {
} else {
debug!(r#"No user found for "{}""#, request.name);
}
Err(Error::AuthenticationError(request.name))
Err(DomainError::AuthenticationError(request.name))
}
}
@@ -101,11 +101,11 @@ impl OpaqueHandler for SqlOpaqueHandler {
.await?
.get::<Option<Vec<u8>>, _>(&*Users::PasswordHash.to_string())
// If no password, always fail.
.ok_or_else(|| Error::AuthenticationError(request.username.clone()))?
.ok_or_else(|| DomainError::AuthenticationError(request.username.clone()))?
};
let password_file = opaque::server::ServerRegistration::deserialize(&password_file_bytes)
.map_err(|_| {
Error::InternalError(format!("Corrupted password file for {}", request.username))
DomainError::InternalError(format!("Corrupted password file for {}", request.username))
})?;
let mut rng = rand::rngs::OsRng;
@@ -163,7 +163,7 @@ impl OpaqueHandler for SqlOpaqueHandler {
&row.get::<Vec<u8>, _>(&*LoginAttempts::ServerLoginData.to_string()),
)
.map_err(|_| {
Error::InternalError(format!(
DomainError::InternalError(format!(
"Corrupted login data for user `{}` [id `{}`]",
username, request.login_key
))
@@ -248,7 +248,7 @@ impl OpaqueHandler for SqlOpaqueHandler {
&row.get::<Vec<u8>, _>(&*RegistrationAttempts::ServerRegistrationData.to_string()),
)
.map_err(|_| {
Error::InternalError(format!(
DomainError::InternalError(format!(
"Corrupted registration data for user `{}` [id `{}`]",
username, request.registration_key
))