Merge branch 'master' of github.com:bitshares/fc

This commit is contained in:
Nathan Hourt 2015-02-12 10:55:12 -05:00
commit c7de8954fb
4 changed files with 25 additions and 9 deletions

View file

@ -3,7 +3,6 @@
#include <fc/fwd.hpp>
#include <fc/io/raw_fwd.hpp>
#include <fc/reflect/typename.hpp>
#include <fc/string.hpp>
namespace fc{
class sha512;
@ -26,14 +25,14 @@ class ripemd160
static ripemd160 hash( const string& );
template<typename T>
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();

View file

@ -2,6 +2,7 @@
#include <fc/fwd.hpp>
#include <fc/string.hpp>
#include <fc/platform_independence.hpp>
#include <fc/io/raw_fwd.hpp>
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<typename T>
static sha256 hash( const T& t )
{
sha256::encoder e;
e << t;
fc::raw::pack(e,t);
return e.result();
}

View file

@ -486,6 +486,15 @@ namespace fc {
return tmp;
} FC_RETHROW_EXCEPTIONS( warn, "error unpacking ${type}", ("type",fc::get_typename<T>::name() ) ) }
template<typename T>
inline void unpack( const std::vector<char>& s, T& tmp )
{ try {
if( s.size() ) {
datastream<const char*> ds( s.data(), size_t(s.size()) );
raw::unpack(ds,tmp);
}
} FC_RETHROW_EXCEPTIONS( warn, "error unpacking ${type}", ("type",fc::get_typename<T>::name() ) ) }
template<typename T>
inline void pack( char* d, uint32_t s, const T& v ) {
datastream<char*> ds(d,s);

View file

@ -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);
}