Skip to content

Commit

Permalink
rust: allow reponse GET body sign/verify (#266)
Browse files Browse the repository at this point in the history
* allow response GET body sign/verify
* bump
* fix signer
  • Loading branch information
tl-flavio-barinas committed Mar 20, 2024
1 parent 5b73c07 commit 6201f48
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 38 deletions.
4 changes: 2 additions & 2 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "truelayer-signing"
version = "0.2.0"
version = "0.2.1"
authors = ["Alex Butler <alex.butler@truelayer.com>"]
edition = "2021"
description = "Produce & verify TrueLayer API requests signatures"
Expand All @@ -11,7 +11,7 @@ readme = "README.md"

[dependencies]
openssl = "0.10"
base64 = "0.21"
base64 = "0.22"
thiserror = "1.0"
anyhow = "1.0"
serde_json = "1.0"
Expand Down
36 changes: 4 additions & 32 deletions rust/src/sign/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,9 @@ impl<'a, K, Pk, Method, Path> SignerBuilder<'a, K, Pk, Unset, Method, Path> {
}
}

impl<'a, K, Pk, Path> SignerBuilder<'a, K, Pk, Unset, Unset, Path> {
impl<'a, K, Pk, Body, Path> SignerBuilder<'a, K, Pk, Body, Unset, Path> {
/// Add the request method.
///
/// If the method is GET the body will be ignored.
pub fn method(self, method: Method) -> SignerBuilder<'a, K, Pk, Unset, Method, Path> {
pub fn method(self, method: Method) -> SignerBuilder<'a, K, Pk, Body, Method, Path> {
SignerBuilder {
kid: self.kid,
private_key: self.private_key,
Expand All @@ -136,26 +134,6 @@ impl<'a, K, Pk, Path> SignerBuilder<'a, K, Pk, Unset, Unset, Path> {
}
}

impl<'a, K, Pk, Path> SignerBuilder<'a, K, Pk, &'a [u8], Unset, Path> {
/// Add the request method.
///
/// If the method is GET the body will be ignored.
pub fn method(self, method: Method) -> SignerBuilder<'a, K, Pk, &'a [u8], Method, Path> {
SignerBuilder {
kid: self.kid,
private_key: self.private_key,
body: match method {
Method::Get | Method::Delete => &[],
Method::Post | Method::Put | Method::Patch => self.body,
},
method,
path: self.path,
headers: self.headers,
jws_jku: self.jws_jku,
}
}
}

impl<'a, K, Pk, Body, Method> SignerBuilder<'a, K, Pk, Body, Method, Unset> {
/// Add the request absolute path starting with a leading `/` and without
/// any trailing slashes.
Expand Down Expand Up @@ -213,10 +191,7 @@ impl<'a> SignerBuilder<'a, &'a str, Unset, &'a [u8], Method, &'a str> {
pub fn build_custom_signer(self) -> CustomSigner<'a> {
CustomSigner {
kid: self.kid,
body: match self.method {
Method::Get | Method::Delete => &[],
Method::Post | Method::Put | Method::Patch => self.body,
},
body: self.body,
method: self.method.name(),
path: self.path,
headers: self.headers,
Expand Down Expand Up @@ -251,10 +226,7 @@ impl<'a> SignerBuilder<'a, &'a str, &'a [u8], &'a [u8], Method, &'a str> {
private_key: self.private_key,
base: CustomSigner {
kid: self.kid,
body: match self.method {
Method::Get | Method::Delete => &[],
Method::Post | Method::Put | Method::Patch => self.body,
},
body: self.body,
method: self.method.name(),
path: self.path,
headers: self.headers,
Expand Down
5 changes: 1 addition & 4 deletions rust/src/verify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,7 @@ impl<'a> VerifierBuilder<'a, PublicKey<'a>, &'a [u8], Method, &'a str> {
pub fn build_verifier(self) -> Verifier<'a> {
Verifier {
base: CustomVerifier {
body: match self.method {
Method::Get | Method::Delete => &[],
Method::Post | Method::Put | Method::Patch => self.body,
},
body: self.body,
method: self.method.name(),
path: self.path,
headers: self.headers,
Expand Down

0 comments on commit 6201f48

Please sign in to comment.