Skip to content

Commit

Permalink
fix: handle 0x prefix to jwt secret if it exists (#246)
Browse files Browse the repository at this point in the history
remove 0x prefix to jwt secret if it exists
  • Loading branch information
alessandromazza98 authored Jun 20, 2024
1 parent 03b9616 commit f72c7aa
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/engine/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,17 @@ impl JwtSecret {
/// The provided `secret` must be a valid hexadecimal string of length 64.
pub fn from_hex<S: AsRef<str>>(hex: S) -> Result<Self> {
let hex: &str = hex.as_ref().trim();
// Remove the "0x" or "0X" prefix if it exists
let hex = hex
.strip_prefix("0x")
.or_else(|| hex.strip_prefix("0X"))
.unwrap_or(hex);
if hex.len() != JWT_SECRET_LEN {
Err(eyre::eyre!("Invalid JWT secret key length."))
Err(eyre::eyre!(
"Invalid JWT secret key length. Expected {} characters, got {}.",
JWT_SECRET_LEN,
hex.len()
))
} else {
let hex_bytes = hex::decode(hex)?;
let bytes = hex_bytes.try_into().expect("is expected len");
Expand Down

0 comments on commit f72c7aa

Please sign in to comment.