Skip to content

Commit

Permalink
Small refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Engelhardt <[email protected]>
  • Loading branch information
antonengelhardt committed Nov 3, 2023
1 parent 83d6312 commit ab33c82
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/cookie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
18 changes: 8 additions & 10 deletions src/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<JsonWebKey> for SigningKey {

/// Function that converts the `JsonWebKey` into the `SigningKey` enum
fn from(key: JsonWebKey) -> Self {
match key {
// RSA Key of 256 bits
Expand All @@ -84,15 +86,11 @@ impl From<JsonWebKey> 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)
Expand Down

0 comments on commit ab33c82

Please sign in to comment.