acme: move Client construction into associated function

This commit is contained in:
Dirkjan Ochtman 2022-05-10 13:59:47 +02:00 committed by Dirkjan Ochtman
parent e4ef9955a3
commit bed1565783
1 changed files with 10 additions and 7 deletions

View File

@ -101,13 +101,7 @@ pub struct Account {
impl Account {
pub async fn create(account: &NewAccount<'_>, server_url: &str) -> Result<Account, Error> {
let client = client()?;
let urls = client.get(server_url).send().await?;
let client = Client {
client,
urls: urls.json().await?,
};
let client = Client::new(server_url).await?;
let key = Key::generate()?;
let nonce = client.nonce().await?;
let header = key.key_header(&nonce, &client.urls.new_account);
@ -271,6 +265,15 @@ struct Client {
}
impl Client {
async fn new(server_url: &str) -> Result<Self, Error> {
let client = client()?;
let urls = client.get(server_url).send().await?;
Ok(Client {
client,
urls: urls.json().await?,
})
}
async fn nonce(&self) -> Result<String, Error> {
let future = self.client.head(&self.urls.new_nonce).send();
match nonce_from_response(&future.await?) {