From cf16c271b858881b9be5aec1cef9d8014222b717 Mon Sep 17 00:00:00 2001 From: Aumetra Weisman Date: Thu, 19 Dec 2024 11:18:02 +0100 Subject: [PATCH] rename fns --- Cargo.lock | 4 ++-- lib/komainu/benches/pkce.rs | 4 ++-- lib/komainu/src/flow/authorization.rs | 16 ++++++++-------- lib/komainu/src/flow/mod.rs | 10 +++++----- lib/komainu/src/flow/pkce.rs | 12 ++++++------ lib/komainu/src/flow/refresh.rs | 8 ++++---- lib/komainu/src/lib.rs | 8 ++------ 7 files changed, 29 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4e95f945..d073f8d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -902,9 +902,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.4" +version = "1.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9157bbaa6b165880c27a4293a474c91cdcf265cc68cc829bf10be0964a391caf" +checksum = "c31a0499c1dc64f458ad13872de75c0eb7e3fdb0e67964610c914b034fc5956e" dependencies = [ "shlex", ] diff --git a/lib/komainu/benches/pkce.rs b/lib/komainu/benches/pkce.rs index 1fac7c6b..d62e0275 100644 --- a/lib/komainu/benches/pkce.rs +++ b/lib/komainu/benches/pkce.rs @@ -6,7 +6,7 @@ use std::borrow::Cow; static GLOBAL: divan::AllocProfiler = divan::AllocProfiler::system(); #[divan::bench] -fn s256() -> Result<(), komainu::flow::FlowError> { +fn s256() -> Result<(), komainu::flow::Error> { let verifier_base64 = "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk"; let challenge_base64 = "E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM"; @@ -19,7 +19,7 @@ fn s256() -> Result<(), komainu::flow::FlowError> { } #[divan::bench] -fn none() -> Result<(), komainu::flow::FlowError> { +fn none() -> Result<(), komainu::flow::Error> { let value = "arbitrary value"; let payload = pkce::Payload { diff --git a/lib/komainu/src/flow/authorization.rs b/lib/komainu/src/flow/authorization.rs index 4e60f73d..18b73878 100644 --- a/lib/komainu/src/flow/authorization.rs +++ b/lib/komainu/src/flow/authorization.rs @@ -1,6 +1,6 @@ use crate::{ extract::ClientCredentials, - flow::{FlowError, OptionExt, TokenResponse}, + flow::{self, OptionExt, TokenResponse}, params::ParamStorage, Authorization, ClientExtractor, }; @@ -11,12 +11,12 @@ pub trait Issuer { fn load_authorization( &self, auth_code: &str, - ) -> impl Future>, FlowError>> + Send; + ) -> impl Future>, flow::Error>> + Send; fn issue_token( &self, authorization: &Authorization<'_>, - ) -> impl Future, FlowError>> + Send; + ) -> impl Future, flow::Error>> + Send; } #[instrument(skip_all)] @@ -24,7 +24,7 @@ pub async fn perform( req: http::Request, client_extractor: CE, token_issuer: I, -) -> Result, FlowError> +) -> Result, flow::Error> where CE: ClientExtractor, I: Issuer, @@ -44,7 +44,7 @@ where if *grant_type != "authorization_code" { error!(?client_id, "grant_type is not authorization_code"); - return Err(FlowError::UnsupportedGrantType); + return Err(flow::Error::UnsupportedGrantType); } let client = client_extractor @@ -53,16 +53,16 @@ where if client.redirect_uri != *redirect_uri { error!(?client_id, "redirect uri doesn't match"); - return Err(FlowError::InvalidClient); + return Err(flow::Error::InvalidClient); } let Some(authorization) = token_issuer.load_authorization(code).await? else { - return Err(FlowError::InvalidGrant); + return Err(flow::Error::InvalidGrant); }; // This check is constant time :3 if client != authorization.client { - return Err(FlowError::UnauthorizedClient); + return Err(flow::Error::UnauthorizedClient); } if let Some(ref pkce) = authorization.pkce_payload { diff --git a/lib/komainu/src/flow/mod.rs b/lib/komainu/src/flow/mod.rs index a5f10721..6e817f2a 100644 --- a/lib/komainu/src/flow/mod.rs +++ b/lib/komainu/src/flow/mod.rs @@ -8,20 +8,20 @@ pub mod pkce; pub mod refresh; trait OptionExt { - fn or_invalid_request(self) -> Result; + fn or_invalid_request(self) -> Result; } impl OptionExt for Option { #[inline] - fn or_invalid_request(self) -> Result { - self.ok_or(FlowError::InvalidRequest) + fn or_invalid_request(self) -> Result { + self.ok_or(Error::InvalidRequest) } } #[derive(Debug, Display, Error, Serialize)] #[serde(rename_all = "snake_case")] #[strum(serialize_all = "snake_case")] -pub enum FlowError { +pub enum Error { InvalidRequest, InvalidClient, InvalidGrant, @@ -49,6 +49,6 @@ pub enum TokenResponse<'a> { expires_in: u64, }, Error { - errorr: FlowError, + errorr: Error, }, } diff --git a/lib/komainu/src/flow/pkce.rs b/lib/komainu/src/flow/pkce.rs index ab18441c..fc3075b9 100644 --- a/lib/komainu/src/flow/pkce.rs +++ b/lib/komainu/src/flow/pkce.rs @@ -1,4 +1,4 @@ -use crate::{error::Error, flow::FlowError}; +use crate::{error::Error, flow}; use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; use std::borrow::Cow; @@ -22,7 +22,7 @@ pub struct Payload<'a> { impl Payload<'_> { #[inline] - fn verify_s256(&self, code_verifier: &str) -> Result<(), FlowError> { + fn verify_s256(&self, code_verifier: &str) -> Result<(), flow::Error> { let decoded = base64_simd::URL_SAFE_NO_PAD .decode_to_vec(self.challenge.as_bytes()) .inspect_err(|error| debug!(?error, "failed to decode pkce payload")) @@ -32,22 +32,22 @@ impl Payload<'_> { if decoded.ct_eq(hash.as_slice()).into() { Ok(()) } else { - Err(FlowError::InvalidGrant) + Err(flow::Error::InvalidGrant) } } #[inline] - fn verify_none(&self, code_verifier: &str) -> Result<(), FlowError> { + fn verify_none(&self, code_verifier: &str) -> Result<(), flow::Error> { let challenge_bytes = self.challenge.as_bytes(); if challenge_bytes.ct_eq(code_verifier.as_bytes()).into() { Ok(()) } else { - Err(FlowError::InvalidGrant) + Err(flow::Error::InvalidGrant) } } #[inline] - pub fn verify(&self, code_verifier: &str) -> Result<(), FlowError> { + pub fn verify(&self, code_verifier: &str) -> Result<(), flow::Error> { match self.method { Method::None => self.verify_none(code_verifier), Method::S256 => self.verify_s256(code_verifier), diff --git a/lib/komainu/src/flow/refresh.rs b/lib/komainu/src/flow/refresh.rs index 74c580bb..658b450c 100644 --- a/lib/komainu/src/flow/refresh.rs +++ b/lib/komainu/src/flow/refresh.rs @@ -1,6 +1,6 @@ use crate::{ extract::ClientCredentials, - flow::{FlowError, OptionExt, TokenResponse}, + flow::{self, OptionExt, TokenResponse}, params::ParamStorage, Client, ClientExtractor, }; @@ -12,7 +12,7 @@ pub trait Issuer { &self, client: &Client<'_>, refresh_token: &str, - ) -> impl Future, FlowError>> + Send; + ) -> impl Future, flow::Error>> + Send; } #[instrument(skip_all)] @@ -20,7 +20,7 @@ pub async fn perform( req: http::Request, client_extractor: CE, token_issuer: I, -) -> Result, FlowError> +) -> Result, flow::Error> where CE: ClientExtractor, I: Issuer, @@ -39,7 +39,7 @@ where if *grant_type != "refresh_token" { debug!(?client_id, "grant_type is not refresh_token"); - return Err(FlowError::UnsupportedGrantType); + return Err(flow::Error::UnsupportedGrantType); } let client = client_extractor diff --git a/lib/komainu/src/lib.rs b/lib/komainu/src/lib.rs index cca16046..67a22a88 100644 --- a/lib/komainu/src/lib.rs +++ b/lib/komainu/src/lib.rs @@ -1,16 +1,12 @@ #[macro_use] extern crate tracing; -use self::flow::pkce; +use self::{error::Error, flow::pkce}; use std::{borrow::Cow, future::Future}; use subtle::ConstantTimeEq; -pub use self::error::Error; -pub use self::params::ParamStorage; - -mod error; - pub mod code_grant; +pub mod error; pub mod extract; pub mod flow; pub mod params;