Skip to content
Snippets Groups Projects
Commit a8c9733f authored by Éloïs's avatar Éloïs
Browse files

[fix] #27

parent 49ea38c3
No related branches found
No related tags found
No related merge requests found
...@@ -94,7 +94,7 @@ dependencies = [ ...@@ -94,7 +94,7 @@ dependencies = [
[[package]] [[package]]
name = "duniter-documents" name = "duniter-documents"
version = "0.4.1" version = "0.5.0"
dependencies = [ dependencies = [
"base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "base64 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
......
...@@ -19,10 +19,12 @@ ...@@ -19,10 +19,12 @@
//! //!
//! [`KeyPairGenerator`]: struct.KeyPairGenerator.html //! [`KeyPairGenerator`]: struct.KeyPairGenerator.html
use std::collections::hash_map::DefaultHasher;
use std::fmt::Display; use std::fmt::Display;
use std::fmt::Error; use std::fmt::Error;
use std::fmt::Formatter; use std::fmt::Formatter;
use std::fmt::Debug; use std::fmt::Debug;
use std::hash::{Hash, Hasher};
use base58::{FromBase58, FromBase58Error, ToBase58}; use base58::{FromBase58, FromBase58Error, ToBase58};
use base64; use base64;
...@@ -35,6 +37,13 @@ use super::{BaseConvertionError, PrivateKey as PrivateKeyMethods, PublicKey as P ...@@ -35,6 +37,13 @@ use super::{BaseConvertionError, PrivateKey as PrivateKeyMethods, PublicKey as P
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub struct Signature(pub [u8; 64]); 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 { impl super::Signature for Signature {
fn from_base64(base64_data: &str) -> Result<Signature, BaseConvertionError> { fn from_base64(base64_data: &str) -> Result<Signature, BaseConvertionError> {
match base64::decode(base64_data) { match base64::decode(base64_data) {
......
[package] [package]
name = "duniter-documents" name = "duniter-documents"
version = "0.4.1" version = "0.5.0"
authors = ["nanocryk <nanocryk@duniter.org>", "elois <elois@ifee.fr>"] authors = ["nanocryk <nanocryk@duniter.org>", "elois <elois@ifee.fr>"]
description = "Handles Duniter documents" description = "Handles Duniter documents"
repository = "https://git.duniter.org/nodes/rust/duniter-rs" repository = "https://git.duniter.org/nodes/rust/duniter-rs"
......
...@@ -25,7 +25,7 @@ pub mod v10; ...@@ -25,7 +25,7 @@ pub mod v10;
#[derive(Debug)] #[derive(Debug)]
pub enum BlockchainProtocol { pub enum BlockchainProtocol {
/// Version 10. /// Version 10.
V10(v10::documents::V10Document), V10(Box<v10::documents::V10Document>),
/// Version 11. (not done yet, but defined for tests) /// Version 11. (not done yet, but defined for tests)
V11(), V11(),
} }
......
...@@ -32,7 +32,7 @@ lazy_static! { ...@@ -32,7 +32,7 @@ lazy_static! {
/// Wrap an Identity document. /// Wrap an Identity document.
/// ///
/// Must be created by parsing a text document or using a builder. /// Must be created by parsing a text document or using a builder.
#[derive(Debug, Clone)] #[derive(Debug, Clone, PartialEq, Hash)]
pub struct IdentityDocument { pub struct IdentityDocument {
/// Document as text. /// Document as text.
/// ///
...@@ -92,7 +92,7 @@ impl TextDocument for IdentityDocument { ...@@ -92,7 +92,7 @@ impl TextDocument for IdentityDocument {
impl IntoSpecializedDocument<BlockchainProtocol> for IdentityDocument { impl IntoSpecializedDocument<BlockchainProtocol> for IdentityDocument {
fn into_specialized(self) -> BlockchainProtocol { fn into_specialized(self) -> BlockchainProtocol {
BlockchainProtocol::V10(V10Document::Identity(self)) BlockchainProtocol::V10(Box::new(V10Document::Identity(self)))
} }
} }
......
...@@ -34,7 +34,7 @@ lazy_static! { ...@@ -34,7 +34,7 @@ lazy_static! {
} }
/// Type of a Membership. /// Type of a Membership.
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy, PartialEq, Hash)]
pub enum MembershipType { pub enum MembershipType {
/// The member wishes to opt-in. /// The member wishes to opt-in.
In(), In(),
...@@ -45,7 +45,7 @@ pub enum MembershipType { ...@@ -45,7 +45,7 @@ pub enum MembershipType {
/// Wrap an Membership document. /// Wrap an Membership document.
/// ///
/// Must be created by parsing a text document or using a builder. /// Must be created by parsing a text document or using a builder.
#[derive(Debug, Clone)] #[derive(Debug, Clone, PartialEq, Hash)]
pub struct MembershipDocument { pub struct MembershipDocument {
/// Document as text. /// Document as text.
/// ///
...@@ -113,7 +113,7 @@ impl TextDocument for MembershipDocument { ...@@ -113,7 +113,7 @@ impl TextDocument for MembershipDocument {
impl IntoSpecializedDocument<BlockchainProtocol> for MembershipDocument { impl IntoSpecializedDocument<BlockchainProtocol> for MembershipDocument {
fn into_specialized(self) -> BlockchainProtocol { fn into_specialized(self) -> BlockchainProtocol {
BlockchainProtocol::V10(V10Document::Membership(self)) BlockchainProtocol::V10(Box::new(V10Document::Membership(self)))
} }
} }
......
...@@ -36,7 +36,7 @@ use duniter_crypto::keys::BaseConvertionError; ...@@ -36,7 +36,7 @@ use duniter_crypto::keys::BaseConvertionError;
pub mod blockchain; pub mod blockchain;
/// A block Id. /// A block Id.
#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct BlockId(pub u32); pub struct BlockId(pub u32);
impl Display for BlockId { impl Display for BlockId {
...@@ -48,7 +48,7 @@ impl Display for BlockId { ...@@ -48,7 +48,7 @@ impl Display for BlockId {
/// A hash wrapper. /// A hash wrapper.
/// ///
/// A hash is often provided as string composed of 64 hexadecimal character (0 to 9 then A to F). /// 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]); pub struct Hash(pub [u8; 32]);
impl Display for Hash { impl Display for Hash {
...@@ -110,7 +110,7 @@ impl Hash { ...@@ -110,7 +110,7 @@ impl Hash {
} }
/// Wrapper of a block hash. /// Wrapper of a block hash.
#[derive(Copy, Clone, PartialEq, Eq)] #[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub struct BlockHash(Hash); pub struct BlockHash(Hash);
impl Display for BlockHash { impl Display for BlockHash {
...@@ -148,7 +148,7 @@ pub enum BlockUIdParseError { ...@@ -148,7 +148,7 @@ pub enum BlockUIdParseError {
/// ///
/// [`BlockId`]: struct.BlockId.html /// [`BlockId`]: struct.BlockId.html
/// [`BlockHash`]: struct.BlockHash.html /// [`BlockHash`]: struct.BlockHash.html
#[derive(Copy, Clone, PartialEq, Eq)] #[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub struct Blockstamp { pub struct Blockstamp {
/// Block Id. /// Block Id.
pub id: BlockId, pub id: BlockId,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment