Skip to content

Commit

Permalink
polish
Browse files Browse the repository at this point in the history
  • Loading branch information
deepu105 committed Jan 13, 2024
1 parent 8280d8e commit 04260cf
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/app/jwt_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use serde_derive::{Deserialize, Serialize};
use serde_json::{to_string_pretty, Value};

use super::{
jwt_utils::{decoding_key_from_jwks_secret, get_secret, JWTError, JWTResult, SecretType},
jwt_utils::{decoding_key_from_jwks_secret, get_secret_from_file_or_input, JWTError, JWTResult, SecretType},
models::{ScrollableTxt, TabRoute, TabsState},
ActiveBlock, App, Route, RouteId, TextInput,
};
Expand Down Expand Up @@ -260,7 +260,7 @@ fn decoding_key_from_secret(
secret_string: &str,
header: Option<Header>,
) -> JWTResult<DecodingKey> {
let (secret, file_type) = get_secret(alg, secret_string);
let (secret, file_type) = get_secret_from_file_or_input(alg, secret_string);
let secret = secret?;
match alg {
Algorithm::HS256 | Algorithm::HS384 | Algorithm::HS512 => match file_type {
Expand Down
4 changes: 2 additions & 2 deletions src/app/jwt_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use jsonwebtoken::{errors::Error, Algorithm, EncodingKey, Header};

use super::{
jwt_decoder::Payload,
jwt_utils::{get_secret, JWTError, JWTResult, SecretType},
jwt_utils::{get_secret_from_file_or_input, JWTError, JWTResult, SecretType},
models::{ScrollableTxt, TabRoute, TabsState},
ActiveBlock, App, Route, RouteId, TextAreaInput, TextInput,
};
Expand Down Expand Up @@ -108,7 +108,7 @@ pub fn encode_jwt_token(app: &mut App) {
}

pub fn encoding_key_from_secret(alg: &Algorithm, secret_string: &str) -> JWTResult<EncodingKey> {
let (secret, file_type) = get_secret(alg, secret_string);
let (secret, file_type) = get_secret_from_file_or_input(alg, secret_string);
let secret = secret?;

match alg {
Expand Down
2 changes: 1 addition & 1 deletion src/app/jwt_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub enum SecretType {
Plain,
}

pub fn get_secret(alg: &Algorithm, secret_string: &str) -> (JWTResult<Vec<u8>>, SecretType) {
pub fn get_secret_from_file_or_input(alg: &Algorithm, secret_string: &str) -> (JWTResult<Vec<u8>>, SecretType) {
return match alg {
Algorithm::HS256 | Algorithm::HS384 | Algorithm::HS512 => {
if secret_string.starts_with('@') {
Expand Down

0 comments on commit 04260cf

Please sign in to comment.