From a8c9733f95d7b58b411d8d28bba7b9ef1a801354 Mon Sep 17 00:00:00 2001 From: librelois <elois@ifee.fr> Date: Fri, 30 Mar 2018 17:34:37 +0200 Subject: [PATCH] [fix] #27 --- Cargo.lock | 2 +- crypto/keys/ed25519.rs | 9 +++++++++ documents/Cargo.toml | 2 +- documents/blockchain/mod.rs | 2 +- documents/blockchain/v10/documents/identity.rs | 4 ++-- documents/blockchain/v10/documents/membership.rs | 6 +++--- documents/lib.rs | 8 ++++---- 7 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 57ecf460..9648b789 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -94,7 +94,7 @@ dependencies = [ [[package]] name = "duniter-documents" -version = "0.4.1" +version = "0.5.0" dependencies = [ "base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "base64 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/crypto/keys/ed25519.rs b/crypto/keys/ed25519.rs index 1d3e50a0..2ed60366 100644 --- a/crypto/keys/ed25519.rs +++ b/crypto/keys/ed25519.rs @@ -19,10 +19,12 @@ //! //! [`KeyPairGenerator`]: struct.KeyPairGenerator.html +use std::collections::hash_map::DefaultHasher; use std::fmt::Display; use std::fmt::Error; use std::fmt::Formatter; use std::fmt::Debug; +use std::hash::{Hash, Hasher}; use base58::{FromBase58, FromBase58Error, ToBase58}; use base64; @@ -35,6 +37,13 @@ use super::{BaseConvertionError, PrivateKey as PrivateKeyMethods, PublicKey as P #[derive(Clone, Copy)] pub struct Signature(pub [u8; 64]); +impl Hash for Signature { + fn hash<H: Hasher>(&self, _state: &mut H) { + let mut hasher = DefaultHasher::new(); + Hash::hash_slice(&self.0, &mut hasher); + } +} + impl super::Signature for Signature { fn from_base64(base64_data: &str) -> Result<Signature, BaseConvertionError> { match base64::decode(base64_data) { diff --git a/documents/Cargo.toml b/documents/Cargo.toml index c43678b6..2a42d7fd 100644 --- a/documents/Cargo.toml +++ b/documents/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "duniter-documents" -version = "0.4.1" +version = "0.5.0" authors = ["nanocryk <nanocryk@duniter.org>", "elois <elois@ifee.fr>"] description = "Handles Duniter documents" repository = "https://git.duniter.org/nodes/rust/duniter-rs" diff --git a/documents/blockchain/mod.rs b/documents/blockchain/mod.rs index 5f997b0c..97e35dd8 100644 --- a/documents/blockchain/mod.rs +++ b/documents/blockchain/mod.rs @@ -25,7 +25,7 @@ pub mod v10; #[derive(Debug)] pub enum BlockchainProtocol { /// Version 10. - V10(v10::documents::V10Document), + V10(Box<v10::documents::V10Document>), /// Version 11. (not done yet, but defined for tests) V11(), } diff --git a/documents/blockchain/v10/documents/identity.rs b/documents/blockchain/v10/documents/identity.rs index 05762ee5..ac7622ec 100644 --- a/documents/blockchain/v10/documents/identity.rs +++ b/documents/blockchain/v10/documents/identity.rs @@ -32,7 +32,7 @@ lazy_static! { /// Wrap an Identity document. /// /// Must be created by parsing a text document or using a builder. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Hash)] pub struct IdentityDocument { /// Document as text. /// @@ -92,7 +92,7 @@ impl TextDocument for IdentityDocument { impl IntoSpecializedDocument<BlockchainProtocol> for IdentityDocument { fn into_specialized(self) -> BlockchainProtocol { - BlockchainProtocol::V10(V10Document::Identity(self)) + BlockchainProtocol::V10(Box::new(V10Document::Identity(self))) } } diff --git a/documents/blockchain/v10/documents/membership.rs b/documents/blockchain/v10/documents/membership.rs index fb1d2d12..0fab5443 100644 --- a/documents/blockchain/v10/documents/membership.rs +++ b/documents/blockchain/v10/documents/membership.rs @@ -34,7 +34,7 @@ lazy_static! { } /// Type of a Membership. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq, Hash)] pub enum MembershipType { /// The member wishes to opt-in. In(), @@ -45,7 +45,7 @@ pub enum MembershipType { /// Wrap an Membership document. /// /// Must be created by parsing a text document or using a builder. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Hash)] pub struct MembershipDocument { /// Document as text. /// @@ -113,7 +113,7 @@ impl TextDocument for MembershipDocument { impl IntoSpecializedDocument<BlockchainProtocol> for MembershipDocument { fn into_specialized(self) -> BlockchainProtocol { - BlockchainProtocol::V10(V10Document::Membership(self)) + BlockchainProtocol::V10(Box::new(V10Document::Membership(self))) } } diff --git a/documents/lib.rs b/documents/lib.rs index e3d8b381..d445c12f 100644 --- a/documents/lib.rs +++ b/documents/lib.rs @@ -36,7 +36,7 @@ use duniter_crypto::keys::BaseConvertionError; pub mod blockchain; /// A block Id. -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub struct BlockId(pub u32); impl Display for BlockId { @@ -48,7 +48,7 @@ impl Display for BlockId { /// A hash wrapper. /// /// A hash is often provided as string composed of 64 hexadecimal character (0 to 9 then A to F). -#[derive(Copy, Clone, PartialEq, Eq)] +#[derive(Copy, Clone, PartialEq, Eq, Hash)] pub struct Hash(pub [u8; 32]); impl Display for Hash { @@ -110,7 +110,7 @@ impl Hash { } /// Wrapper of a block hash. -#[derive(Copy, Clone, PartialEq, Eq)] +#[derive(Copy, Clone, PartialEq, Eq, Hash)] pub struct BlockHash(Hash); impl Display for BlockHash { @@ -148,7 +148,7 @@ pub enum BlockUIdParseError { /// /// [`BlockId`]: struct.BlockId.html /// [`BlockHash`]: struct.BlockHash.html -#[derive(Copy, Clone, PartialEq, Eq)] +#[derive(Copy, Clone, PartialEq, Eq, Hash)] pub struct Blockstamp { /// Block Id. pub id: BlockId, -- GitLab