Merge pull request #14 from tzadikv/phoenix
Adding binary constructor for hash.
This commit is contained in:
commit
6bf740c28f
2 changed files with 7 additions and 0 deletions
|
|
@ -11,6 +11,7 @@ class sha256
|
||||||
public:
|
public:
|
||||||
sha256();
|
sha256();
|
||||||
explicit sha256( const string& hex_str );
|
explicit sha256( const string& hex_str );
|
||||||
|
explicit sha256( const char *data, size_t size );
|
||||||
|
|
||||||
string str()const;
|
string str()const;
|
||||||
operator string()const;
|
operator string()const;
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,16 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <fc/crypto/sha256.hpp>
|
#include <fc/crypto/sha256.hpp>
|
||||||
#include <fc/variant.hpp>
|
#include <fc/variant.hpp>
|
||||||
|
#include <fc/exception/exception.hpp>
|
||||||
|
|
||||||
namespace fc {
|
namespace fc {
|
||||||
|
|
||||||
sha256::sha256() { memset( _hash, 0, sizeof(_hash) ); }
|
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 ) {
|
sha256::sha256( const string& hex_str ) {
|
||||||
fc::from_hex( hex_str, (char*)_hash, sizeof(_hash) );
|
fc::from_hex( hex_str, (char*)_hash, sizeof(_hash) );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue