Merge pull request #1500 from newpavlov/master

Replaced rust-crypto with RustCrypto crates
This commit is contained in:
Matthias Beyer 2018-07-19 05:56:29 +02:00 committed by GitHub
commit 851db4abe4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 46 additions and 40 deletions

View file

@ -24,7 +24,8 @@ itertools = "0.7"
log = "0.4.0" log = "0.4.0"
toml = "0.4" toml = "0.4"
url = "1.5" url = "1.5"
rust-crypto = "0.2" sha-1 = "0.7"
hex = "0.3"
is-match = "0.1" is-match = "0.1"
toml-query = "0.6" toml-query = "0.6"
error-chain = "0.11" error-chain = "0.11"

View file

@ -54,8 +54,8 @@ use self::iter::*;
use toml::Value; use toml::Value;
use url::Url; use url::Url;
use crypto::sha1::Sha1; use sha1::{Sha1, Digest};
use crypto::digest::Digest; use hex;
pub trait Link { pub trait Link {
@ -318,11 +318,7 @@ impl ExternalLinker for Entry {
debug!("Iterating {} links = {:?}", links.len(), links); debug!("Iterating {} links = {:?}", links.len(), links);
for link in links { // for all links for link in links { // for all links
let hash = { let hash = hex::encode(Sha1::digest(&link.as_str().as_bytes()));
let mut s = Sha1::new();
s.input_str(&link.as_str()[..]);
s.result_str()
};
let file_id = let file_id =
ModuleEntryPath::new(format!("external/{}", hash)).into_storeid() ModuleEntryPath::new(format!("external/{}", hash)).into_storeid()
.map_dbg_err(|_| { .map_dbg_err(|_| {

View file

@ -40,7 +40,8 @@ extern crate itertools;
extern crate toml; extern crate toml;
extern crate toml_query; extern crate toml_query;
extern crate url; extern crate url;
extern crate crypto; extern crate sha1;
extern crate hex;
#[macro_use] extern crate is_match; #[macro_use] extern crate is_match;
#[macro_use] extern crate error_chain; #[macro_use] extern crate error_chain;

View file

@ -25,22 +25,22 @@ log = "0.4.0"
toml = "0.4" toml = "0.4"
toml-query = "0.6" toml-query = "0.6"
error-chain = "0.11" 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" } libimagstore = { version = "0.9.0", path = "../../../lib/core/libimagstore" }
libimagerror = { version = "0.9.0", path = "../../../lib/core/libimagerror" } libimagerror = { version = "0.9.0", path = "../../../lib/core/libimagerror" }
libimagentryutil = { version = "0.9.0", path = "../../../lib/entry/libimagentryutil" } libimagentryutil = { version = "0.9.0", path = "../../../lib/entry/libimagentryutil" }
[dependencies.rust-crypto]
version = "0.2"
optional = true
[features] [features]
default = [] default = []
generators = [] generators = []
generators-sha1 = ["rust-crypto"] generators-sha1 = ["sha-1", "hex"]
generators-sha224 = ["rust-crypto"] generators-sha224 = ["sha2", "hex"]
generators-sha256 = ["rust-crypto"] generators-sha256 = ["sha2", "hex"]
generators-sha384 = ["rust-crypto"] generators-sha384 = ["sha2", "hex"]
generators-sha512 = ["rust-crypto"] generators-sha512 = ["sha2", "hex"]
generators-sha3 = ["rust-crypto"] generators-sha3 = ["sha3", "hex"]

View file

@ -175,7 +175,7 @@ macro_rules! make_sha_mod {
use error::RefError as RE; use error::RefError as RE;
use crypto::digest::Digest; use hex;
make_unique_ref_path_generator! ( make_unique_ref_path_generator! (
pub $hashname pub $hashname
over generators::base::Base over generators::base::Base
@ -235,59 +235,53 @@ macro_rules! make_sha_mod {
#[cfg(feature = "generators-sha1")] #[cfg(feature = "generators-sha1")]
make_sha_mod! { make_sha_mod! {
sha1, Sha1, |buffer: String| { sha1, Sha1, |buffer: String| {
let mut hasher = ::crypto::sha1::Sha1::new(); use sha1::{Sha1, Digest};
trace!("Hashing: '{:?}'", buffer); trace!("Hashing: '{:?}'", buffer);
hasher.input_str(&buffer); let res = hex::encode(Sha1::digest(buffer.as_bytes()));
let res = hasher.result_str();
trace!("Hash => '{:?}'", res); trace!("Hash => '{:?}'", res);
Ok(String::from(res)) Ok(res)
} }
} }
#[cfg(feature = "generators-sha224")] #[cfg(feature = "generators-sha224")]
make_sha_mod! { make_sha_mod! {
sha224, Sha224, |buffer: String| { sha224, Sha224, |buffer: String| {
let mut hasher = ::crypto::sha2::Sha224::new(); use sha2::{Sha224, Digest};
hasher.input_str(&buffer); Ok(hex::encode(Sha224::digest(buffer.as_bytes())))
Ok(String::from(hasher.result_str()))
} }
} }
#[cfg(feature = "generators-sha256")] #[cfg(feature = "generators-sha256")]
make_sha_mod! { make_sha_mod! {
sha256, Sha256, |buffer: String| { sha256, Sha256, |buffer: String| {
let mut hasher = ::crypto::sha2::Sha256::new(); use sha2::{Sha256, Digest};
hasher.input_str(&buffer); Ok(hex::encode(Sha256::digest(buffer.as_bytes())))
Ok(String::from(hasher.result_str()))
} }
} }
#[cfg(feature = "generators-sha384")] #[cfg(feature = "generators-sha384")]
make_sha_mod! { make_sha_mod! {
sha384, Sha384, |buffer: String| { sha384, Sha384, |buffer: String| {
let mut hasher = ::crypto::sha2::Sha384::new(); use sha2::{Sha384, Digest};
hasher.input_str(&buffer); Ok(hex::encode(Sha384::digest(buffer.as_bytes())))
Ok(String::from(hasher.result_str()))
} }
} }
#[cfg(feature = "generators-sha512")] #[cfg(feature = "generators-sha512")]
make_sha_mod! { make_sha_mod! {
sha512, Sha512, |buffer: String| { sha512, Sha512, |buffer: String| {
let mut hasher = ::crypto::sha2::Sha512::new(); use sha2::{Sha512, Digest};
hasher.input_str(&buffer); Ok(hex::encode(Sha512::digest(buffer.as_bytes())))
Ok(String::from(hasher.result_str()))
} }
} }
#[cfg(feature = "generators-sha3")] #[cfg(feature = "generators-sha3")]
make_sha_mod! { make_sha_mod! {
sha3, Sha3, |buffer: String| { sha3, Sha3, |buffer: String| {
let mut hasher = ::crypto::sha3::Sha3::sha3_256(); use sha3::{Sha3_256, Digest};
hasher.input_str(&buffer); Ok(hex::encode(Sha3_256::digest(buffer.as_bytes())))
Ok(String::from(hasher.result_str()))
} }
} }

View file

@ -51,6 +51,20 @@ pub mod error;
pub mod reference; pub mod reference;
pub mod refstore; 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( #[cfg(any(
feature = "generators-sha1", feature = "generators-sha1",
feature = "generators-sha224", feature = "generators-sha224",
@ -59,7 +73,7 @@ pub mod refstore;
feature = "generators-sha512", feature = "generators-sha512",
feature = "generators-sha3", feature = "generators-sha3",
))] ))]
extern crate crypto; extern crate hex;
#[cfg(feature = "generators")] #[cfg(feature = "generators")]
pub mod generators; pub mod generators;