use alloc::{boxed::Box, vec};
use asimov_http::{Component, SecretKey, VerificationPolicy};
use std::net::SocketAddr;
pub type BoxError = Box<dyn core::error::Error + Send + Sync>;
pub const RESPONSE_TAG: &str = "asimov-http-example-response";
pub fn address() -> Result<SocketAddr, BoxError> {
let address = match std::env::var("ASIMOV_HTTP_EXAMPLE_ADDR") {
Ok(address) => address,
Err(std::env::VarError::NotPresent) => "127.0.0.1:3000".into(),
Err(error) => return Err(error.into()),
};
Ok(address.parse()?)
}
pub fn client_key() -> SecretKey {
SecretKey::from_bytes(&[1; 32])
}
pub fn server_key() -> SecretKey {
SecretKey::from_bytes(&[2; 32])
}
pub fn response_policy() -> Result<VerificationPolicy, asimov_http::Error> {
let mut policy = VerificationPolicy::new(vec![
Component::new("@status")?,
Component::new("content-type")?,
Component::parse(r#""signature";req;key="asimov""#)?,
]);
policy.required_tag = Some(RESPONSE_TAG.into());
Ok(policy)
}