2017-01-09 00:50:51 -05:00
|
|
|
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)]
|
2017-01-09 00:50:51 -05:00
|
|
|
pub struct Header {
|
|
|
|
typ: String,
|
|
|
|
pub alg: Algorithm,
|
2017-04-10 23:40:01 -04:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2017-01-09 00:50:51 -05:00
|
|
|
pub jku: Option<String>,
|
2017-04-10 23:40:01 -04:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2017-01-09 00:50:51 -05:00
|
|
|
pub kid: Option<String>,
|
2017-04-10 23:40:01 -04:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2017-01-09 00:50:51 -05:00
|
|
|
pub x5u: Option<String>,
|
2017-04-10 23:40:01 -04:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub x5t: Option<String>,
|
2017-01-09 00:50:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|