2019-09-11 22:05:58 +00:00
|
|
|
use actix_web::http::header::{
|
|
|
|
HeaderMap, HeaderName, HeaderValue, InvalidHeaderValue, AUTHORIZATION,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub struct Signed {
|
|
|
|
pub signed: http_signature_normalization::create::Signed,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Unsigned {
|
|
|
|
pub unsigned: http_signature_normalization::create::Unsigned,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Signed {
|
|
|
|
pub fn signature_header(self, hm: &mut HeaderMap) -> Result<(), InvalidHeaderValue> {
|
2019-09-13 22:55:51 +00:00
|
|
|
let sig_header = self.signed.signature_header();
|
2019-09-11 22:05:58 +00:00
|
|
|
hm.insert(
|
|
|
|
HeaderName::from_static("Signature"),
|
2019-09-13 22:55:51 +00:00
|
|
|
HeaderValue::from_str(&sig_header)?,
|
2019-09-11 22:05:58 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn authorization_header(self, hm: &mut HeaderMap) -> Result<(), InvalidHeaderValue> {
|
2019-09-13 22:55:51 +00:00
|
|
|
let auth_header = self.signed.authorization_header();
|
|
|
|
hm.insert(AUTHORIZATION, HeaderValue::from_str(&auth_header)?);
|
2019-09-11 22:05:58 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Unsigned {
|
|
|
|
pub fn sign<F, E>(self, key_id: String, f: F) -> Result<Signed, E>
|
|
|
|
where
|
2019-09-13 22:55:51 +00:00
|
|
|
F: FnOnce(&str) -> Result<String, E>,
|
2019-09-11 22:05:58 +00:00
|
|
|
{
|
|
|
|
let signed = self.unsigned.sign(key_id, f)?;
|
|
|
|
Ok(Signed { signed })
|
|
|
|
}
|
|
|
|
}
|