diff --git a/lib/entry/libimagentrylink/Cargo.toml b/lib/entry/libimagentrylink/Cargo.toml index c52d0c26..3b0029ef 100644 --- a/lib/entry/libimagentrylink/Cargo.toml +++ b/lib/entry/libimagentrylink/Cargo.toml @@ -24,7 +24,8 @@ itertools = "0.7" log = "0.4.0" toml = "0.4" url = "1.5" -rust-crypto = "0.2" +sha-1 = "0.7" +hex = "0.3" is-match = "0.1" toml-query = "0.6" error-chain = "0.11" diff --git a/lib/entry/libimagentrylink/src/external.rs b/lib/entry/libimagentrylink/src/external.rs index 77a81849..b2b898ba 100644 --- a/lib/entry/libimagentrylink/src/external.rs +++ b/lib/entry/libimagentrylink/src/external.rs @@ -54,8 +54,8 @@ use self::iter::*; use toml::Value; use url::Url; -use crypto::sha1::Sha1; -use crypto::digest::Digest; +use sha1::{Sha1, Digest}; +use hex; pub trait Link { @@ -318,11 +318,7 @@ impl ExternalLinker for Entry { debug!("Iterating {} links = {:?}", links.len(), links); for link in links { // for all links - let hash = { - let mut s = Sha1::new(); - s.input_str(&link.as_str()[..]); - s.result_str() - }; + let hash = hex::encode(Sha1::digest(&link.as_str().as_bytes())); let file_id = ModuleEntryPath::new(format!("external/{}", hash)).into_storeid() .map_dbg_err(|_| { diff --git a/lib/entry/libimagentrylink/src/lib.rs b/lib/entry/libimagentrylink/src/lib.rs index 788f8b39..366d53fe 100644 --- a/lib/entry/libimagentrylink/src/lib.rs +++ b/lib/entry/libimagentrylink/src/lib.rs @@ -40,7 +40,8 @@ extern crate itertools; extern crate toml; extern crate toml_query; extern crate url; -extern crate crypto; +extern crate sha1; +extern crate hex; #[macro_use] extern crate is_match; #[macro_use] extern crate error_chain; diff --git a/lib/entry/libimagentryref/Cargo.toml b/lib/entry/libimagentryref/Cargo.toml index 97ea47e9..a23c13da 100644 --- a/lib/entry/libimagentryref/Cargo.toml +++ b/lib/entry/libimagentryref/Cargo.toml @@ -25,22 +25,22 @@ log = "0.4.0" toml = "0.4" toml-query = "0.6" error-chain = "0.11" +sha-1 = { version = "0.7", optional = true } +sha2 = { version = "0.7", optional = true } +sha3 = { version = "0.7", optional = true } +hex = { version = "0.3", optional = true } libimagstore = { version = "0.9.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.9.0", path = "../../../lib/core/libimagerror" } libimagentryutil = { version = "0.9.0", path = "../../../lib/entry/libimagentryutil" } -[dependencies.rust-crypto] -version = "0.2" -optional = true - [features] default = [] generators = [] -generators-sha1 = ["rust-crypto"] -generators-sha224 = ["rust-crypto"] -generators-sha256 = ["rust-crypto"] -generators-sha384 = ["rust-crypto"] -generators-sha512 = ["rust-crypto"] -generators-sha3 = ["rust-crypto"] +generators-sha1 = ["sha-1", "hex"] +generators-sha224 = ["sha2", "hex"] +generators-sha256 = ["sha2", "hex"] +generators-sha384 = ["sha2", "hex"] +generators-sha512 = ["sha2", "hex"] +generators-sha3 = ["sha3", "hex"] diff --git a/lib/entry/libimagentryref/src/generators/mod.rs b/lib/entry/libimagentryref/src/generators/mod.rs index 204ae081..23f12f51 100644 --- a/lib/entry/libimagentryref/src/generators/mod.rs +++ b/lib/entry/libimagentryref/src/generators/mod.rs @@ -175,7 +175,7 @@ macro_rules! make_sha_mod { use error::RefError as RE; - use crypto::digest::Digest; + use hex; make_unique_ref_path_generator! ( pub $hashname over generators::base::Base @@ -235,59 +235,53 @@ macro_rules! make_sha_mod { #[cfg(feature = "generators-sha1")] make_sha_mod! { sha1, Sha1, |buffer: String| { - let mut hasher = ::crypto::sha1::Sha1::new(); + use sha1::{Sha1, Digest}; trace!("Hashing: '{:?}'", buffer); - hasher.input_str(&buffer); - let res = hasher.result_str(); + let res = hex::encode(Sha1::digest(buffer.as_bytes())); trace!("Hash => '{:?}'", res); - Ok(String::from(res)) + Ok(res) } } #[cfg(feature = "generators-sha224")] make_sha_mod! { sha224, Sha224, |buffer: String| { - let mut hasher = ::crypto::sha2::Sha224::new(); - hasher.input_str(&buffer); - Ok(String::from(hasher.result_str())) + use sha2::{Sha224, Digest}; + Ok(hex::encode(Sha224::digest(buffer.as_bytes()))) } } #[cfg(feature = "generators-sha256")] make_sha_mod! { sha256, Sha256, |buffer: String| { - let mut hasher = ::crypto::sha2::Sha256::new(); - hasher.input_str(&buffer); - Ok(String::from(hasher.result_str())) + use sha2::{Sha256, Digest}; + Ok(hex::encode(Sha256::digest(buffer.as_bytes()))) } } #[cfg(feature = "generators-sha384")] make_sha_mod! { sha384, Sha384, |buffer: String| { - let mut hasher = ::crypto::sha2::Sha384::new(); - hasher.input_str(&buffer); - Ok(String::from(hasher.result_str())) + use sha2::{Sha384, Digest}; + Ok(hex::encode(Sha384::digest(buffer.as_bytes()))) } } #[cfg(feature = "generators-sha512")] make_sha_mod! { sha512, Sha512, |buffer: String| { - let mut hasher = ::crypto::sha2::Sha512::new(); - hasher.input_str(&buffer); - Ok(String::from(hasher.result_str())) + use sha2::{Sha512, Digest}; + Ok(hex::encode(Sha512::digest(buffer.as_bytes()))) } } #[cfg(feature = "generators-sha3")] make_sha_mod! { sha3, Sha3, |buffer: String| { - let mut hasher = ::crypto::sha3::Sha3::sha3_256(); - hasher.input_str(&buffer); - Ok(String::from(hasher.result_str())) + use sha3::{Sha3_256, Digest}; + Ok(hex::encode(Sha3_256::digest(buffer.as_bytes()))) } } diff --git a/lib/entry/libimagentryref/src/lib.rs b/lib/entry/libimagentryref/src/lib.rs index a9656d92..d22c04a7 100644 --- a/lib/entry/libimagentryref/src/lib.rs +++ b/lib/entry/libimagentryref/src/lib.rs @@ -51,6 +51,20 @@ pub mod error; pub mod reference; pub mod refstore; +#[cfg(feature = "generators-sha1")] +extern crate sha1; + +#[cfg(any( + feature = "generators-sha224", + feature = "generators-sha256", + feature = "generators-sha384", + feature = "generators-sha512", +))] +extern crate sha2; + +#[cfg(feature = "generators-sha3")] +extern crate sha3; + #[cfg(any( feature = "generators-sha1", feature = "generators-sha224", @@ -59,7 +73,7 @@ pub mod refstore; feature = "generators-sha512", feature = "generators-sha3", ))] -extern crate crypto; +extern crate hex; #[cfg(feature = "generators")] pub mod generators;