Skip to content

Commit

Permalink
Merge pull request #22 from alexrudy/feature/header-render-methods
Browse files Browse the repository at this point in the history
Adds .message() method to header
  • Loading branch information
alexrudy authored Dec 26, 2023
2 parents 2a34f5c + 9f3c2fa commit 062a8de
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/jose/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,12 @@ where
map.extend(parameters);
Ok(map.into())
}

/// The JOSE header value, serialized into compact form, used for signing.
pub(crate) fn message(&self) -> Result<String, serde_json::Error> {
Base64JSON(&self).serialized_value()
}
}

#[cfg(feature = "fmt")]
Expand Down
6 changes: 2 additions & 4 deletions src/token/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,9 @@ specified by constraining the type of `key` when calling [`Token::sign`].
S: SignatureEncoding,
{
let header = self.state.header.into_signed_header(algorithm)?;
let headers = Base64JSON(&header).serialized_value()?;
let payload = self.payload.serialized_value()?;
let signature = algorithm
.try_sign_token(&headers, &payload)
.try_sign_token(&header.message()?, &payload)
.map_err(TokenSigningError::Signing)?;
Ok(Token {
payload: self.payload,
Expand All @@ -492,10 +491,9 @@ specified by constraining the type of `key` when calling [`Token::sign`].
S: SignatureEncoding,
{
let header = self.state.header.into_signed_header(algorithm)?;
let headers = Base64JSON(&header).serialized_value()?;
let payload = self.payload.serialized_value()?;
let signature = algorithm
.try_sign_token(&headers, &payload, rng)
.try_sign_token(&header.message()?, &payload, rng)
.map_err(TokenSigningError::Signing)?;
Ok(Token {
payload: self.payload,
Expand Down

0 comments on commit 062a8de

Please sign in to comment.