From d42c0464a4e040514056a996ba7d6afcf97a5447 Mon Sep 17 00:00:00 2001 From: "Aode (lion)" Date: Mon, 13 Dec 2021 12:35:10 -0600 Subject: [PATCH] Update sha dependencies --- http-signature-normalization-actix/Cargo.toml | 6 +- .../src/digest/sha2.rs | 55 ++++--------------- .../src/digest/sha3.rs | 11 +++- 3 files changed, 23 insertions(+), 49 deletions(-) diff --git a/http-signature-normalization-actix/Cargo.toml b/http-signature-normalization-actix/Cargo.toml index cf0309a..84eef51 100644 --- a/http-signature-normalization-actix/Cargo.toml +++ b/http-signature-normalization-actix/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "http-signature-normalization-actix" description = "An HTTP Signatures library that leaves the signing to you" -version = "0.5.0-beta.13" +version = "0.5.0-beta.14" authors = ["asonix "] license-file = "LICENSE" readme = "README.md" @@ -35,8 +35,8 @@ base64 = { version = "0.13", optional = true } chrono = "0.4.6" futures-util = { version = "0.3", default-features = false } http-signature-normalization = { version = "0.5.1", path = ".." } -sha2 = { version = "0.9", optional = true } -sha3 = { version = "0.9", optional = true } +sha2 = { version = "0.10", optional = true } +sha3 = { version = "0.10", optional = true } thiserror = "1.0" tokio = { version = "1", default-features = false, features = ["sync"] } tracing = "0.1" diff --git a/http-signature-normalization-actix/src/digest/sha2.rs b/http-signature-normalization-actix/src/digest/sha2.rs index 2edd8d2..56dfb90 100644 --- a/http-signature-normalization-actix/src/digest/sha2.rs +++ b/http-signature-normalization-actix/src/digest/sha2.rs @@ -1,5 +1,5 @@ use crate::digest::DigestName; -use sha2::{Sha224, Sha256, Sha384, Sha512, Sha512Trunc224, Sha512Trunc256}; +use sha2::{Sha224, Sha256, Sha384, Sha512}; impl DigestName for Sha224 { const NAME: &'static str = "SHA-244"; @@ -17,21 +17,16 @@ impl DigestName for Sha512 { const NAME: &'static str = "SHA-512"; } -impl DigestName for Sha512Trunc224 { - const NAME: &'static str = "SHA-512-224"; -} - -impl DigestName for Sha512Trunc256 { - const NAME: &'static str = "SHA-512-256"; -} - #[cfg(feature = "client")] mod client { use super::*; use crate::digest::DigestCreate; - fn create(digest: &mut impl sha2::Digest, input: &[u8]) -> String { - digest.update(input); + fn create( + digest: &mut D, + input: &[u8], + ) -> String { + sha2::Digest::update(digest, input); base64::encode(&digest.finalize_reset()) } @@ -58,18 +53,6 @@ mod client { create(self, input) } } - - impl DigestCreate for Sha512Trunc224 { - fn compute(&mut self, input: &[u8]) -> String { - create(self, input) - } - } - - impl DigestCreate for Sha512Trunc256 { - fn compute(&mut self, input: &[u8]) -> String { - create(self, input) - } - } } #[cfg(feature = "server")] @@ -78,7 +61,11 @@ mod server { use crate::digest::{DigestPart, DigestVerify}; use tracing::{debug, warn}; - fn verify(digest: &mut impl sha2::Digest, name: &str, parts: &[DigestPart]) -> bool { + fn verify( + digest: &mut D, + name: &str, + parts: &[DigestPart], + ) -> bool { if let Some(part) = parts .iter() .find(|p| p.algorithm.to_lowercase() == name.to_lowercase()) @@ -143,24 +130,4 @@ mod server { verify(self, Self::NAME, parts) } } - - impl DigestVerify for Sha512Trunc224 { - fn update(&mut self, part: &[u8]) { - sha2::Digest::update(self, part); - } - - fn verify(&mut self, parts: &[DigestPart]) -> bool { - verify(self, Self::NAME, parts) - } - } - - impl DigestVerify for Sha512Trunc256 { - fn update(&mut self, part: &[u8]) { - sha2::Digest::update(self, part); - } - - fn verify(&mut self, parts: &[DigestPart]) -> bool { - verify(self, Self::NAME, parts) - } - } } diff --git a/http-signature-normalization-actix/src/digest/sha3.rs b/http-signature-normalization-actix/src/digest/sha3.rs index 5959f3f..a889f0d 100644 --- a/http-signature-normalization-actix/src/digest/sha3.rs +++ b/http-signature-normalization-actix/src/digest/sha3.rs @@ -45,7 +45,10 @@ mod client { use super::*; use crate::digest::DigestCreate; - fn create(digest: &mut impl sha3::Digest, input: &[u8]) -> String { + fn create( + digest: &mut D, + input: &[u8], + ) -> String { digest.update(input); base64::encode(&digest.finalize_reset()) } @@ -111,7 +114,11 @@ mod server { use crate::digest::{DigestPart, DigestVerify}; use tracing::{debug, warn}; - fn verify(digest: &mut impl sha3::Digest, name: &str, parts: &[DigestPart]) -> bool { + fn verify( + digest: &mut D, + name: &str, + parts: &[DigestPart], + ) -> bool { if let Some(part) = parts .iter() .find(|p| p.algorithm.to_lowercase() == name.to_lowercase())