Skip to content
Permalink
Browse files
Add custom Default implementation for Header
Signed-off-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
  • Loading branch information
orhun committed Apr 20, 2022
1 parent c6d2fb9 commit a2433724a4ed4f1e028624968b6f0d4eb67c4734
Showing 1 changed file with 12 additions and 1 deletion.
@@ -28,7 +28,7 @@ pub trait JoseHeader {

/// Generic [JWT header](https://tools.ietf.org/html/rfc7519#page-11) with
/// defined fields for common fields.
#[derive(Default, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Header {
#[serde(rename = "typ")]
pub type_: Option<HeaderType>,
@@ -43,6 +43,17 @@ pub struct Header {
pub content_type: Option<HeaderContentType>,
}

impl Default for Header {
fn default() -> Header {
Header {
type_: Some(HeaderType::JsonWebToken),
key_id: None,
algorithm: AlgorithmType::Hs256,
content_type: None,
}
}
}

impl JoseHeader for Header {
fn algorithm_type(&self) -> AlgorithmType {
self.algorithm

0 comments on commit a243372

Please sign in to comment.