Move JSON creation out of Signer trait

This commit is contained in:
Dirkjan Ochtman 2023-05-18 10:37:22 +02:00
parent 11551dedf4
commit df80c1621d
1 changed files with 2 additions and 10 deletions

View File

@ -359,11 +359,12 @@ impl Client {
}; };
let nonce = nonce.ok_or("no nonce found")?; let nonce = nonce.ok_or("no nonce found")?;
let body = signer.key().signed_json(payload, signer.header(&nonce, url))?;
let request = Request::builder() let request = Request::builder()
.method(Method::POST) .method(Method::POST)
.uri(url) .uri(url)
.header(CONTENT_TYPE, JOSE_JSON) .header(CONTENT_TYPE, JOSE_JSON)
.body(signer.signed_json(payload, &nonce, url)?) .body(body)
.unwrap(); .unwrap();
Ok(self.client.request(request).await?) Ok(self.client.request(request).await?)
@ -444,15 +445,6 @@ impl Signer for Key {
} }
trait Signer { trait Signer {
fn signed_json(
&self,
payload: Option<&impl Serialize>,
nonce: &str,
url: &str,
) -> Result<Body, Error> {
self.key().signed_json(payload, self.header(nonce, url))
}
fn header<'n, 'u: 'n, 's: 'u>(&'s self, nonce: &'n str, url: &'u str) -> Header<'n>; fn header<'n, 'u: 'n, 's: 'u>(&'s self, nonce: &'n str, url: &'u str) -> Header<'n>;
fn key(&self) -> &Key; fn key(&self) -> &Key;