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

[fix] #55 impl Serialize for WOT Documents & pubkey

parent 8b877072
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
//! //!
//! [`KeyPairGenerator`]: struct.KeyPairGenerator.html //! [`KeyPairGenerator`]: struct.KeyPairGenerator.html
extern crate serde;
use std::collections::hash_map::DefaultHasher; use std::collections::hash_map::DefaultHasher;
use std::fmt::Debug; use std::fmt::Debug;
use std::fmt::Display; use std::fmt::Display;
...@@ -30,6 +32,7 @@ use base58::{FromBase58, FromBase58Error, ToBase58}; ...@@ -30,6 +32,7 @@ use base58::{FromBase58, FromBase58Error, ToBase58};
use base64; use base64;
use base64::DecodeError; use base64::DecodeError;
use crypto; use crypto;
use self::serde::ser::{Serialize, Serializer};
use super::{BaseConvertionError, PrivateKey as PrivateKeyMethods, PublicKey as PublicKeyMethods}; use super::{BaseConvertionError, PrivateKey as PrivateKeyMethods, PublicKey as PublicKeyMethods};
...@@ -123,6 +126,15 @@ impl Debug for PublicKey { ...@@ -123,6 +126,15 @@ impl Debug for PublicKey {
} }
} }
impl Serialize for PublicKey {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&format!("{}", self))
}
}
impl super::PublicKey for PublicKey { impl super::PublicKey for PublicKey {
type Signature = Signature; type Signature = Signature;
......
...@@ -15,8 +15,11 @@ ...@@ -15,8 +15,11 @@
//! Wrappers around Certification documents. //! Wrappers around Certification documents.
use duniter_crypto::keys::{ed25519, PublicKey, Signature}; extern crate serde;
use duniter_crypto::keys::{PublicKey, Signature, ed25519};
use regex::Regex; use regex::Regex;
use self::serde::ser::{Serialize, Serializer};
use blockchain::v10::documents::{StandardTextDocumentParser, TextDocument, TextDocumentBuilder, use blockchain::v10::documents::{StandardTextDocumentParser, TextDocument, TextDocumentBuilder,
V10Document, V10DocumentParsingError}; V10Document, V10DocumentParsingError};
...@@ -115,6 +118,15 @@ impl TextDocument for CertificationDocument { ...@@ -115,6 +118,15 @@ impl TextDocument for CertificationDocument {
} }
} }
impl Serialize for CertificationDocument {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&self.generate_compact_text())
}
}
impl IntoSpecializedDocument<BlockchainProtocol> for CertificationDocument { impl IntoSpecializedDocument<BlockchainProtocol> for CertificationDocument {
fn into_specialized(self) -> BlockchainProtocol { fn into_specialized(self) -> BlockchainProtocol {
BlockchainProtocol::V10(Box::new(V10Document::Certification(Box::new(self)))) BlockchainProtocol::V10(Box::new(V10Document::Certification(Box::new(self))))
......
...@@ -15,8 +15,11 @@ ...@@ -15,8 +15,11 @@
//! Wrappers around Identity documents. //! Wrappers around Identity documents.
use duniter_crypto::keys::{ed25519, PublicKey}; extern crate serde;
use duniter_crypto::keys::{PublicKey, ed25519};
use regex::Regex; use regex::Regex;
use self::serde::ser::{Serialize, Serializer};
use blockchain::v10::documents::{StandardTextDocumentParser, TextDocument, TextDocumentBuilder, use blockchain::v10::documents::{StandardTextDocumentParser, TextDocument, TextDocumentBuilder,
V10Document, V10DocumentParsingError}; V10Document, V10DocumentParsingError};
...@@ -100,6 +103,15 @@ impl TextDocument for IdentityDocument { ...@@ -100,6 +103,15 @@ impl TextDocument for IdentityDocument {
} }
} }
impl Serialize for IdentityDocument {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&self.generate_compact_text())
}
}
impl IntoSpecializedDocument<BlockchainProtocol> for IdentityDocument { impl IntoSpecializedDocument<BlockchainProtocol> for IdentityDocument {
fn into_specialized(self) -> BlockchainProtocol { fn into_specialized(self) -> BlockchainProtocol {
BlockchainProtocol::V10(Box::new(V10Document::Identity(self))) BlockchainProtocol::V10(Box::new(V10Document::Identity(self)))
......
...@@ -15,8 +15,11 @@ ...@@ -15,8 +15,11 @@
//! Wrappers around Membership documents. //! Wrappers around Membership documents.
use duniter_crypto::keys::{ed25519, PublicKey}; extern crate serde;
use duniter_crypto::keys::{PublicKey, ed25519};
use regex::Regex; use regex::Regex;
use self::serde::ser::{Serialize, Serializer};
use blockchain::v10::documents::{StandardTextDocumentParser, TextDocument, TextDocumentBuilder, use blockchain::v10::documents::{StandardTextDocumentParser, TextDocument, TextDocumentBuilder,
V10Document, V10DocumentParsingError}; V10Document, V10DocumentParsingError};
...@@ -122,6 +125,15 @@ impl TextDocument for MembershipDocument { ...@@ -122,6 +125,15 @@ impl TextDocument for MembershipDocument {
} }
} }
impl Serialize for MembershipDocument {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&self.generate_compact_text())
}
}
impl IntoSpecializedDocument<BlockchainProtocol> for MembershipDocument { impl IntoSpecializedDocument<BlockchainProtocol> for MembershipDocument {
fn into_specialized(self) -> BlockchainProtocol { fn into_specialized(self) -> BlockchainProtocol {
BlockchainProtocol::V10(Box::new(V10Document::Membership(self))) BlockchainProtocol::V10(Box::new(V10Document::Membership(self)))
......
...@@ -15,8 +15,11 @@ ...@@ -15,8 +15,11 @@
//! Wrappers around Revocation documents. //! Wrappers around Revocation documents.
use duniter_crypto::keys::{ed25519, PublicKey, Signature}; extern crate serde;
use duniter_crypto::keys::{PublicKey, Signature, ed25519};
use regex::Regex; use regex::Regex;
use self::serde::ser::{Serialize, Serializer};
use blockchain::v10::documents::{StandardTextDocumentParser, TextDocument, TextDocumentBuilder, use blockchain::v10::documents::{StandardTextDocumentParser, TextDocument, TextDocumentBuilder,
V10Document, V10DocumentParsingError}; V10Document, V10DocumentParsingError};
...@@ -102,6 +105,15 @@ impl TextDocument for RevocationDocument { ...@@ -102,6 +105,15 @@ impl TextDocument for RevocationDocument {
} }
} }
impl Serialize for RevocationDocument {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&self.generate_compact_text())
}
}
impl IntoSpecializedDocument<BlockchainProtocol> for RevocationDocument { impl IntoSpecializedDocument<BlockchainProtocol> for RevocationDocument {
fn into_specialized(self) -> BlockchainProtocol { fn into_specialized(self) -> BlockchainProtocol {
BlockchainProtocol::V10(Box::new(V10Document::Revocation(Box::new(self)))) BlockchainProtocol::V10(Box::new(V10Document::Revocation(Box::new(self))))
......
...@@ -120,7 +120,7 @@ impl Hash { ...@@ -120,7 +120,7 @@ impl Hash {
/// Wrapper of a block hash. /// Wrapper of a block hash.
#[derive(Copy, Clone, PartialEq, Eq, Hash)] #[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub struct BlockHash(Hash); pub struct BlockHash(pub Hash);
impl Display for BlockHash { impl Display for BlockHash {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment