From 011c10cd81c2cd21149e8d9fb1056d78a714f2f5 Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Mon, 21 Nov 2016 22:22:08 +0100 Subject: [PATCH] Add `value` back to `Proof`. --- protobuf/proof.proto | 1 + src/merkletree.rs | 4 +- src/proof.rs | 9 ++- src/proto/mod.rs | 28 +++++--- src/proto/proof.rs | 150 ++++++++++++++++++++++++++++++------------- src/tests.rs | 6 +- 6 files changed, 135 insertions(+), 63 deletions(-) diff --git a/protobuf/proof.proto b/protobuf/proof.proto index 8521e92..36a119f 100644 --- a/protobuf/proof.proto +++ b/protobuf/proof.proto @@ -4,6 +4,7 @@ syntax = "proto3"; message ProofProto { bytes root_hash = 1; LemmaProto lemma = 2; + bytes value = 3; } message LemmaProto { diff --git a/src/merkletree.rs b/src/merkletree.rs index b9c700c..d6b53eb 100644 --- a/src/merkletree.rs +++ b/src/merkletree.rs @@ -112,13 +112,13 @@ impl MerkleTree where D: Digest + Clone, T: Into> + Clone { /// Generate an inclusion proof for the given value. /// Returns `None` if the given value is not found in the tree. - pub fn gen_proof(&self, value: &T) -> Option> { + pub fn gen_proof(&self, value: T) -> Option> { let mut digest = self.digest.clone(); let root_hash = self.root_hash().clone(); let node_hash = digest.hash_bytes(&value.clone().into()); Lemma::new(&self.root, &node_hash).map(|lemma| - Proof::new(digest, root_hash, lemma) + Proof::new(digest, root_hash, lemma, value) ) } diff --git a/src/proof.rs b/src/proof.rs index c24e022..357b5ef 100644 --- a/src/proof.rs +++ b/src/proof.rs @@ -1,6 +1,4 @@ -use std::marker::PhantomData; - use crypto::digest::Digest; use tree::Tree; @@ -20,18 +18,19 @@ pub struct Proof { /// The first `Lemma` of the `Proof` pub lemma: Lemma, - _value_marker: PhantomData + /// The value concerned by this `Proof` + pub value: T } impl Proof { /// Constructs a new `Proof` - pub fn new(digest: D, root_hash: Vec, lemma: Lemma) -> Self { + pub fn new(digest: D, root_hash: Vec, lemma: Lemma, value: T) -> Self { Proof { digest: digest, root_hash: root_hash, lemma: lemma, - _value_marker: PhantomData + value: value } } diff --git a/src/proto/mod.rs b/src/proto/mod.rs index 8798791..6870f26 100644 --- a/src/proto/mod.rs +++ b/src/proto/mod.rs @@ -11,22 +11,28 @@ use protobuf::core::parse_from_bytes; impl Proof { /// Constructs a `Proof` struct from its Protobuf representation. - pub fn from_protobuf(digest: D, proto: ProofProto) -> Option { + pub fn from_protobuf(digest: D, proto: ProofProto) -> Option + where T: From> + { proto.into_proof(digest) } /// Encode this `Proof` to its Protobuf representation. - pub fn into_protobuf(self) -> ProofProto { + pub fn into_protobuf(self) -> ProofProto + where T: Into> + { ProofProto::from_proof(self) } /// Parse a `Proof` from its Protobuf binary representation. - pub fn parse_from_bytes(bytes: &[u8], digest: D) -> ProtobufResult>> { + pub fn parse_from_bytes(bytes: &[u8], digest: D) -> ProtobufResult>> + where T: From> + { parse_from_bytes::(bytes).map(|proto| proto.into_proof(digest)) } /// Serialize this `Proof` with Protobuf. - pub fn write_to_bytes(self) -> ProtobufResult> { + pub fn write_to_bytes(self) -> ProtobufResult> where T: Into> { self.into_protobuf().write_to_bytes() } @@ -34,20 +40,25 @@ impl Proof { impl ProofProto { - pub fn from_proof(proof: Proof) -> Self { + pub fn from_proof(proof: Proof) -> Self + where T: Into> + { let mut proto = Self::new(); match proof { - Proof { root_hash, lemma, .. } => { + Proof { root_hash, lemma, value, .. } => { proto.set_root_hash(root_hash); proto.set_lemma(LemmaProto::from_lemma(lemma)); + proto.set_value(value.into()); } } proto } - pub fn into_proof(mut self, digest: D) -> Option> { + pub fn into_proof(mut self, digest: D) -> Option> + where T: From> + { if !self.has_root_hash() || !self.has_lemma() { return None; } @@ -56,7 +67,8 @@ impl ProofProto { Proof::new( digest, self.take_root_hash(), - lemma + lemma, + self.take_value().into() ) }) } diff --git a/src/proto/proof.rs b/src/proto/proof.rs index 2855b8e..4b04a9e 100644 --- a/src/proto/proof.rs +++ b/src/proto/proof.rs @@ -25,6 +25,7 @@ pub struct ProofProto { // message fields root_hash: ::protobuf::SingularField<::std::vec::Vec>, lemma: ::protobuf::SingularPtrField, + value: ::protobuf::SingularField<::std::vec::Vec>, // special fields unknown_fields: ::protobuf::UnknownFields, cached_size: ::std::cell::Cell, @@ -48,6 +49,7 @@ impl ProofProto { ProofProto { root_hash: ::protobuf::SingularField::none(), lemma: ::protobuf::SingularPtrField::none(), + value: ::protobuf::SingularField::none(), unknown_fields: ::protobuf::UnknownFields::new(), cached_size: ::std::cell::Cell::new(0), } @@ -123,6 +125,42 @@ impl ProofProto { pub fn get_lemma(&self) -> &LemmaProto { self.lemma.as_ref().unwrap_or_else(|| LemmaProto::default_instance()) } + + // optional bytes value = 3; + + pub fn clear_value(&mut self) { + self.value.clear(); + } + + pub fn has_value(&self) -> bool { + self.value.is_some() + } + + // Param is passed by value, moved + pub fn set_value(&mut self, v: ::std::vec::Vec) { + self.value = ::protobuf::SingularField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_value(&mut self) -> &mut ::std::vec::Vec { + if self.value.is_none() { + self.value.set_default(); + }; + self.value.as_mut().unwrap() + } + + // Take field + pub fn take_value(&mut self) -> ::std::vec::Vec { + self.value.take().unwrap_or_else(|| ::std::vec::Vec::new()) + } + + pub fn get_value(&self) -> &[u8] { + match self.value.as_ref() { + Some(v) => &v, + None => &[], + } + } } impl ::protobuf::Message for ProofProto { @@ -140,6 +178,9 @@ impl ::protobuf::Message for ProofProto { 2 => { try!(::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.lemma)); }, + 3 => { + try!(::protobuf::rt::read_singular_bytes_into(wire_type, is, &mut self.value)); + }, _ => { try!(::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())); }, @@ -159,6 +200,9 @@ impl ::protobuf::Message for ProofProto { let len = value.compute_size(); my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; }; + for value in &self.value { + my_size += ::protobuf::rt::bytes_size(3, &value); + }; my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); self.cached_size.set(my_size); my_size @@ -173,6 +217,9 @@ impl ::protobuf::Message for ProofProto { try!(os.write_raw_varint32(v.get_cached_size())); try!(v.write_to_with_cached_sizes(os)); }; + if let Some(v) = self.value.as_ref() { + try!(os.write_bytes(3, &v)); + }; try!(os.write_unknown_fields(self.get_unknown_fields())); ::std::result::Result::Ok(()) } @@ -225,6 +272,11 @@ impl ::protobuf::MessageStatic for ProofProto { ProofProto::has_lemma, ProofProto::get_lemma, )); + fields.push(::protobuf::reflect::accessor::make_singular_bytes_accessor( + "value", + ProofProto::has_value, + ProofProto::get_value, + )); ::protobuf::reflect::MessageDescriptor::new::( "ProofProto", fields, @@ -239,6 +291,7 @@ impl ::protobuf::Clear for ProofProto { fn clear(&mut self) { self.clear_root_hash(); self.clear_lemma(); + self.clear_value(); self.unknown_fields.clear(); } } @@ -247,6 +300,7 @@ impl ::std::cmp::PartialEq for ProofProto { fn eq(&self, other: &ProofProto) -> bool { self.root_hash == other.root_hash && self.lemma == other.lemma && + self.value == other.value && self.unknown_fields == other.unknown_fields } } @@ -650,55 +704,61 @@ impl ::std::fmt::Debug for LemmaProto { static file_descriptor_proto_data: &'static [u8] = &[ 0x0a, 0x14, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x70, 0x72, 0x6f, 0x6f, 0x66, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x4c, 0x0a, 0x0a, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x50, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x62, 0x0a, 0x0a, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x1b, 0x0a, 0x09, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x72, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, 0x21, 0x0a, 0x05, 0x6c, 0x65, 0x6d, 0x6d, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x4c, 0x65, 0x6d, 0x6d, 0x61, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x52, 0x05, 0x6c, - 0x65, 0x6d, 0x6d, 0x61, 0x22, 0xc1, 0x01, 0x0a, 0x0a, 0x4c, 0x65, 0x6d, 0x6d, 0x61, 0x50, 0x72, - 0x6f, 0x74, 0x6f, 0x12, 0x1b, 0x0a, 0x09, 0x6e, 0x6f, 0x64, 0x65, 0x5f, 0x68, 0x61, 0x73, 0x68, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x6e, 0x6f, 0x64, 0x65, 0x48, 0x61, 0x73, 0x68, - 0x12, 0x28, 0x0a, 0x09, 0x73, 0x75, 0x62, 0x5f, 0x6c, 0x65, 0x6d, 0x6d, 0x61, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x4c, 0x65, 0x6d, 0x6d, 0x61, 0x50, 0x72, 0x6f, 0x74, 0x6f, - 0x52, 0x08, 0x73, 0x75, 0x62, 0x4c, 0x65, 0x6d, 0x6d, 0x61, 0x12, 0x2c, 0x0a, 0x11, 0x6c, 0x65, - 0x66, 0x74, 0x5f, 0x73, 0x69, 0x62, 0x6c, 0x69, 0x6e, 0x67, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x00, 0x52, 0x0f, 0x6c, 0x65, 0x66, 0x74, 0x53, 0x69, 0x62, - 0x6c, 0x69, 0x6e, 0x67, 0x48, 0x61, 0x73, 0x68, 0x12, 0x2e, 0x0a, 0x12, 0x72, 0x69, 0x67, 0x68, - 0x74, 0x5f, 0x73, 0x69, 0x62, 0x6c, 0x69, 0x6e, 0x67, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x04, - 0x20, 0x01, 0x28, 0x0c, 0x48, 0x00, 0x52, 0x10, 0x72, 0x69, 0x67, 0x68, 0x74, 0x53, 0x69, 0x62, - 0x6c, 0x69, 0x6e, 0x67, 0x48, 0x61, 0x73, 0x68, 0x42, 0x0e, 0x0a, 0x0c, 0x73, 0x69, 0x62, 0x6c, - 0x69, 0x6e, 0x67, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x4a, 0xe4, 0x03, 0x0a, 0x06, 0x12, 0x04, 0x01, - 0x00, 0x11, 0x01, 0x0a, 0x08, 0x0a, 0x01, 0x0c, 0x12, 0x03, 0x01, 0x00, 0x12, 0x0a, 0x0a, 0x0a, - 0x02, 0x04, 0x00, 0x12, 0x04, 0x03, 0x00, 0x06, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x00, 0x01, - 0x12, 0x03, 0x03, 0x08, 0x12, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x00, 0x02, 0x00, 0x12, 0x03, 0x04, - 0x02, 0x16, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x04, 0x12, 0x04, 0x04, 0x02, 0x03, - 0x14, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x05, 0x12, 0x03, 0x04, 0x02, 0x07, 0x0a, - 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x01, 0x12, 0x03, 0x04, 0x08, 0x11, 0x0a, 0x0c, 0x0a, - 0x05, 0x04, 0x00, 0x02, 0x00, 0x03, 0x12, 0x03, 0x04, 0x14, 0x15, 0x0a, 0x0b, 0x0a, 0x04, 0x04, - 0x00, 0x02, 0x01, 0x12, 0x03, 0x05, 0x02, 0x17, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x01, - 0x04, 0x12, 0x04, 0x05, 0x02, 0x04, 0x16, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x01, 0x06, - 0x12, 0x03, 0x05, 0x02, 0x0c, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x01, 0x01, 0x12, 0x03, - 0x05, 0x0d, 0x12, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x01, 0x03, 0x12, 0x03, 0x05, 0x15, - 0x16, 0x0a, 0x0a, 0x0a, 0x02, 0x04, 0x01, 0x12, 0x04, 0x08, 0x00, 0x11, 0x01, 0x0a, 0x0a, 0x0a, - 0x03, 0x04, 0x01, 0x01, 0x12, 0x03, 0x08, 0x08, 0x12, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x01, 0x02, - 0x00, 0x12, 0x03, 0x09, 0x02, 0x16, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x00, 0x04, 0x12, - 0x04, 0x09, 0x02, 0x08, 0x14, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x00, 0x05, 0x12, 0x03, - 0x09, 0x02, 0x07, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x00, 0x01, 0x12, 0x03, 0x09, 0x08, - 0x11, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x00, 0x03, 0x12, 0x03, 0x09, 0x14, 0x15, 0x0a, - 0x0b, 0x0a, 0x04, 0x04, 0x01, 0x02, 0x01, 0x12, 0x03, 0x0a, 0x02, 0x1b, 0x0a, 0x0d, 0x0a, 0x05, - 0x04, 0x01, 0x02, 0x01, 0x04, 0x12, 0x04, 0x0a, 0x02, 0x09, 0x16, 0x0a, 0x0c, 0x0a, 0x05, 0x04, - 0x01, 0x02, 0x01, 0x06, 0x12, 0x03, 0x0a, 0x02, 0x0c, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, - 0x01, 0x01, 0x12, 0x03, 0x0a, 0x0d, 0x16, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x01, 0x03, - 0x12, 0x03, 0x0a, 0x19, 0x1a, 0x0a, 0x0c, 0x0a, 0x04, 0x04, 0x01, 0x08, 0x00, 0x12, 0x04, 0x0c, - 0x02, 0x0f, 0x03, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x08, 0x00, 0x01, 0x12, 0x03, 0x0c, 0x08, - 0x14, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x01, 0x02, 0x02, 0x12, 0x03, 0x0d, 0x04, 0x20, 0x0a, 0x0c, - 0x0a, 0x05, 0x04, 0x01, 0x02, 0x02, 0x05, 0x12, 0x03, 0x0d, 0x04, 0x09, 0x0a, 0x0c, 0x0a, 0x05, - 0x04, 0x01, 0x02, 0x02, 0x01, 0x12, 0x03, 0x0d, 0x0a, 0x1b, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, - 0x02, 0x02, 0x03, 0x12, 0x03, 0x0d, 0x1e, 0x1f, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x01, 0x02, 0x03, - 0x12, 0x03, 0x0e, 0x04, 0x21, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x03, 0x05, 0x12, 0x03, - 0x0e, 0x04, 0x09, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x03, 0x01, 0x12, 0x03, 0x0e, 0x0a, - 0x1c, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x03, 0x03, 0x12, 0x03, 0x0e, 0x1f, 0x20, 0x62, - 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x6d, 0x6d, 0x61, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0xc1, 0x01, 0x0a, 0x0a, 0x4c, + 0x65, 0x6d, 0x6d, 0x61, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x1b, 0x0a, 0x09, 0x6e, 0x6f, 0x64, + 0x65, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x6e, 0x6f, + 0x64, 0x65, 0x48, 0x61, 0x73, 0x68, 0x12, 0x28, 0x0a, 0x09, 0x73, 0x75, 0x62, 0x5f, 0x6c, 0x65, + 0x6d, 0x6d, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x4c, 0x65, 0x6d, 0x6d, + 0x61, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x52, 0x08, 0x73, 0x75, 0x62, 0x4c, 0x65, 0x6d, 0x6d, 0x61, + 0x12, 0x2c, 0x0a, 0x11, 0x6c, 0x65, 0x66, 0x74, 0x5f, 0x73, 0x69, 0x62, 0x6c, 0x69, 0x6e, 0x67, + 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x00, 0x52, 0x0f, 0x6c, + 0x65, 0x66, 0x74, 0x53, 0x69, 0x62, 0x6c, 0x69, 0x6e, 0x67, 0x48, 0x61, 0x73, 0x68, 0x12, 0x2e, + 0x0a, 0x12, 0x72, 0x69, 0x67, 0x68, 0x74, 0x5f, 0x73, 0x69, 0x62, 0x6c, 0x69, 0x6e, 0x67, 0x5f, + 0x68, 0x61, 0x73, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x00, 0x52, 0x10, 0x72, 0x69, + 0x67, 0x68, 0x74, 0x53, 0x69, 0x62, 0x6c, 0x69, 0x6e, 0x67, 0x48, 0x61, 0x73, 0x68, 0x42, 0x0e, + 0x0a, 0x0c, 0x73, 0x69, 0x62, 0x6c, 0x69, 0x6e, 0x67, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x4a, 0xaa, + 0x04, 0x0a, 0x06, 0x12, 0x04, 0x01, 0x00, 0x12, 0x01, 0x0a, 0x08, 0x0a, 0x01, 0x0c, 0x12, 0x03, + 0x01, 0x00, 0x12, 0x0a, 0x0a, 0x0a, 0x02, 0x04, 0x00, 0x12, 0x04, 0x03, 0x00, 0x07, 0x01, 0x0a, + 0x0a, 0x0a, 0x03, 0x04, 0x00, 0x01, 0x12, 0x03, 0x03, 0x08, 0x12, 0x0a, 0x0b, 0x0a, 0x04, 0x04, + 0x00, 0x02, 0x00, 0x12, 0x03, 0x04, 0x02, 0x16, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, + 0x04, 0x12, 0x04, 0x04, 0x02, 0x03, 0x14, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x05, + 0x12, 0x03, 0x04, 0x02, 0x07, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x01, 0x12, 0x03, + 0x04, 0x08, 0x11, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x03, 0x12, 0x03, 0x04, 0x14, + 0x15, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x00, 0x02, 0x01, 0x12, 0x03, 0x05, 0x02, 0x17, 0x0a, 0x0d, + 0x0a, 0x05, 0x04, 0x00, 0x02, 0x01, 0x04, 0x12, 0x04, 0x05, 0x02, 0x04, 0x16, 0x0a, 0x0c, 0x0a, + 0x05, 0x04, 0x00, 0x02, 0x01, 0x06, 0x12, 0x03, 0x05, 0x02, 0x0c, 0x0a, 0x0c, 0x0a, 0x05, 0x04, + 0x00, 0x02, 0x01, 0x01, 0x12, 0x03, 0x05, 0x0d, 0x12, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, + 0x01, 0x03, 0x12, 0x03, 0x05, 0x15, 0x16, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x00, 0x02, 0x02, 0x12, + 0x03, 0x06, 0x02, 0x12, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x02, 0x04, 0x12, 0x04, 0x06, + 0x02, 0x05, 0x17, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x02, 0x05, 0x12, 0x03, 0x06, 0x02, + 0x07, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x02, 0x01, 0x12, 0x03, 0x06, 0x08, 0x0d, 0x0a, + 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x02, 0x03, 0x12, 0x03, 0x06, 0x10, 0x11, 0x0a, 0x0a, 0x0a, + 0x02, 0x04, 0x01, 0x12, 0x04, 0x09, 0x00, 0x12, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x01, 0x01, + 0x12, 0x03, 0x09, 0x08, 0x12, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x01, 0x02, 0x00, 0x12, 0x03, 0x0a, + 0x02, 0x16, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x00, 0x04, 0x12, 0x04, 0x0a, 0x02, 0x09, + 0x14, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x00, 0x05, 0x12, 0x03, 0x0a, 0x02, 0x07, 0x0a, + 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x00, 0x01, 0x12, 0x03, 0x0a, 0x08, 0x11, 0x0a, 0x0c, 0x0a, + 0x05, 0x04, 0x01, 0x02, 0x00, 0x03, 0x12, 0x03, 0x0a, 0x14, 0x15, 0x0a, 0x0b, 0x0a, 0x04, 0x04, + 0x01, 0x02, 0x01, 0x12, 0x03, 0x0b, 0x02, 0x1b, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x01, + 0x04, 0x12, 0x04, 0x0b, 0x02, 0x0a, 0x16, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x01, 0x06, + 0x12, 0x03, 0x0b, 0x02, 0x0c, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x01, 0x01, 0x12, 0x03, + 0x0b, 0x0d, 0x16, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x01, 0x03, 0x12, 0x03, 0x0b, 0x19, + 0x1a, 0x0a, 0x0c, 0x0a, 0x04, 0x04, 0x01, 0x08, 0x00, 0x12, 0x04, 0x0d, 0x02, 0x10, 0x03, 0x0a, + 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x08, 0x00, 0x01, 0x12, 0x03, 0x0d, 0x08, 0x14, 0x0a, 0x0b, 0x0a, + 0x04, 0x04, 0x01, 0x02, 0x02, 0x12, 0x03, 0x0e, 0x04, 0x20, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, + 0x02, 0x02, 0x05, 0x12, 0x03, 0x0e, 0x04, 0x09, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x02, + 0x01, 0x12, 0x03, 0x0e, 0x0a, 0x1b, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x02, 0x03, 0x12, + 0x03, 0x0e, 0x1e, 0x1f, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x01, 0x02, 0x03, 0x12, 0x03, 0x0f, 0x04, + 0x21, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x03, 0x05, 0x12, 0x03, 0x0f, 0x04, 0x09, 0x0a, + 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x03, 0x01, 0x12, 0x03, 0x0f, 0x0a, 0x1c, 0x0a, 0x0c, 0x0a, + 0x05, 0x04, 0x01, 0x02, 0x03, 0x03, 0x12, 0x03, 0x0f, 0x1f, 0x20, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, ]; static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { diff --git a/src/tests.rs b/src/tests.rs index 4508dd6..51e924a 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -108,7 +108,7 @@ fn test_valid_proof() { let tree = MerkleTree::from_vec_unsafe(Sha3::sha3_256(), values.clone()); let root_hash = tree.root_hash(); - for value in values.iter() { + for value in values { let proof = tree.gen_proof(value); let is_valid = proof.map(|p| p.validate(&root_hash)).unwrap_or(false); @@ -140,7 +140,7 @@ fn test_wrong_proof() { let root_hash = tree2.root_hash(); - for value in values1.iter() { + for value in values1 { let proof = tree1.gen_proof(value); let is_valid = proof.map(|p| p.validate(root_hash)).unwrap_or(false); @@ -156,7 +156,7 @@ fn test_mutate_proof_first_lemma() { let mut i = 0; - for value in values.iter() { + for value in values { let mut proof = tree.gen_proof(value).unwrap(); match i % 3 {