Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion crates/rpc/rpc/src/layers/jwt_secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl JwtSecret {
/// - `hex` is not a valid hexadecimal string
/// - `hex` argument length is less than `JWT_SECRET_LEN`
Comment thread
onbjerg marked this conversation as resolved.
pub fn from_hex<S: AsRef<str>>(hex: S) -> Result<Self, JwtError> {
let hex: &str = hex.as_ref().trim();
let hex: &str = hex.as_ref().trim().trim_start_matches("0x");
if hex.len() != JWT_SECRET_LEN {
Err(JwtError::InvalidLength(JWT_SECRET_LEN, hex.len()))
} else {
Expand Down Expand Up @@ -212,6 +212,14 @@ mod tests {
assert_eq!(hex.len(), expected_len);
}

#[test]
fn creation_ok_hex_string_with_0x() {
let hex: String =
"0x7365637265747365637265747365637265747365637265747365637265747365".into();
let result = JwtSecret::from_hex(hex);
assert!(matches!(result, Ok(_)));
}

#[test]
fn creation_error_wrong_len() {
let hex = "f79ae8046";
Expand Down