use serde::{self, Serialize, Deserialize};
use crate::{
authorization::AcmeAuthorization,
directory::AcmeBoundDirectory,
error::Result,
identifier::AcmeIdentifier,
problem::AcmeProblem,
};
#[derive(Debug, Serialize, Deserialize)]
pub struct AcmeOrder {
pub status: String,
pub expires: Option<String>,
pub identifiers: Vec<AcmeIdentifier>,
#[serde(rename="notBefore")]
pub not_before: Option<String>,
#[serde(rename="notBefore")]
pub not_after: Option<String>,
pub error: Option<AcmeProblem>,
pub authorizations: Vec<String>,
pub finalize: String,
pub certificate: Option<String>,
}
impl AcmeOrder {
pub async fn get_authorizations(&self, dir: &AcmeBoundDirectory) -> Result<Vec<(String, AcmeAuthorization)>> {
let mut futures = Vec::with_capacity(self.authorizations.len());
for auth_url in &self.authorizations {
futures.push((auth_url, dir.get_authorization(&auth_url)));
}
let mut result = Vec::with_capacity(self.authorizations.len());
for future in futures {
result.push((future.0.to_string(), future.1.await?));
}
Ok(result)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct AcmeOrderRequest {
pub identifiers: Vec<AcmeIdentifier>,
#[serde(rename="notBefore")]
pub not_before: Option<String>,
#[serde(rename="notBefore")]
pub not_after: Option<String>,
}
impl AcmeOrderRequest {
pub fn new<I, S1, S2>(identifiers: I, not_before: S1, not_after: S2) -> Self
where
I: Into<Vec<AcmeIdentifier>>,
S1: Into<String>,
S2: Into<String>
{
Self { identifiers: identifiers.into(), not_before: Some(not_before.into()), not_after: Some(not_after.into()) }
}
pub fn for_identifiers<I>(identifiers: I) -> Self
where
I: Into<Vec<AcmeIdentifier>>
{
Self { identifiers: identifiers.into(), not_before: None, not_after: None }
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct AcmeOrderFinalization {
pub csr: String,
}