From 9b26cc25a45a1fb083022a7102fa7c73a09353a2 Mon Sep 17 00:00:00 2001 From: bain Date: Sun, 2 Jun 2024 14:13:43 +0200 Subject: [PATCH] refactoring --- src/accounts.rs | 2 +- src/main.rs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/accounts.rs b/src/accounts.rs index 5637d77..2172e2c 100644 --- a/src/accounts.rs +++ b/src/accounts.rs @@ -1,4 +1,4 @@ -/// v1 of the account identificators +/// v1 of account codes use std::time::{SystemTime, UNIX_EPOCH}; use ring::rand::{SecureRandom, SystemRandom}; diff --git a/src/main.rs b/src/main.rs index ea60108..0170c29 100644 --- a/src/main.rs +++ b/src/main.rs @@ -84,9 +84,9 @@ impl fmt::Display for OAuthError { impl Error for OAuthError {} -async fn error_handler(res: tide::Response) -> tide::Result { +async fn error_handler(res: Response) -> tide::Result { if let Some(err) = res.downcast_error::() { - return Ok(tide::Response::builder(400) + return Ok(Response::builder(400) .body(tide::Body::from_json(err)?) .build()); } @@ -111,10 +111,10 @@ fn redirect_with_query(redirect_uri: &str, query: &[(&str, Option<&str>)]) -> ti Ok(tide::Redirect::new(redirect).into()) } -fn render_login_page(client_name: &str, issuer_name: &str, notice: &str) -> tide::Response { +fn render_login_page(client_name: &str, issuer_name: &str, notice: &str) -> Response { Response::builder(200) .body( - // I could use a rendering library here, but its literally as simple as replacing + // I could use a rendering library here, but it's literally as simple as replacing // a few strings from a trusted config. include_str!("authorization.html") .replace("{{client_name}}", client_name) @@ -287,7 +287,7 @@ fn create_id_token( client_id: &str, normalized_account: &str, nonce: Option, -) -> anyhow::Result { +) -> Result { let header = base64_coder::URL_SAFE_NO_PAD.encode( json!({ "alg": "RS256", @@ -312,7 +312,7 @@ fn create_id_token( let mut signature = vec![0; app_state.signing_key.public().modulus_len()]; app_state.signing_key.sign( &ring::signature::RSA_PKCS1_SHA256, - &ring::rand::SystemRandom::new(), + &SystemRandom::new(), message.as_bytes(), &mut signature, )?; @@ -417,7 +417,7 @@ async fn authenticate_endpoint(mut req: Request) -> tide::Result { } } - // The token is random because there are no resources protected by the token anyways. + // The token is random because there are no resources protected by the token anyway. let mut access_token = [0u8; 32]; SystemRandom::new().fill(&mut access_token)?; let access_token = base64_coder::URL_SAFE_NO_PAD.encode(&access_token); @@ -537,7 +537,7 @@ pub struct Authorization { } #[async_std::main] -async fn main() -> anyhow::Result<()> { +async fn main() -> Result<()> { log::with_level(log::LevelFilter::Error); let mut conf_file =