use http::Method;
use super::hash::sha256_lower_hex;
#[derive(Debug, Clone)]
pub struct ServiceStringToSign<'a> {
pub method: &'a Method,
pub path: &'a str,
pub access_token: &'a str,
pub body: &'a [u8],
pub timestamp: &'a str,
}
impl ServiceStringToSign<'_> {
pub fn build(&self) -> String {
let body_hash = sha256_lower_hex(self.body);
format!(
"{method}:{path}:{token}:{body_hash}:{ts}",
method = self.method.as_str(),
path = self.path,
token = self.access_token,
body_hash = body_hash,
ts = self.timestamp,
)
}
}
#[derive(Debug, Clone)]
pub struct OAuthStringToSign<'a> {
pub client_id: &'a str,
pub timestamp: &'a str,
}
impl OAuthStringToSign<'_> {
pub fn build(&self) -> String {
format!("{}|{}", self.client_id, self.timestamp)
}
}