diff --git a/reqwest/Cargo.toml b/reqwest/Cargo.toml index 67ec9e6..87a67f2 100644 --- a/reqwest/Cargo.toml +++ b/reqwest/Cargo.toml @@ -21,7 +21,7 @@ sha-3 = ["digest", "dep:sha3"] [[example]] name = "client" -required-features = ["default-spawner", "sha-2"] +required-features = ["default-spawner", "ring"] [dependencies] async-trait = "0.1.71" diff --git a/reqwest/examples/client.rs b/reqwest/examples/client.rs index c75b9ff..5fc16b1 100644 --- a/reqwest/examples/client.rs +++ b/reqwest/examples/client.rs @@ -1,9 +1,8 @@ -use http_signature_normalization_reqwest::prelude::*; +use http_signature_normalization_reqwest::{digest::ring::Sha256, prelude::*}; use reqwest::{ header::{ACCEPT, USER_AGENT}, Client, }; -use sha2::{Digest, Sha256}; async fn request(config: Config) -> Result<(), Box> { let digest = Sha256::new(); diff --git a/reqwest/src/digest/ring.rs b/reqwest/src/digest/ring.rs index 691c5a0..a9d8771 100644 --- a/reqwest/src/digest/ring.rs +++ b/reqwest/src/digest/ring.rs @@ -1,5 +1,7 @@ //! Types for creating digests with the `ring` cryptography library +use super::DigestCreate; + /// A Sha256 digest backed by ring #[derive(Clone)] pub struct Sha256 { @@ -78,38 +80,32 @@ impl Default for Sha512 { } } -#[cfg(feature = "client")] -mod client { - use super::*; - use crate::digest::DigestCreate; +fn create(mut context: ring::digest::Context, input: &[u8]) -> String { + context.update(input); + let digest = context.finish(); + base64::encode(digest.as_ref()) +} - fn create(mut context: ring::digest::Context, input: &[u8]) -> String { - context.update(input); - let digest = context.finish(); - base64::encode(digest.as_ref()) - } +impl DigestCreate for Sha256 { + const NAME: &'static str = "SHA-256"; - impl DigestCreate for Sha256 { - const NAME: &'static str = "SHA-256"; - - fn compute(&mut self, input: &[u8]) -> String { - create(self.ctx.clone(), input) - } - } - - impl DigestCreate for Sha384 { - const NAME: &'static str = "SHA-384"; - - fn compute(&mut self, input: &[u8]) -> String { - create(self.ctx.clone(), input) - } - } - - impl DigestCreate for Sha512 { - const NAME: &'static str = "SHA-512"; - - fn compute(&mut self, input: &[u8]) -> String { - create(self.ctx.clone(), input) - } + fn compute(&mut self, input: &[u8]) -> String { + create(self.ctx.clone(), input) + } +} + +impl DigestCreate for Sha384 { + const NAME: &'static str = "SHA-384"; + + fn compute(&mut self, input: &[u8]) -> String { + create(self.ctx.clone(), input) + } +} + +impl DigestCreate for Sha512 { + const NAME: &'static str = "SHA-512"; + + fn compute(&mut self, input: &[u8]) -> String { + create(self.ctx.clone(), input) } }