From 4a9e5753586a711d000c20268768dd80d7a6b79d Mon Sep 17 00:00:00 2001 From: Jack Cargill Date: Mon, 16 Aug 2021 10:41:36 +0100 Subject: [PATCH 1/3] Bump reqwest version to 0.11 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index f1fb26f..2503038 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ chrono = "0.4.11" http = "0.2.1" sha2 = "0.8.1" base64 = "0.12.0" -reqwest = {version = "0.10.4", features = ["blocking"], optional = true} +reqwest = {version = "0.11", features = ["blocking"], optional = true} rouille = {version = "3.0.0", optional = true} subtle = "2.2.2" ring = { version = "0.16.12", features = ["std"], optional = true } From 720b5a57e02bed67a597c95ae2be04237aa40827 Mon Sep 17 00:00:00 2001 From: Jack Cargill Date: Thu, 19 Aug 2021 15:43:26 +0100 Subject: [PATCH 2/3] Run cargo fmt --- src/algorithm.rs | 3 +-- src/algorithm/openssl.rs | 12 +++++++++--- src/algorithm/ring.rs | 15 ++++++++++++--- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/algorithm.rs b/src/algorithm.rs index 61da2ea..6606caf 100644 --- a/src/algorithm.rs +++ b/src/algorithm.rs @@ -46,8 +46,7 @@ macro_rules! hmac_signature { /// Create a new instance of the signature scheme using the /// provided key. pub fn new(key: &[u8]) -> Self { - Self(Hmac::new_varkey(key) - .expect("Hmac construction should be infallible")) + Self(Hmac::new_varkey(key).expect("Hmac construction should be infallible")) } } diff --git a/src/algorithm/openssl.rs b/src/algorithm/openssl.rs index 4bf1993..50a370b 100644 --- a/src/algorithm/openssl.rs +++ b/src/algorithm/openssl.rs @@ -41,12 +41,16 @@ macro_rules! rsa_signature { /// Create a new instance of the signature scheme using the /// provided private key. pub fn new_der(private_key: &[u8]) -> Result> { - Ok(Self(PKey::from_rsa(Rsa::private_key_from_der(private_key)?)?)) + Ok(Self(PKey::from_rsa(Rsa::private_key_from_der( + private_key, + )?)?)) } /// Create a new instance of the signature scheme using the /// provided private key. pub fn new_pem(private_key: &[u8]) -> Result> { - Ok(Self(PKey::from_rsa(Rsa::private_key_from_pem(private_key)?)?)) + Ok(Self(PKey::from_rsa(Rsa::private_key_from_pem( + private_key, + )?)?)) } } @@ -67,7 +71,9 @@ macro_rules! rsa_signature { fn http_sign(&self, bytes_to_sign: &[u8]) -> String { let mut signer = Signer::new(MessageDigest::$hash_alg(), &self.0).unwrap(); signer.set_rsa_padding(Padding::PKCS1).unwrap(); - let tag = signer.sign_oneshot_to_vec(bytes_to_sign).expect("Signing to be infallible"); + let tag = signer + .sign_oneshot_to_vec(bytes_to_sign) + .expect("Signing to be infallible"); base64::encode(&tag) } } diff --git a/src/algorithm/ring.rs b/src/algorithm/ring.rs index 5f011ff..e1bee01 100644 --- a/src/algorithm/ring.rs +++ b/src/algorithm/ring.rs @@ -50,7 +50,13 @@ macro_rules! rsa_signature { impl HttpSignatureSign for $sign_name { fn http_sign(&self, bytes_to_sign: &[u8]) -> String { let mut tag = vec![0; self.0.public_modulus_len()]; - self.0.sign(&signature::$sign_alg, &rand::SystemRandom::new(), bytes_to_sign, &mut tag) + self.0 + .sign( + &signature::$sign_alg, + &rand::SystemRandom::new(), + bytes_to_sign, + &mut tag, + ) .expect("Signing should be infallible"); base64::encode(&tag) } @@ -63,8 +69,11 @@ macro_rules! rsa_signature { }; signature::VerificationAlgorithm::verify( &signature::$verify_alg, - self.0.as_slice().into(), bytes_to_verify.into(), tag.as_slice().into() - ).is_ok() + self.0.as_slice().into(), + bytes_to_verify.into(), + tag.as_slice().into(), + ) + .is_ok() } } }; From dc19c320e3d328d9ca97e487bbd818307c41b548 Mon Sep 17 00:00:00 2001 From: Jack Cargill Date: Thu, 19 Aug 2021 15:44:28 +0100 Subject: [PATCH 3/3] Fix clippy lints --- src/canonicalize.rs | 2 +- src/mock_request.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/canonicalize.rs b/src/canonicalize.rs index b7d814b..6e6d70b 100644 --- a/src/canonicalize.rs +++ b/src/canonicalize.rs @@ -133,7 +133,7 @@ impl CanonicalizeExt for T { let (headers, missing_headers): (Vec<_>, Vec<_>) = config .headers .as_deref() - .unwrap_or_else(|| DEFAULT_HEADERS) + .unwrap_or(DEFAULT_HEADERS) .iter() .cloned() .partition_map(|header| { diff --git a/src/mock_request.rs b/src/mock_request.rs index f3a8706..0b0c769 100644 --- a/src/mock_request.rs +++ b/src/mock_request.rs @@ -153,7 +153,7 @@ impl MockRequest { if let Some(body) = &self.body { writeln!(writer)?; - writer.write_all(&body)?; + writer.write_all(body)?; } Ok(())