jsonwebtoken/src/header.rs

38 lines
962 B
Rust
Raw Normal View History

use crypto::Algorithm;
/// A basic JWT header, the alg defaults to HS256 and typ is automatically
/// set to `JWT`. All the other fields are optional
2017-04-10 23:40:01 -04:00
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Header {
typ: String,
pub alg: Algorithm,
2017-04-10 23:40:01 -04:00
#[serde(skip_serializing_if = "Option::is_none")]
pub jku: Option<String>,
2017-04-10 23:40:01 -04:00
#[serde(skip_serializing_if = "Option::is_none")]
pub kid: Option<String>,
2017-04-10 23:40:01 -04:00
#[serde(skip_serializing_if = "Option::is_none")]
pub x5u: Option<String>,
2017-04-10 23:40:01 -04:00
#[serde(skip_serializing_if = "Option::is_none")]
pub x5t: Option<String>,
}
impl Header {
pub fn new(algorithm: Algorithm) -> Header {
Header {
typ: "JWT".to_string(),
alg: algorithm,
jku: None,
kid: None,
x5u: None,
x5t: None
}
}
}
impl Default for Header {
fn default() -> Header {
Header::new(Algorithm::HS256)
}
}