mirror of
https://github.com/mii443/merkle.rs.git
synced 2025-08-22 16:05:30 +00:00
Update dependencies
This commit is contained in:
39
.travis.yml
39
.travis.yml
@ -1,9 +1,15 @@
|
|||||||
language: rust
|
language: rust
|
||||||
|
|
||||||
|
# Need to cache the whole `.cargo` directory to keep .crates.toml for
|
||||||
|
# cargo-update to work
|
||||||
cache:
|
cache:
|
||||||
directories:
|
directories:
|
||||||
- $HOME/.cargo
|
|
||||||
- $HOME/protobuf
|
- $HOME/protobuf
|
||||||
- $TRAVIS_BUILD_DIR/target
|
- $HOME/.cargo
|
||||||
|
|
||||||
|
# But don't cache the cargo registry
|
||||||
|
before_cache:
|
||||||
|
- rm -rf $HOME/.cargo/registry
|
||||||
|
|
||||||
rust:
|
rust:
|
||||||
- stable
|
- stable
|
||||||
@ -21,23 +27,12 @@ matrix:
|
|||||||
- env: NAME='nightly'
|
- env: NAME='nightly'
|
||||||
rust: nightly
|
rust: nightly
|
||||||
|
|
||||||
- env:
|
- env: NAME='clippy'
|
||||||
- NAME='rustfmt'
|
rust: stable
|
||||||
- PROTOBUF_CODEGEN_VERSION=2.0.0
|
|
||||||
- PATH=$PATH:$HOME/.cargo/bin:$HOME/protobuf/bin
|
|
||||||
rust: nightly-2018-07-22
|
|
||||||
before_script:
|
before_script:
|
||||||
- rustup component add rustfmt-preview
|
- rustup component add clippy-preview
|
||||||
# Protoc plugin needed to generate proof.rs from proof.proto
|
|
||||||
- cargo install protobuf-codegen --version $PROTOBUF_CODEGEN_VERSION || echo "protobuf-codegen already installed"
|
|
||||||
# TODO: see if we can avoid installing protobuf-codegen and generating
|
|
||||||
# proof.rs in this build by using rustfmt options (see
|
|
||||||
# https://github.com/SpinResearch/merkle.rs/pull/38#issuecomment-391336829,
|
|
||||||
# paragraph 2).
|
|
||||||
- protoc --version
|
|
||||||
- protoc --rust_out src/proto/ protobuf/proof.proto
|
|
||||||
script:
|
script:
|
||||||
- cargo fmt --all -- --check
|
- cargo clippy --all-targets --all-features -- -D warnings
|
||||||
|
|
||||||
- env: NAME='kcov'
|
- env: NAME='kcov'
|
||||||
sudo: required # travis-ci/travis-ci#9061
|
sudo: required # travis-ci/travis-ci#9061
|
||||||
@ -58,13 +53,6 @@ matrix:
|
|||||||
- libiberty-dev
|
- libiberty-dev
|
||||||
- zlib1g-dev
|
- zlib1g-dev
|
||||||
|
|
||||||
- env: NAME='clippy'
|
|
||||||
rust: nightly-2018-07-22
|
|
||||||
before_script:
|
|
||||||
- rustup component add clippy-preview
|
|
||||||
script:
|
|
||||||
- cargo clippy --all --all-features -- -D clippy
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
- RUSTFLAGS="-C link-dead-code"
|
- RUSTFLAGS="-C link-dead-code"
|
||||||
@ -78,4 +66,5 @@ script:
|
|||||||
before_install:
|
before_install:
|
||||||
- export PATH=$PATH:$HOME/protobuf/bin
|
- export PATH=$PATH:$HOME/protobuf/bin
|
||||||
- export PROTOC_VERSION=$(cat PROTOC_VERSION)
|
- export PROTOC_VERSION=$(cat PROTOC_VERSION)
|
||||||
- bash install_protobuf.sh
|
- bash ci/install_protobuf.sh
|
||||||
|
|
||||||
|
13
Cargo.toml
13
Cargo.toml
@ -18,16 +18,16 @@ categories = ["data-structures", "cryptography"]
|
|||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ring = "^0.13.0"
|
ring = "^0.16.1"
|
||||||
protobuf = { version = "^2.0.2", optional = true }
|
protobuf = { version = "^2.8.0", optional = true }
|
||||||
serde = { version = "^1.0.55", optional = true }
|
serde = { version = "^1.0.97", optional = true }
|
||||||
serde_derive = { version = "^1.0.55", optional = true }
|
serde_derive = { version = "^1.0.97", optional = true }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
protoc-rust = { version = "^2.0.2", optional = true }
|
protoc-rust = { version = "^2.8.0", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde_json = "1.0.17"
|
serde_json = "1.0.40"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
serialization-protobuf = [ "protobuf", "protoc-rust" ]
|
serialization-protobuf = [ "protobuf", "protoc-rust" ]
|
||||||
@ -43,4 +43,3 @@ tag-message = "Release version {{version}}."
|
|||||||
doc-commit-message = "Update documentation."
|
doc-commit-message = "Update documentation."
|
||||||
dev-version-ext = "pre"
|
dev-version-ext = "pre"
|
||||||
|
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
libprotoc 3.5.1
|
3.7.1
|
||||||
|
9
build.rs
9
build.rs
@ -15,7 +15,8 @@ fn has_right_protoc_version(version: &str) -> bool {
|
|||||||
let version_output = protoc.wait_with_output().unwrap();
|
let version_output = protoc.wait_with_output().unwrap();
|
||||||
assert!(version_output.status.success());
|
assert!(version_output.status.success());
|
||||||
|
|
||||||
String::from_utf8(version_output.stdout).unwrap().trim() == version.trim()
|
let full_version = String::from_utf8(version_output.stdout).unwrap();
|
||||||
|
full_version.trim() == format!("libprotoc {}", version.trim())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "serialization-protobuf")]
|
#[cfg(feature = "serialization-protobuf")]
|
||||||
@ -26,7 +27,8 @@ fn build_protobuf(out_dir: &str, input: &[&str], includes: &[&str]) {
|
|||||||
input,
|
input,
|
||||||
includes,
|
includes,
|
||||||
customize: Default::default(),
|
customize: Default::default(),
|
||||||
}).expect("protoc");
|
})
|
||||||
|
.expect("protoc");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "serialization-protobuf")]
|
#[cfg(feature = "serialization-protobuf")]
|
||||||
@ -36,13 +38,14 @@ fn build_protobuf_schemata() {
|
|||||||
let mut version_string = String::new();
|
let mut version_string = String::new();
|
||||||
let mut version_pin =
|
let mut version_pin =
|
||||||
File::open("PROTOC_VERSION").expect("protoc version pin `PROTOC_VERSION` file is missing");
|
File::open("PROTOC_VERSION").expect("protoc version pin `PROTOC_VERSION` file is missing");
|
||||||
|
|
||||||
version_pin
|
version_pin
|
||||||
.read_to_string(&mut version_string)
|
.read_to_string(&mut version_string)
|
||||||
.expect("cannot read protoc pin file");
|
.expect("cannot read protoc pin file");
|
||||||
|
|
||||||
if !has_right_protoc_version(&version_string) {
|
if !has_right_protoc_version(&version_string) {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"Build failed because merkle.rs could not find: {}",
|
"Build failed because merkle.rs could not find protobuf version {}",
|
||||||
version_string
|
version_string
|
||||||
);
|
);
|
||||||
|
|
||||||
|
22
ci/install_protobuf.sh
Executable file
22
ci/install_protobuf.sh
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
PROTOC_VERSION=$(cat "$(dirname "$(dirname "$0")")/PROTOC_VERSION")
|
||||||
|
|
||||||
|
check_protoc_version () {
|
||||||
|
this_version=$(protoc --version)
|
||||||
|
return $([ "libprotoc $PROTOC_VERSION" = "$this_version" ])
|
||||||
|
}
|
||||||
|
|
||||||
|
if check_protoc_version; then
|
||||||
|
echo "[SUCCESS] protobuf version $PROTOC_VERSION detected."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[INFO] Installing protobuf $PROTOC_VERSION to $HOME/protobuf..."
|
||||||
|
|
||||||
|
cd "$TMPDIR"
|
||||||
|
wget "https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOC_VERSION/protoc-$PROTOC_VERSION-linux-x86_64.zip"
|
||||||
|
unzip -d "$HOME/protobuf" "protoc-$PROTOC_VERSION-linux-x86_64.zip"
|
||||||
|
|
||||||
|
echo "[SUCCESS] Done."
|
@ -1,18 +0,0 @@
|
|||||||
#!/usr/bin/bash
|
|
||||||
set -e
|
|
||||||
|
|
||||||
PROTOC_VERSION=$(cat PROTOC_VERSION)
|
|
||||||
|
|
||||||
check_protoc_version () {
|
|
||||||
this_version=`protoc --version`
|
|
||||||
return `[ "$PROTOC_VERSION" = "$this_version" ]`
|
|
||||||
}
|
|
||||||
|
|
||||||
if check_protoc_version; then
|
|
||||||
echo $PROTOC_VERSION detected.
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
wget https://github.com/google/protobuf/archive/v3.5.1.tar.gz
|
|
||||||
tar -xzvf v3.5.1.tar.gz
|
|
||||||
cd protobuf-3.5.1 && ./autogen.sh && ./configure --prefix=$HOME/protobuf && make && make install
|
|
27
src/proof.rs
27
src/proof.rs
@ -8,17 +8,11 @@ use tree::Tree;
|
|||||||
|
|
||||||
/// An inclusion proof represent the fact that a `value` is a member
|
/// An inclusion proof represent the fact that a `value` is a member
|
||||||
/// of a `MerkleTree` with root hash `root_hash`, and hash function `algorithm`.
|
/// of a `MerkleTree` with root hash `root_hash`, and hash function `algorithm`.
|
||||||
#[cfg_attr(
|
#[cfg_attr(feature = "serialization-serde", derive(Serialize, Deserialize))]
|
||||||
feature = "serialization-serde",
|
|
||||||
derive(Serialize, Deserialize)
|
|
||||||
)]
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Proof<T> {
|
pub struct Proof<T> {
|
||||||
/// The hashing algorithm used in the original `MerkleTree`
|
/// The hashing algorithm used in the original `MerkleTree`
|
||||||
#[cfg_attr(
|
#[cfg_attr(feature = "serialization-serde", serde(with = "algorithm_serde"))]
|
||||||
feature = "serialization-serde",
|
|
||||||
serde(with = "algorithm_serde")
|
|
||||||
)]
|
|
||||||
pub algorithm: &'static Algorithm,
|
pub algorithm: &'static Algorithm,
|
||||||
|
|
||||||
/// The hash of the root of the original `MerkleTree`
|
/// The hash of the root of the original `MerkleTree`
|
||||||
@ -48,7 +42,7 @@ mod algorithm_serde {
|
|||||||
pub fn deserialize<'de, D: Deserializer<'de>>(de: D) -> Result<&'static Algorithm, D::Error> {
|
pub fn deserialize<'de, D: Deserializer<'de>>(de: D) -> Result<&'static Algorithm, D::Error> {
|
||||||
let alg_str: String = Deserialize::deserialize(de)?;
|
let alg_str: String = Deserialize::deserialize(de)?;
|
||||||
match &*alg_str {
|
match &*alg_str {
|
||||||
"SHA1" => Ok(&digest::SHA1),
|
"SHA1" => Ok(&digest::SHA1_FOR_LEGACY_USE_ONLY),
|
||||||
"SHA256" => Ok(&digest::SHA256),
|
"SHA256" => Ok(&digest::SHA256),
|
||||||
"SHA384" => Ok(&digest::SHA384),
|
"SHA384" => Ok(&digest::SHA384),
|
||||||
"SHA512" => Ok(&digest::SHA512),
|
"SHA512" => Ok(&digest::SHA512),
|
||||||
@ -61,7 +55,7 @@ mod algorithm_serde {
|
|||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use ring::digest::{
|
use ring::digest::{
|
||||||
SHA1 as sha1, SHA256 as sha256, SHA384 as sha384, SHA512 as sha512,
|
SHA1_FOR_LEGACY_USE_ONLY as sha1, SHA256 as sha256, SHA384 as sha384, SHA512 as sha512,
|
||||||
SHA512_256 as sha512_256,
|
SHA512_256 as sha512_256,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -84,7 +78,8 @@ mod algorithm_serde {
|
|||||||
serialize(alg, &mut serializer).expect(&format!("{:?}", alg));
|
serialize(alg, &mut serializer).expect(&format!("{:?}", alg));
|
||||||
let alg_ = deserialize(&mut serde_json::Deserializer::from_slice(
|
let alg_ = deserialize(&mut serde_json::Deserializer::from_slice(
|
||||||
&serializer.into_inner()[..],
|
&serializer.into_inner()[..],
|
||||||
)).expect(&format!("{:?}", alg));
|
))
|
||||||
|
.expect(&format!("{:?}", alg));
|
||||||
|
|
||||||
assert_eq!(*alg, alg_);
|
assert_eq!(*alg, alg_);
|
||||||
}
|
}
|
||||||
@ -168,10 +163,7 @@ impl<T> Proof<T> {
|
|||||||
/// A `Lemma` holds the hash of a node, the hash of its sibling node,
|
/// A `Lemma` holds the hash of a node, the hash of its sibling node,
|
||||||
/// and a sub lemma, whose `node_hash`, when combined with this `sibling_hash`
|
/// and a sub lemma, whose `node_hash`, when combined with this `sibling_hash`
|
||||||
/// must be equal to this `node_hash`.
|
/// must be equal to this `node_hash`.
|
||||||
#[cfg_attr(
|
#[cfg_attr(feature = "serialization-serde", derive(Serialize, Deserialize))]
|
||||||
feature = "serialization-serde",
|
|
||||||
derive(Serialize, Deserialize)
|
|
||||||
)]
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct Lemma {
|
pub struct Lemma {
|
||||||
pub node_hash: Vec<u8>,
|
pub node_hash: Vec<u8>,
|
||||||
@ -327,10 +319,7 @@ impl Lemma {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Tags a value so that we know from which branch of a `Tree` (if any) it was found.
|
/// Tags a value so that we know from which branch of a `Tree` (if any) it was found.
|
||||||
#[cfg_attr(
|
#[cfg_attr(feature = "serialization-serde", derive(Serialize, Deserialize))]
|
||||||
feature = "serialization-serde",
|
|
||||||
derive(Serialize, Deserialize)
|
|
||||||
)]
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub enum Positioned<T> {
|
pub enum Positioned<T> {
|
||||||
/// The value was found in the left branch
|
/// The value was found in the left branch
|
||||||
|
Reference in New Issue
Block a user