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

Merge branch '46-protocol-add-documenthasher-trait' into 'dev'

Resolve "protocol : add DocumentHasher Trait"

Closes #46

See merge request !33
parents d4935650 dc5ca45e
No related branches found
No related tags found
1 merge request!33Resolve "protocol : add DocumentHasher Trait"
...@@ -15,6 +15,10 @@ ...@@ -15,6 +15,10 @@
//! Provide wrappers around Duniter blockchain documents for protocol version 10. //! Provide wrappers around Duniter blockchain documents for protocol version 10.
extern crate crypto;
use self::crypto::digest::Digest;
use duniter_crypto::keys::{Signature, ed25519}; use duniter_crypto::keys::{Signature, ed25519};
use regex::Regex; use regex::Regex;
use blockchain::{Document, DocumentBuilder, DocumentParser}; use blockchain::{Document, DocumentBuilder, DocumentParser};
...@@ -72,6 +76,12 @@ pub trait TextDocument: Document<PublicKey = ed25519::PublicKey, CurrencyType = ...@@ -72,6 +76,12 @@ pub trait TextDocument: Document<PublicKey = ed25519::PublicKey, CurrencyType =
/// Return document as text. /// Return document as text.
fn as_text(&self) -> &str; fn as_text(&self) -> &str;
/// Return sha256 hash of text document
fn hash<H: Digest>(&self, digest: &mut H) -> String {
digest.input_str(self.as_text());
digest.result_str()
}
/// Return document as text with leading signatures. /// Return document as text with leading signatures.
fn as_text_with_signatures(&self) -> String { fn as_text_with_signatures(&self) -> String {
let mut text = self.as_text().to_string(); let mut text = self.as_text().to_string();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment