diff --git a/src/lib.rs b/src/lib.rs index c242ffc..a9d1be8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -309,6 +309,8 @@ impl AccountInner { } impl Signer for AccountInner { + type Signature = ::Signature; + fn header<'n, 'u: 'n, 's: 'u>(&'s self, nonce: &'n str, url: &'u str) -> Header<'n> { Header { alg: self.key.signing_algorithm, @@ -318,6 +320,10 @@ impl Signer for AccountInner { } } + fn sign(&self, payload: &[u8]) -> Result { + self.key.sign(payload) + } + fn key(&self) -> &Key { &self.key } @@ -359,7 +365,9 @@ impl Client { }; let nonce = nonce.ok_or("no nonce found")?; - let body = signer.key().signed_json(payload, signer.header(&nonce, url))?; + let body = signer + .key() + .signed_json(payload, signer.header(&nonce, url))?; let request = Request::builder() .method(Method::POST) .uri(url) @@ -420,7 +428,7 @@ impl Key { }; let combined = format!("{protected}.{payload}"); - let signature = self.inner.sign(&self.rng, combined.as_bytes())?; + let signature = self.sign(combined.as_bytes())?; Ok(Body::from(serde_json::to_vec(&JoseJson { protected, payload, @@ -430,6 +438,8 @@ impl Key { } impl Signer for Key { + type Signature = ring::signature::Signature; + fn header<'n, 'u: 'n, 's: 'u>(&'s self, nonce: &'n str, url: &'u str) -> Header<'n> { Header { alg: self.signing_algorithm, @@ -439,14 +449,22 @@ impl Signer for Key { } } + fn sign(&self, payload: &[u8]) -> Result { + Ok(self.inner.sign(&self.rng, payload)?) + } + fn key(&self) -> &Key { self } } trait Signer { + type Signature: AsRef<[u8]>; + fn header<'n, 'u: 'n, 's: 'u>(&'s self, nonce: &'n str, url: &'u str) -> Header<'n>; + fn sign(&self, payload: &[u8]) -> Result; + fn key(&self) -> &Key; }