diff --git a/include/fc/crypto/ripemd160.hpp b/include/fc/crypto/ripemd160.hpp index 2539412..3200873 100644 --- a/include/fc/crypto/ripemd160.hpp +++ b/include/fc/crypto/ripemd160.hpp @@ -3,7 +3,6 @@ #include #include #include -#include namespace fc{ class sha512; @@ -26,14 +25,14 @@ class ripemd160 static ripemd160 hash( const string& ); template - static ripemd160 hash( const T& t ) - { - ripemd160::encoder e; - fc::raw::pack( e, t ); - return e.result(); - } + static ripemd160 hash( const T& t ) + { + ripemd160::encoder e; + fc::raw::pack(e,t); + return e.result(); + } - class encoder + class encoder { public: encoder(); diff --git a/include/fc/crypto/sha256.hpp b/include/fc/crypto/sha256.hpp index 9a06bd7..c40c83a 100644 --- a/include/fc/crypto/sha256.hpp +++ b/include/fc/crypto/sha256.hpp @@ -2,6 +2,7 @@ #include #include #include +#include namespace fc { @@ -20,12 +21,13 @@ 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 ) { 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); 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); }