Skip to content

Commit

Permalink
fix: simplify header parsing (#685)
Browse files Browse the repository at this point in the history
  • Loading branch information
joyqvq authored Nov 7, 2023
1 parent 0094185 commit 1b3323b
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions fastcrypto/src/jwt_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@ impl JWTHeader {
pub fn new(header_base64: &str) -> Result<Self, FastCryptoError> {
let header_bytes = Base64UrlUnpadded::decode_vec(header_base64)
.map_err(|_| FastCryptoError::InvalidInput)?;
let header_str =
std::str::from_utf8(&header_bytes).map_err(|_| FastCryptoError::InvalidInput)?;
let header: JWTHeader =
serde_json::from_str(header_str).map_err(|_| FastCryptoError::InvalidInput)?;
serde_json::from_slice(&header_bytes).map_err(|_| FastCryptoError::InvalidInput)?;
if header.alg != "RS256" {
return Err(FastCryptoError::GeneralError("Invalid header".to_string()));
}
Expand Down

0 comments on commit 1b3323b

Please sign in to comment.