Defer serialization of JoseJson data

This commit is contained in:
Dirkjan Ochtman 2023-05-18 10:42:27 +02:00
parent 963ca96aa2
commit 48cd0a0ded
1 changed files with 4 additions and 4 deletions

View File

@ -372,7 +372,7 @@ impl Client {
.method(Method::POST) .method(Method::POST)
.uri(url) .uri(url)
.header(CONTENT_TYPE, JOSE_JSON) .header(CONTENT_TYPE, JOSE_JSON)
.body(body) .body(Body::from(serde_json::to_vec(&body)?))
.unwrap(); .unwrap();
Ok(self.client.request(request).await?) Ok(self.client.request(request).await?)
@ -420,7 +420,7 @@ impl Key {
&self, &self,
payload: Option<&impl Serialize>, payload: Option<&impl Serialize>,
protected: Header<'_>, protected: Header<'_>,
) -> Result<Body, Error> { ) -> Result<JoseJson, Error> {
let protected = base64(&protected)?; let protected = base64(&protected)?;
let payload = match payload { let payload = match payload {
Some(data) => base64(&data)?, Some(data) => base64(&data)?,
@ -429,11 +429,11 @@ impl Key {
let combined = format!("{protected}.{payload}"); let combined = format!("{protected}.{payload}");
let signature = self.sign(combined.as_bytes())?; let signature = self.sign(combined.as_bytes())?;
Ok(Body::from(serde_json::to_vec(&JoseJson { Ok(JoseJson {
protected, protected,
payload, payload,
signature: BASE64_URL_SAFE_NO_PAD.encode(signature.as_ref()), signature: BASE64_URL_SAFE_NO_PAD.encode(signature.as_ref()),
})?)) })
} }
} }