Add openssl sha2 impl

This commit is contained in:
asonix 2022-12-11 19:14:36 -06:00
parent e906063432
commit 1d02bc9e9f
4 changed files with 21 additions and 4 deletions

View file

@ -10,8 +10,9 @@ required-features = ["rustcrypto"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = ["rustcrypto"]
rustcrypto = ["sha2", "hex"]
default = ["rustcrypto-sha2"]
rustcrypto-sha2 = ["sha2", "hex"]
openssl-sha2 = ["openssl", "hex"]
[dependencies]
contextual = "0.1.3"
@ -23,6 +24,7 @@ rdf-types = "0.12.4"
hex = { version = "0.4.3", optional = true }
sha2 = { version = "0.10.6", optional = true }
openssl = { version = "0.10.44", optional = true }
[dev-dependencies]
iref = "2.2.0"

View file

@ -11,9 +11,11 @@ use std::{
mod input_dataset;
mod issuer;
#[cfg(feature = "openssl-sha2")]
mod openssl_impls;
mod output_dataset;
#[cfg(feature = "rustcrypto")]
mod sha2_impls;
#[cfg(feature = "rustcrypto-sha2")]
mod rustcrypto_impls;
use input_dataset::{InputDataset, NormalizingQuad, Position, QuadSubject, QuadValue};
use issuer::Issuer;

13
src/openssl_impls.rs Normal file
View file

@ -0,0 +1,13 @@
use openssl::sha::Sha256;
impl super::Sha256 for Sha256 {
fn update(&mut self, bytes: &[u8]) {
openssl::sha::Sha256::update(self, bytes)
}
fn finalize_hex_and_reset(&mut self) -> crate::HexHash {
let this = std::mem::replace(self, Sha256::default());
crate::HexHash(hex::encode(this.finish()))
}
}