summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-07-19 05:56:29 +0200
committerGitHub <noreply@github.com>2018-07-19 05:56:29 +0200
commit851db4abe4d8d0aebafe35ef41c5594213b1be6b (patch)
treee3a6b55de80df8e44b5ba075e055f415c6a3aec5
parente50204041566b0ae02526da4a3bb344f1e33ffd5 (diff)
parent04b3e7243d81b50e693a18f1cc4382e17251cc52 (diff)
downloadimag-851db4abe4d8d0aebafe35ef41c5594213b1be6b.zip
imag-851db4abe4d8d0aebafe35ef41c5594213b1be6b.tar.gz
Merge pull request #1500 from newpavlov/master
Replaced rust-crypto with RustCrypto crates
-rw-r--r--lib/entry/libimagentrylink/Cargo.toml3
-rw-r--r--lib/entry/libimagentrylink/src/external.rs10
-rw-r--r--lib/entry/libimagentrylink/src/lib.rs3
-rw-r--r--lib/entry/libimagentryref/Cargo.toml20
-rw-r--r--lib/entry/libimagentryref/src/generators/mod.rs34
-rw-r--r--lib/entry/libimagentryref/src/lib.rs16
6 files changed, 46 insertions, 40 deletions
diff --git a/lib/entry/libimagentrylink/Cargo.toml b/lib/entry/libimagentrylink/Cargo.toml
index c52d0c2..3b0029e 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 77a8184..b2b898b 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 788f8b3..366d53f 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 97ea47e..a23c13d 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 204ae08..23f12f5 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 a9656d9..d22c04a 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;