diff --git a/src/auth.rs b/src/auth.rs index 846b3ff..c0156d0 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -5,21 +5,21 @@ use tracing::{trace, warn}; use crate::password; -pub fn auth_layer<'a, ResBody>( +pub fn layer<'a, ResBody>( user_pass_hash: &'a [u8], salt: &'a str, -) -> ValidateRequestHeaderLayer> { - ValidateRequestHeaderLayer::custom(BasicAuth::new(user_pass_hash, salt)) +) -> ValidateRequestHeaderLayer> { + ValidateRequestHeaderLayer::custom(Basic::new(user_pass_hash, salt)) } #[derive(Copy)] -pub struct BasicAuth<'a, ResBody> { +pub struct Basic<'a, ResBody> { pass: &'a [u8], salt: &'a str, _ty: std::marker::PhantomData ResBody>, } -impl std::fmt::Debug for BasicAuth<'_, ResBody> { +impl std::fmt::Debug for Basic<'_, ResBody> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("BasicAuth") .field("pass", &self.pass) @@ -29,7 +29,7 @@ impl std::fmt::Debug for BasicAuth<'_, ResBody> { } } -impl Clone for BasicAuth<'_, ResBody> { +impl Clone for Basic<'_, ResBody> { fn clone(&self) -> Self { Self { pass: self.pass, @@ -39,7 +39,7 @@ impl Clone for BasicAuth<'_, ResBody> { } } -impl<'a, ResBody> BasicAuth<'a, ResBody> { +impl<'a, ResBody> Basic<'a, ResBody> { pub fn new(pass: &'a [u8], salt: &'a str) -> Self { Self { pass, @@ -81,7 +81,7 @@ impl<'a, ResBody> BasicAuth<'a, ResBody> { } } -impl tower_http::validate_request::ValidateRequest for BasicAuth<'_, ResBody> +impl tower_http::validate_request::ValidateRequest for Basic<'_, ResBody> where ResBody: Default, { diff --git a/src/main.rs b/src/main.rs index b1b7d89..b612c38 100644 --- a/src/main.rs +++ b/src/main.rs @@ -290,7 +290,7 @@ fn main() -> Result<()> { let app = Router::new().route("/update", get(update_records)); // if a password is provided, validate it let app = if let Some(pass) = password_hash { - app.layer(auth::auth_layer(Box::leak(pass), String::leak(salt))) + app.layer(auth::layer(Box::leak(pass), String::leak(salt))) } else { app }