acme: move more logic into library
This commit is contained in:
parent
a04cf7c618
commit
8b8ade0cb3
39
src/lib.rs
39
src/lib.rs
|
@ -43,11 +43,7 @@ impl Order {
|
||||||
KeyAuthorization(format!("{}.{}", challenge.token, &self.account.key.thumb))
|
KeyAuthorization(format!("{}.{}", challenge.token, &self.account.key.thumb))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn finalize(
|
pub async fn finalize(&mut self, csr_der: &[u8], finalize_url: &str) -> Result<String, Error> {
|
||||||
&mut self,
|
|
||||||
csr_der: &[u8],
|
|
||||||
finalize_url: &str,
|
|
||||||
) -> Result<OrderState, Error> {
|
|
||||||
let rsp = self
|
let rsp = self
|
||||||
.account
|
.account
|
||||||
.post(
|
.post(
|
||||||
|
@ -58,7 +54,24 @@ impl Order {
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
self.nonce = nonce_from_response(&rsp);
|
self.nonce = nonce_from_response(&rsp);
|
||||||
Problem::check(rsp).await
|
let state = Problem::check::<OrderState>(rsp).await?;
|
||||||
|
|
||||||
|
let cert_url = match state.certificate {
|
||||||
|
Some(url) => url,
|
||||||
|
None => return Err(Error::Str("no certificate URL")),
|
||||||
|
};
|
||||||
|
|
||||||
|
let rsp = self
|
||||||
|
.account
|
||||||
|
.post(None::<&Empty>, self.nonce.take(), &cert_url)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
self.nonce = nonce_from_response(&rsp);
|
||||||
|
let status = rsp.status();
|
||||||
|
match status.is_client_error() || status.is_server_error() {
|
||||||
|
false => Ok(rsp.text().await?),
|
||||||
|
true => Err(rsp.json::<Problem>().await?.into()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn set_challenge_ready(&mut self, challenge_url: &str) -> Result<(), Error> {
|
pub async fn set_challenge_ready(&mut self, challenge_url: &str) -> Result<(), Error> {
|
||||||
|
@ -72,20 +85,6 @@ impl Order {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn certificate_chain(&mut self, cert_url: &str) -> Result<String, Error> {
|
|
||||||
let rsp = self
|
|
||||||
.account
|
|
||||||
.post(None::<&Empty>, self.nonce.take(), cert_url)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
self.nonce = nonce_from_response(&rsp);
|
|
||||||
let status = rsp.status();
|
|
||||||
match status.is_client_error() || status.is_server_error() {
|
|
||||||
false => Ok(rsp.text().await?),
|
|
||||||
true => Err(rsp.json::<Problem>().await?.into()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn challenge(&mut self, challenge_url: &str) -> Result<Challenge, Error> {
|
pub async fn challenge(&mut self, challenge_url: &str) -> Result<Challenge, Error> {
|
||||||
self.account.get(&mut self.nonce, challenge_url).await
|
self.account.get(&mut self.nonce, challenge_url).await
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue