Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc: small refactor for JwtSecret #1611

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Changes from all commits
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
9 changes: 4 additions & 5 deletions crates/rpc-types-engine/src/jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl JwtSecret {
///
/// This strips the leading `0x`, if any.
pub fn from_hex<S: AsRef<str>>(hex: S) -> Result<Self, JwtError> {
let hex: &str = hex.as_ref().trim().trim_start_matches("0x");
let hex = hex.as_ref().trim().trim_start_matches("0x");
if hex.len() == JWT_SECRET_LEN {
let hex_bytes = hex::decode(hex)?;
// is 32bytes, see length check
Expand All @@ -188,10 +188,9 @@ impl JwtSecret {
/// a [`JwtError`].
#[cfg(feature = "std")]
pub fn from_file(fpath: &Path) -> Result<Self, JwtError> {
let hex = fs::read_to_string(fpath)
.map_err(|err| JwtError::Read { source: err, path: fpath.into() })?;
let secret = Self::from_hex(hex)?;
Ok(secret)
fs::read_to_string(fpath)
.map_err(|err| JwtError::Read { source: err, path: fpath.into() })
.and_then(Self::from_hex)
}

/// Creates a random [`JwtSecret`] and tries to store it at the specified path. I/O errors might
Expand Down