unuseds & cargo clippy

This commit is contained in:
2026-03-01 23:59:42 +01:00
parent e60172527c
commit f6a9807794
12 changed files with 46 additions and 39 deletions

View File

@@ -120,7 +120,7 @@ impl<'a> AuthScheme<'a> {
impl UserAuthenticate for User {
fn authenticate(headers: &HeaderMap) -> Result<Option<User>, AuthError> {
let (basic_auth, bearer_auth) = auth_common(&headers);
let (basic_auth, bearer_auth) = auth_common(headers);
match (basic_auth, bearer_auth) {
(Some(creds), _) => authenticate_basic(&creds),
@@ -131,7 +131,7 @@ impl UserAuthenticate for User {
}
impl SessionAuthenticate for Session {
fn authenticate(headers: &HeaderMap) -> Result<Option<Session>, AuthError> {
let (_, bearer_auth) = auth_common(&headers);
let (_, bearer_auth) = auth_common(headers);
if let Some(token) = bearer_auth {
authenticate_bearer_with_session(&token)
} else {
@@ -203,7 +203,7 @@ pub fn authenticate_via_credentials(
false => Err(AuthError::InvalidCredentials),
},
_ => {
let _ = User::match_hash_password(DUMMY_PASSWORD, &*DUMMY_PASSWORD_PHC)?;
let _ = User::match_hash_password(DUMMY_PASSWORD, &DUMMY_PASSWORD_PHC)?;
Err(AuthError::InvalidCredentials)
}
}

View File

@@ -33,7 +33,7 @@ pub trait UserPasswordHashing {
fn match_hash_password(passw: &str, hash: &str) -> Result<bool, argon2::password_hash::Error>;
}
pub static SHARED_ARGON: LazyLock<Argon2> = LazyLock::new(|| Argon2::default());
pub static SHARED_ARGON: LazyLock<Argon2> = LazyLock::new(Argon2::default);
pub const DUMMY_PASSWORD: &str = "PASSWORD";
pub static DUMMY_PASSWORD_PHC: LazyLock<String> = LazyLock::new(|| {
let salt = SaltString::generate(&mut OsRng);
@@ -70,15 +70,17 @@ pub enum AuthError {
}
#[derive(Debug, Clone, Copy)]
#[allow(unused)]
pub enum TokenSize {
/// 5 bytes = 8 chars
#[allow(unused)]
Char8,
/// 10 bytes = 16 chars
Char16,
/// 20 bytes = 32 chars
#[allow(unused)]
Char32,
/// 40 bytes = 64 chars
#[allow(unused)]
Char64,
}

View File

@@ -14,11 +14,11 @@ pub struct UserHandle(String);
#[derive(Debug, thiserror::Error, Clone, PartialEq, Eq, Serialize)]
pub enum UserHandleError {
#[error("Handle is too short - must be 3 or more characters.")]
HandleTooShort,
TooShort,
#[error("Handle is too long - must be 16 or less characters.")]
HandleTooLong,
TooLong,
#[error("Handle must consist of ASCII alphanumeric characters only.")]
HandleNonAsciiAlphanumeric,
NonAsciiAlphanumeric,
}
impl UserHandle {
@@ -29,12 +29,12 @@ impl UserHandle {
}
pub fn validate_str(str: &str) -> Result<(), UserHandleError> {
match str.len() {
..=2 => return Err(UserHandleError::HandleTooShort),
17.. => return Err(UserHandleError::HandleTooLong),
..=2 => return Err(UserHandleError::TooShort),
17.. => return Err(UserHandleError::TooLong),
_ => (),
};
if str.bytes().any(|c| !c.is_ascii_alphanumeric()) {
return Err(UserHandleError::HandleNonAsciiAlphanumeric);
return Err(UserHandleError::NonAsciiAlphanumeric);
}
Ok(())
}
@@ -93,7 +93,7 @@ impl From<UserHandle> for String {
impl ToSql for UserHandle {
fn to_sql(&self) -> RusqliteResult<ToSqlOutput<'_>> {
Ok(self.0.to_sql()?)
self.0.to_sql()
}
}

View File

@@ -79,10 +79,10 @@ impl User {
conn.prepare("UPDATE users SET handle = ?1 WHERE id = ?2")?
.execute((&new_handle, self.id))
.map_err(|e| {
if let Some(e) = e.sqlite_error() {
if e.code == ErrorCode::ConstraintViolation {
return UserError::HandleAlreadyExists(new_handle.clone());
}
if let Some(e) = e.sqlite_error()
&& e.code == ErrorCode::ConstraintViolation
{
return UserError::HandleAlreadyExists(new_handle.clone());
}
UserError::from(e)
})?;

View File

@@ -13,7 +13,10 @@ pub enum Permission {
}
impl User {
pub fn has_permission(&self, permission: Permission) -> Result<bool, DatabaseError> {
pub fn has_permission(
&self,
#[allow(unused)] permission: Permission,
) -> Result<bool, DatabaseError> {
// Infradmin and systemuser have all permissions
if self.is_infradmin() || self.is_systemuser() {
return Ok(true);

View File

@@ -67,7 +67,7 @@ impl Session {
let res = database::conn()?
.prepare("SELECT user_id, expiry, revoked, revoked_at, revoked_by FROM sessions WHERE id = ?1")?
.query_one((&id,), |r| Ok(Session {
id: id,
id,
user_id: r.get(0)?,
expiry: r.get(1)?,
status: match r.get::<_, bool>(2)? {