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 = [
[[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)",
......
......@@ -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) {
......
[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"
......
......@@ -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(),
}
......
......@@ -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)))
}
}
......
......@@ -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)))
}
}
......
......@@ -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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment