Skip to content

Commit f72c7aa

Browse files
fix: handle 0x prefix to jwt secret if it exists (#246)
remove 0x prefix to jwt secret if it exists
1 parent 03b9616 commit f72c7aa

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/engine/auth.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,17 @@ impl JwtSecret {
3030
/// The provided `secret` must be a valid hexadecimal string of length 64.
3131
pub fn from_hex<S: AsRef<str>>(hex: S) -> Result<Self> {
3232
let hex: &str = hex.as_ref().trim();
33+
// Remove the "0x" or "0X" prefix if it exists
34+
let hex = hex
35+
.strip_prefix("0x")
36+
.or_else(|| hex.strip_prefix("0X"))
37+
.unwrap_or(hex);
3338
if hex.len() != JWT_SECRET_LEN {
34-
Err(eyre::eyre!("Invalid JWT secret key length."))
39+
Err(eyre::eyre!(
40+
"Invalid JWT secret key length. Expected {} characters, got {}.",
41+
JWT_SECRET_LEN,
42+
hex.len()
43+
))
3544
} else {
3645
let hex_bytes = hex::decode(hex)?;
3746
let bytes = hex_bytes.try_into().expect("is expected len");

0 commit comments

Comments
 (0)