mirror of
https://git.asonix.dog/asonix/http-signature-normalization.git
synced 2024-11-21 08:51:00 +00:00
Use ring for reqwest example
This commit is contained in:
parent
ec73fe55c9
commit
c1d36000dd
3 changed files with 29 additions and 34 deletions
|
@ -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"
|
||||
|
|
|
@ -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<dyn std::error::Error + Send + Sync>> {
|
||||
let digest = Sha256::new();
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue