adding variant support to sha1
This commit is contained in:
parent
a4a00717ef
commit
bf94caf864
2 changed files with 21 additions and 0 deletions
|
|
@ -64,4 +64,8 @@ class sha1
|
||||||
uint32_t _hash[5];
|
uint32_t _hash[5];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class variant;
|
||||||
|
void to_variant( const sha1& bi, variant& v );
|
||||||
|
void from_variant( const variant& v, sha1& bi );
|
||||||
|
|
||||||
} // namespace fc
|
} // namespace fc
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
#include <openssl/sha.h>
|
#include <openssl/sha.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <fc/crypto/sha1.hpp>
|
#include <fc/crypto/sha1.hpp>
|
||||||
|
#include <fc/variant.hpp>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace fc
|
namespace fc
|
||||||
{
|
{
|
||||||
|
|
@ -84,4 +86,19 @@ bool operator == ( const sha1& h1, const sha1& h2 ) {
|
||||||
return memcmp( h1._hash, h2._hash, sizeof(h1._hash) ) == 0;
|
return memcmp( h1._hash, h2._hash, sizeof(h1._hash) ) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void to_variant( const sha1& bi, variant& v )
|
||||||
|
{
|
||||||
|
v = std::vector<char>( (const char*)&bi, ((const char*)&bi) + sizeof(bi) );
|
||||||
|
}
|
||||||
|
void from_variant( const variant& v, sha1& bi )
|
||||||
|
{
|
||||||
|
std::vector<char> ve = v.as< std::vector<char> >();
|
||||||
|
if( ve.size() )
|
||||||
|
{
|
||||||
|
memcpy(&bi, ve.data(), fc::min<size_t>(ve.size(),sizeof(bi)) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
memset( &bi, char(0), sizeof(bi) );
|
||||||
|
}
|
||||||
|
|
||||||
} // fc
|
} // fc
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue