From 057861c608d684a36be376c2173974c57242a7a7 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Wed, 11 Feb 2015 18:27:33 -0500 Subject: [PATCH 1/3] extra raw io helpers --- include/fc/crypto/ripemd160.hpp | 3 ++- include/fc/crypto/sha256.hpp | 3 ++- include/fc/io/raw.hpp | 9 +++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/fc/crypto/ripemd160.hpp b/include/fc/crypto/ripemd160.hpp index 4c2e3b6..2febd58 100644 --- a/include/fc/crypto/ripemd160.hpp +++ b/include/fc/crypto/ripemd160.hpp @@ -2,6 +2,7 @@ #include #include #include +#include namespace fc{ @@ -28,7 +29,7 @@ class ripemd160 static ripemd160 hash( const T& t ) { ripemd160::encoder e; - e << t; + fc::raw::pack(e,t); return e.result(); } diff --git a/include/fc/crypto/sha256.hpp b/include/fc/crypto/sha256.hpp index 9a06bd7..4d2d606 100644 --- a/include/fc/crypto/sha256.hpp +++ b/include/fc/crypto/sha256.hpp @@ -2,6 +2,7 @@ #include #include #include +#include namespace fc { @@ -25,7 +26,7 @@ class sha256 static sha256 hash( const T& t ) { sha256::encoder e; - e << t; + fc::raw::pack(e,t); return e.result(); } diff --git a/include/fc/io/raw.hpp b/include/fc/io/raw.hpp index 8aa5558..7e58330 100644 --- a/include/fc/io/raw.hpp +++ b/include/fc/io/raw.hpp @@ -486,6 +486,15 @@ namespace fc { return tmp; } FC_RETHROW_EXCEPTIONS( warn, "error unpacking ${type}", ("type",fc::get_typename::name() ) ) } + template + inline void unpack( const std::vector& s, T& tmp ) + { try { + if( s.size() ) { + datastream ds( s.data(), size_t(s.size()) ); + raw::unpack(ds,tmp); + } + } FC_RETHROW_EXCEPTIONS( warn, "error unpacking ${type}", ("type",fc::get_typename::name() ) ) } + template inline void pack( char* d, uint32_t s, const T& v ) { datastream ds(d,s); From 0bf2f9cfd4ac1f58522526100f8636adfebe7dee Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Wed, 11 Feb 2015 18:32:23 -0500 Subject: [PATCH 2/3] fix conflict --- include/fc/crypto/ripemd160.hpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/include/fc/crypto/ripemd160.hpp b/include/fc/crypto/ripemd160.hpp index 6b56f31..3200873 100644 --- a/include/fc/crypto/ripemd160.hpp +++ b/include/fc/crypto/ripemd160.hpp @@ -3,12 +3,6 @@ #include #include #include -<<<<<<< HEAD -#include - -======= -#include ->>>>>>> 13430fce127bb3fdba53d218dd840aea8e46408c namespace fc{ class sha512; From ee370dd5a88f1d1ea406c0b119fe2ed62b58335e Mon Sep 17 00:00:00 2001 From: Vikram Rajkumar Date: Wed, 11 Feb 2015 18:58:19 -0500 Subject: [PATCH 3/3] Define sha256::hash( sha256 ) --- include/fc/crypto/sha256.hpp | 1 + src/crypto/sha256.cpp | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/include/fc/crypto/sha256.hpp b/include/fc/crypto/sha256.hpp index 4d2d606..c40c83a 100644 --- a/include/fc/crypto/sha256.hpp +++ b/include/fc/crypto/sha256.hpp @@ -21,6 +21,7 @@ class sha256 static sha256 hash( const char* d, uint32_t dlen ); static sha256 hash( const string& ); + static sha256 hash( const sha256& ); template static sha256 hash( const T& t ) diff --git a/src/crypto/sha256.cpp b/src/crypto/sha256.cpp index 1c06108..ae1d6af 100644 --- a/src/crypto/sha256.cpp +++ b/src/crypto/sha256.cpp @@ -40,10 +40,16 @@ namespace fc { e.write(d,dlen); return e.result(); } + sha256 sha256::hash( const string& s ) { return hash( s.c_str(), s.size() ); } + sha256 sha256::hash( const sha256& s ) + { + return hash( s.data(), sizeof( s._hash ) ); + } + void sha256::encoder::write( const char* d, uint32_t dlen ) { SHA256_Update( &my->ctx, d, dlen); }