1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use actix_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> {
let sig_header = self.signed.signature_header();
hm.insert(
HeaderName::from_static("signature"),
HeaderValue::from_str(&sig_header)?,
);
Ok(())
}
pub fn authorization_header(self, hm: &mut HeaderMap) -> Result<(), InvalidHeaderValue> {
let auth_header = self.signed.authorization_header();
hm.insert(AUTHORIZATION, HeaderValue::from_str(&auth_header)?);
Ok(())
}
}
impl Unsigned {
pub fn sign<F, E>(self, key_id: String, f: F) -> Result<Signed, E>
where
F: FnOnce(&str) -> Result<String, E>,
{
let signed = self.unsigned.sign(key_id, f)?;
Ok(Signed { signed })
}
}