From ab33c82f0762f01c4c6d395ee88a0946b07d03e7 Mon Sep 17 00:00:00 2001 From: Anton Engelhardt Date: Fri, 3 Nov 2023 16:11:13 +0100 Subject: [PATCH] Small refactoring Signed-off-by: Anton Engelhardt --- src/config.rs | 2 +- src/cookie.rs | 1 - src/responses.rs | 18 ++++++++---------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/config.rs b/src/config.rs index 0c1a7fe4..18c67f59 100644 --- a/src/config.rs +++ b/src/config.rs @@ -7,7 +7,7 @@ use regex::Regex; // url use url::Url; -// wasm-oidc-plugin +// crate use crate::responses::SigningKey; /// Struct that holds the configuration for the filter and all relevant information for the diff --git a/src/cookie.rs b/src/cookie.rs index 3f4f4e31..fec6b3aa 100644 --- a/src/cookie.rs +++ b/src/cookie.rs @@ -13,7 +13,6 @@ use base64::{engine::general_purpose::STANDARD_NO_PAD as base64engine, Engine as // aes_gcm use aes_gcm::{Aes256Gcm, aead::{OsRng, AeadMut}, AeadCore}; - /// Struct parse the cookie from the request into a struct in order to access the fields and /// also to save the cookie on the client side #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/src/responses.rs b/src/responses.rs index f1fa0a48..872004c8 100644 --- a/src/responses.rs +++ b/src/responses.rs @@ -2,7 +2,7 @@ use serde::Deserialize; // log -use log::{debug, info}; +use log::{info, debug}; // base64 use {base64::engine::general_purpose::URL_SAFE_NO_PAD as base64engine_urlsafe, base64::Engine as _}; @@ -37,7 +37,7 @@ pub struct JWKsResponse { pub enum JsonWebKey { /// A RSA Key of 256 bits RS256 { - /// The key type + /// The key type like RSA kty: String, /// The Public Keys Component n, the modulus n: String, @@ -74,6 +74,8 @@ impl SigningKey { /// Implementation of the `From` trait for the `SigningKey` enum to convert the `JsonWebKey` into /// the `SigningKey` enum impl From for SigningKey { + + /// Function that converts the `JsonWebKey` into the `SigningKey` enum fn from(key: JsonWebKey) -> Self { match key { // RSA Key of 256 bits @@ -84,15 +86,11 @@ impl From for SigningKey { debug!("key is not of type RSA although alg is RS256"); } - // Extract public key components - let public_key_comp_n = &n; - let public_key_comp_e = &e; - - // Decode and parse the public key - let n_dec = base64engine_urlsafe.decode(public_key_comp_n).unwrap(); - let e_dec = base64engine_urlsafe.decode(public_key_comp_e).unwrap(); + // Decode and parse the public key components + let n_dec = base64engine_urlsafe.decode(&n).unwrap(); + let e_dec = base64engine_urlsafe.decode(&e).unwrap(); - info!("loaded rs256 public key"); + info!("loaded RS256 public key"); return SigningKey::RS256PublicKey( jwt_simple::algorithms::RS256PublicKey::from_components(&n_dec, &e_dec)