http_signature_normalization_http/
create.rs1use http::header::{HeaderMap, HeaderName, HeaderValue, InvalidHeaderValue, AUTHORIZATION};
3
4pub struct Signed {
6 pub signed: http_signature_normalization::create::Signed,
8}
9
10pub struct Unsigned {
14 pub unsigned: http_signature_normalization::create::Unsigned,
16}
17
18impl Signed {
19 pub fn signature_header(self, hm: &mut HeaderMap) -> Result<(), InvalidHeaderValue> {
21 hm.insert(
22 HeaderName::from_static("Signature"),
23 HeaderValue::from_str(&self.signed.signature_header())?,
24 );
25
26 Ok(())
27 }
28
29 pub fn authorization_header(self, hm: &mut HeaderMap) -> Result<(), InvalidHeaderValue> {
31 hm.insert(
32 AUTHORIZATION,
33 HeaderValue::from_str(&self.signed.authorization_header())?,
34 );
35 Ok(())
36 }
37}
38
39impl Unsigned {
40 pub fn sign<F, E>(self, key_id: String, f: F) -> Result<Signed, E>
49 where
50 F: FnOnce(&str) -> Result<String, E>,
51 {
52 let signed = self.unsigned.sign(key_id, f)?;
53 Ok(Signed { signed })
54 }
55}