Merge pull request #14 from tzadikv/phoenix

Adding binary constructor for hash.
This commit is contained in:
Daniel Larimer 2014-02-25 01:20:04 -05:00
commit 6bf740c28f
2 changed files with 7 additions and 0 deletions

View file

@ -11,6 +11,7 @@ class sha256
public:
sha256();
explicit sha256( const string& hex_str );
explicit sha256( const char *data, size_t size );
string str()const;
operator string()const;

View file

@ -4,10 +4,16 @@
#include <string.h>
#include <fc/crypto/sha256.hpp>
#include <fc/variant.hpp>
#include <fc/exception/exception.hpp>
namespace fc {
sha256::sha256() { memset( _hash, 0, sizeof(_hash) ); }
sha256::sha256( const char *data, size_t size ) {
if (size != sizeof(_hash))
FC_THROW_EXCEPTION( exception, "sha256: size mismatch" );
memcpy(_hash, data, size );
}
sha256::sha256( const string& hex_str ) {
fc::from_hex( hex_str, (char*)_hash, sizeof(_hash) );
}