提交 9eb3e125 编写于 作者: M Matt Witherspoon

add a hash_value() for fc::cryto::signature

This is for usage in a container; not a cryptograhic hash or such
上级 4d18f8c7
......@@ -38,6 +38,7 @@ namespace fc { namespace crypto {
friend bool operator == ( const signature& p1, const signature& p2);
friend bool operator != ( const signature& p1, const signature& p2);
friend bool operator < ( const signature& p1, const signature& p2);
friend std::size_t hash_value(const signature& b); //not cryptographic; for containers
friend struct reflector<signature>;
friend class private_key;
friend class public_key;
......
......@@ -3,6 +3,15 @@
#include <fc/exception/exception.hpp>
namespace fc { namespace crypto {
struct hash_visitor : public fc::visitor<size_t> {
template<typename SigType>
size_t operator()(const SigType& sig) const {
static_assert(sizeof(sig._data.data) == 65, "sig size is expected to be 65");
//signatures are two bignums: r & s. Just add up least significant digits of the two
return *(size_t*)&sig._data.data[32-sizeof(size_t)] + *(size_t*)&sig._data.data[64-sizeof(size_t)];
}
};
static signature::storage_type parse_base58(const std::string& base58str)
{
constexpr auto prefix = config::signature_base_prefix;
......@@ -53,6 +62,10 @@ namespace fc { namespace crypto {
{
return less_comparator<signature::storage_type>::apply(p1._storage, p2._storage);
}
size_t hash_value(const signature& b) {
return b._storage.visit(hash_visitor());
}
} } // eosio::blockchain
namespace fc
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册