59 lines
1.5 KiB
Rust
59 lines
1.5 KiB
Rust
use actix_web::{
|
|
client::ClientRequest,
|
|
http::header::{InvalidHeaderValue, ToStrError},
|
|
};
|
|
use std::fmt::Display;
|
|
|
|
use crate::{
|
|
digest::{DigestClient, DigestCreate, SignExt},
|
|
Config, Sign,
|
|
};
|
|
|
|
impl SignExt for ClientRequest {
|
|
fn authorization_signature_with_digest<F, E, K, D, V>(
|
|
self,
|
|
config: &Config,
|
|
key_id: K,
|
|
digest: &mut D,
|
|
v: V,
|
|
f: F,
|
|
) -> Result<DigestClient<V>, E>
|
|
where
|
|
F: FnOnce(&str) -> Result<String, E>,
|
|
E: From<ToStrError> + From<InvalidHeaderValue>,
|
|
K: Display,
|
|
D: DigestCreate,
|
|
V: AsRef<[u8]>,
|
|
Self: Sized,
|
|
{
|
|
let digest = digest.compute(v.as_ref());
|
|
|
|
self.set_header("Digest", format!("{}={}", D::NAME, digest))
|
|
.authorization_signature(config, key_id, f)
|
|
.map(|c| DigestClient::new(c, v))
|
|
}
|
|
|
|
fn signature_with_digest<F, E, K, D, V>(
|
|
self,
|
|
config: &Config,
|
|
key_id: K,
|
|
digest: &mut D,
|
|
v: V,
|
|
f: F,
|
|
) -> Result<DigestClient<V>, E>
|
|
where
|
|
F: FnOnce(&str) -> Result<String, E>,
|
|
E: From<ToStrError> + From<InvalidHeaderValue>,
|
|
K: Display,
|
|
D: DigestCreate,
|
|
V: AsRef<[u8]>,
|
|
Self: Sized,
|
|
{
|
|
let digest = digest.compute(v.as_ref());
|
|
|
|
self.set_header("Digest", format!("{}={}", D::NAME, digest))
|
|
.signature(config, key_id, f)
|
|
.map(|c| DigestClient::new(c, v))
|
|
}
|
|
}
|