use reqwest::Client;
use crate::{error::Error, tsa::TsaProvider};
const URL: &str = "https://tsa.evidency.io/api/timestamp";
pub async fn request_token(
client: &Client,
message: &[u8],
api_key: &str,
) -> crate::Result<Vec<u8>> {
request_token_to(client, message, api_key, URL).await
}
pub async fn request_token_to(
client: &Client,
message: &[u8],
api_key: &str,
url: &str,
) -> crate::Result<Vec<u8>> {
let req_der = super::ts_request::build(message);
let resp = client
.post(url)
.header("Content-Type", "application/timestamp-query")
.header("X-API-Key", api_key)
.body(req_der)
.send()
.await
.map_err(|e| Error::Collection(format!("Evidency request: {e}")))?;
if !resp.status().is_success() {
return Err(Error::TsaVerification(format!(
"Evidency returned HTTP {}",
resp.status()
)));
}
let bytes = resp
.bytes()
.await
.map_err(|e| Error::Collection(format!("Evidency response body: {e}")))?;
super::ts_request::extract_token(&bytes)
}
pub fn provider() -> TsaProvider {
TsaProvider::Evidency
}