diff --git a/src/lib.rs b/src/lib.rs index dacdcea..932a0f4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,11 +43,7 @@ impl Order { KeyAuthorization(format!("{}.{}", challenge.token, &self.account.key.thumb)) } - pub async fn finalize( - &mut self, - csr_der: &[u8], - finalize_url: &str, - ) -> Result { + pub async fn finalize(&mut self, csr_der: &[u8], finalize_url: &str) -> Result { let rsp = self .account .post( @@ -58,7 +54,24 @@ impl Order { .await?; self.nonce = nonce_from_response(&rsp); - Problem::check(rsp).await + let state = Problem::check::(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::().await?.into()), + } } pub async fn set_challenge_ready(&mut self, challenge_url: &str) -> Result<(), Error> { @@ -72,20 +85,6 @@ impl Order { Ok(()) } - pub async fn certificate_chain(&mut self, cert_url: &str) -> Result { - 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::().await?.into()), - } - } - pub async fn challenge(&mut self, challenge_url: &str) -> Result { self.account.get(&mut self.nonce, challenge_url).await }