41 lines
1 KiB
Rust
41 lines
1 KiB
Rust
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> {
|
|
hm.insert(
|
|
HeaderName::from_static("Signature"),
|
|
HeaderValue::from_str(&self.signed.signature_header())?,
|
|
);
|
|
|
|
Ok(())
|
|
}
|
|
|
|
pub fn authorization_header(self, hm: &mut HeaderMap) -> Result<(), InvalidHeaderValue> {
|
|
hm.insert(
|
|
AUTHORIZATION,
|
|
HeaderValue::from_str(&self.signed.authorization_header())?,
|
|
);
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
impl Unsigned {
|
|
pub fn sign<F, E>(self, key_id: String, f: F) -> Result<Signed, E>
|
|
where
|
|
F: FnOnce(&str) -> Result<Vec<u8>, E>,
|
|
{
|
|
let signed = self.unsigned.sign(key_id, f)?;
|
|
Ok(Signed { signed })
|
|
}
|
|
}
|