Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
signature.cpp
Go to the documentation of this file.
4
5namespace fc { namespace crypto {
6 struct hash_visitor : public fc::visitor<size_t> {
7 template<typename SigType>
8 size_t operator()(const SigType& sig) const {
9 static_assert(sizeof(sig._data.data) == 65, "sig size is expected to be 65");
10 //signatures are two bignums: r & s. Just add up least significant digits of the two
11 return *(size_t*)&sig._data.data[32-sizeof(size_t)] + *(size_t*)&sig._data.data[64-sizeof(size_t)];
12 }
13
14 size_t operator()(const webauthn::signature& sig) const {
15 return sig.get_hash();
16 }
17 };
18
19 static signature::storage_type sig_parse_base58(const std::string& base58str)
20 { try {
21 constexpr auto prefix = config::signature_base_prefix;
22
23 const auto pivot = base58str.find('_');
24 FC_ASSERT(pivot != std::string::npos, "No delimiter in string, cannot determine type: ${str}", ("str", base58str));
25
26 const auto prefix_str = base58str.substr(0, pivot);
27 FC_ASSERT(prefix == prefix_str, "Signature Key has invalid prefix: ${str}", ("str", base58str)("prefix_str", prefix_str));
28
29 auto data_str = base58str.substr(pivot + 1);
30 FC_ASSERT(!data_str.empty(), "Signature has no data: ${str}", ("str", base58str));
31 return base58_str_parser<signature::storage_type, config::signature_prefix>::apply(data_str);
32 } FC_RETHROW_EXCEPTIONS( warn, "error parsing signature", ("str", base58str ) ) }
33
34 signature::signature(const std::string& base58str)
35 :_storage(sig_parse_base58(base58str))
36 {}
37
38 size_t signature::which() const {
39 return _storage.index();
40 }
41
42 template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
43 template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
44
45 size_t signature::variable_size() const {
46 return std::visit(overloaded {
47 [&](const auto& k1r1) {
48 return static_cast<size_t>(0);
49 },
50 [&](const webauthn::signature& wa) {
51 return static_cast<size_t>(wa.variable_size());
52 }
53 }, _storage);
54 }
55
56 std::string signature::to_string(const fc::yield_function_t& yield) const
57 {
58 auto data_str = std::visit(base58str_visitor<storage_type, config::signature_prefix>(yield), _storage);
59 yield();
60 return std::string(config::signature_base_prefix) + "_" + data_str;
61 }
62
63 std::ostream& operator<<(std::ostream& s, const signature& k) {
64 s << "signature(" << k.to_string() << ')';
65 return s;
66 }
67
68 bool operator == ( const signature& p1, const signature& p2) {
69 return eq_comparator<signature::storage_type>::apply(p1._storage, p2._storage);
70 }
71
72 bool operator != ( const signature& p1, const signature& p2) {
73 return !eq_comparator<signature::storage_type>::apply(p1._storage, p2._storage);
74 }
75
76 bool operator < ( const signature& p1, const signature& p2)
77 {
78 return less_comparator<signature::storage_type>::apply(p1._storage, p2._storage);
79 }
80
81 size_t hash_value(const signature& b) {
82 return std::visit(hash_visitor(), b._storage);
83 }
84} } // sysio::blockchain
85
86namespace fc
87{
89 {
90 vo = var.to_string(yield);
91 }
92
94 {
96 }
97} // fc
wasm_allocator wa
Definition main.cpp:10
std::string to_string(const fc::yield_function_t &yield=fc::yield_function_t()) const
Definition signature.cpp:56
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
string as_string() const
Definition variant.cpp:469
Defines exception's used by fc.
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
#define FC_RETHROW_EXCEPTIONS(LOG_LEVEL, FORMAT,...)
Catchs all exception's, std::exceptions, and ... and rethrows them after appending the provided log m...
std::ostream & operator<<(std::ostream &s, const private_key &k)
overloaded(Ts...) -> overloaded< Ts... >
bool operator<(const private_key &p1, const private_key &p2)
size_t hash_value(const signature &b)
Definition signature.cpp:81
bool operator!=(const public_key &p1, const public_key &p2)
bool operator==(const private_key &p1, const private_key &p2)
namespace sysio::chain
Definition authority.cpp:3
void from_variant(const fc::variant &v, sysio::chain::chain_id_type &cid)
void to_variant(const sysio::chain::shared_public_key &var, fc::variant &vo)
Definition authority.cpp:4
static bool apply(const T &a, const T &b)
Definition common.hpp:119
size_t operator()(const webauthn::signature &sig) const
Definition signature.cpp:14
size_t operator()(const SigType &sig) const
Definition signature.cpp:8
static bool apply(const T &a, const T &b)
Definition common.hpp:147
char * s