diff --git a/src/api/users.rs b/src/api/users.rs index a1b9ef4..fdbb203 100644 --- a/src/api/users.rs +++ b/src/api/users.rs @@ -55,7 +55,7 @@ pub async fn change_handle( let mut target = if u.id == id { u } else { - if u.has_permission(Permission::ChangeOthersHandles)? == false { + if !u.has_permission(Permission::ChangeOthersHandles)? { return Ok((StatusCode::FORBIDDEN, CANT_CHANGE_OTHERS_HANDLE).into_response()); } User::get_by_id(id)? @@ -77,7 +77,7 @@ pub async fn change_password( let mut target = if u.id == id { u } else { - if u.has_permission(Permission::ChangeOthersPasswords)? == false { + if !u.has_permission(Permission::ChangeOthersPasswords)? { return Ok((StatusCode::FORBIDDEN, CANT_CHANGE_OTHERS_PASSW).into_response()); } User::get_by_id(id)? diff --git a/src/database/mod.rs b/src/database/mod.rs index 99e9018..2551888 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -27,7 +27,7 @@ CREATE TABLE IF NOT EXISTS migrations ( pub struct DatabaseError(#[from] rusqlite::Error); impl IntoResponse for DatabaseError { fn into_response(self) -> axum::response::Response { - println!("[DB ERROR] {}", self.to_string()); + println!("[DB ERROR] {}", self); (StatusCode::INTERNAL_SERVER_ERROR, "Internal server error.").into_response() } } @@ -35,7 +35,7 @@ impl IntoResponse for DatabaseError { pub fn conn() -> Result { let conn = Connection::open(&*DB_URL)?; for pragma in CONNECTION_PRAGMAS { - conn.query_row(*pragma, (), |_| Ok(())).optional()?; + conn.query_row(pragma, (), |_| Ok(())).optional()?; } Ok(conn) } @@ -43,7 +43,7 @@ pub fn conn() -> Result { pub fn migrations() -> Result<(), Box> { let conn = Connection::open(&*DB_URL)?; for pragma in PERSISTENT_PRAGMAS { - conn.query_row(*pragma, (), |_| Ok(()))?; + conn.query_row(pragma, (), |_| Ok(()))?; } conn.execute(TABLE_MIGRATIONS, ())?; @@ -58,7 +58,7 @@ pub fn migrations() -> Result<(), Box> { println!("Applying migration {key}..."); conn.execute_batch(sql)?; - conn.execute("INSERT INTO migrations(id) VALUES (?1)", &[key])?; + conn.execute("INSERT INTO migrations(id) VALUES (?1)", [key])?; } if changes { diff --git a/src/main.rs b/src/main.rs index 5e5829e..4e53ba6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,10 +17,10 @@ const ISE_MSG: &str = "Internal server error"; #[tokio::main] async fn main() -> Result<(), Box> { - if let Err(e) = dotenvy::dotenv() { - if !e.not_found() { - return Err(e.into()); - } + if let Err(e) = dotenvy::dotenv() + && !e.not_found() + { + return Err(e.into()); } database::migrations()?; diff --git a/src/quotes/lines.rs b/src/quotes/lines.rs index 155e7cf..dd37193 100644 --- a/src/quotes/lines.rs +++ b/src/quotes/lines.rs @@ -2,6 +2,7 @@ use uuid::Uuid; use crate::persons::{Person, names::Name}; +#[allow(unused)] pub struct QuoteLine { pub id: Uuid, pub attribution: (Name, Person), diff --git a/src/quotes/mod.rs b/src/quotes/mod.rs index 9bd699b..ff5561a 100644 --- a/src/quotes/mod.rs +++ b/src/quotes/mod.rs @@ -5,6 +5,7 @@ use crate::quotes::lines::QuoteLine; pub mod lines; +#[allow(unused)] pub struct Quote { pub id: Uuid, pub lines: Vec, diff --git a/src/tags.rs b/src/tags.rs index 3bce54e..9768ff4 100644 --- a/src/tags.rs +++ b/src/tags.rs @@ -91,15 +91,15 @@ pub struct TagName(String); #[derive(Debug, thiserror::Error, Clone, PartialEq, Eq, Serialize)] pub enum TagNameError { #[error("Tag is too short - must be 2 or more characters.")] - TagTooShort, + TooShort, #[error("Tag is too long - must be 24 or less characters.")] - TagTooLong, + TooLong, #[error("Tag must consist of ASCII alphanumerics or mid-tag dashes only.")] - TagNonDashAsciiAlphanumeric, + NonDashAsciiAlphanumeric, #[error("Tag must not have a leading or trailing dash.")] - TagLeadingTrailingDash, + LeadingTrailingDash, #[error("Tag must not have consecutive dashes.")] - TagConsecutiveDashes, + ConsecutiveDashes, } impl TagName { @@ -110,22 +110,22 @@ impl TagName { } pub fn validate_str(str: &str) -> Result<(), TagNameError> { match str.len() { - ..2 => return Err(TagNameError::TagTooShort), - 25.. => return Err(TagNameError::TagTooLong), + ..2 => return Err(TagNameError::TooShort), + 25.. => return Err(TagNameError::TooLong), _ => (), }; if str.bytes().any(|c| !c.is_ascii_alphanumeric() && c != b'-') { - return Err(TagNameError::TagNonDashAsciiAlphanumeric); + return Err(TagNameError::NonDashAsciiAlphanumeric); } if str.starts_with('-') || str.ends_with('-') { - return Err(TagNameError::TagLeadingTrailingDash); + return Err(TagNameError::LeadingTrailingDash); } if str .as_bytes() .windows(2) .any(|w| w[0] == b'-' && w[1] == b'-') { - return Err(TagNameError::TagConsecutiveDashes); + return Err(TagNameError::ConsecutiveDashes); } Ok(()) } @@ -184,7 +184,7 @@ impl From for String { impl ToSql for TagName { fn to_sql(&self) -> RusqliteResult> { - Ok(self.0.to_sql()?) + self.0.to_sql() } } diff --git a/src/users/auth/implementation.rs b/src/users/auth/implementation.rs index 63a52d7..1c671d9 100644 --- a/src/users/auth/implementation.rs +++ b/src/users/auth/implementation.rs @@ -120,7 +120,7 @@ impl<'a> AuthScheme<'a> { impl UserAuthenticate for User { fn authenticate(headers: &HeaderMap) -> Result, 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, 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) } } diff --git a/src/users/auth/mod.rs b/src/users/auth/mod.rs index 89cb6b9..edc6932 100644 --- a/src/users/auth/mod.rs +++ b/src/users/auth/mod.rs @@ -33,7 +33,7 @@ pub trait UserPasswordHashing { fn match_hash_password(passw: &str, hash: &str) -> Result; } -pub static SHARED_ARGON: LazyLock = LazyLock::new(|| Argon2::default()); +pub static SHARED_ARGON: LazyLock = LazyLock::new(Argon2::default); pub const DUMMY_PASSWORD: &str = "PASSWORD"; pub static DUMMY_PASSWORD_PHC: LazyLock = 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, } diff --git a/src/users/handle.rs b/src/users/handle.rs index 181c5aa..4bbf872 100644 --- a/src/users/handle.rs +++ b/src/users/handle.rs @@ -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 for String { impl ToSql for UserHandle { fn to_sql(&self) -> RusqliteResult> { - Ok(self.0.to_sql()?) + self.0.to_sql() } } diff --git a/src/users/mod.rs b/src/users/mod.rs index 942b122..e05ac2c 100644 --- a/src/users/mod.rs +++ b/src/users/mod.rs @@ -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) })?; diff --git a/src/users/permissions.rs b/src/users/permissions.rs index d87ae31..9e2e631 100644 --- a/src/users/permissions.rs +++ b/src/users/permissions.rs @@ -13,7 +13,10 @@ pub enum Permission { } impl User { - pub fn has_permission(&self, permission: Permission) -> Result { + pub fn has_permission( + &self, + #[allow(unused)] permission: Permission, + ) -> Result { // Infradmin and systemuser have all permissions if self.is_infradmin() || self.is_systemuser() { return Ok(true); diff --git a/src/users/sessions.rs b/src/users/sessions.rs index 142ea4c..5dfa4b2 100644 --- a/src/users/sessions.rs +++ b/src/users/sessions.rs @@ -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)? {