From b65969c0d80075a86d683de849f84f2a14d9d6aa Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Wed, 4 Aug 2021 12:04:20 -0500 Subject: [PATCH] Fix interface of recover_key --- programs/eosio-tester/main.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/programs/eosio-tester/main.cpp b/programs/eosio-tester/main.cpp index 8c1e7ab7ebc..494e40d46a6 100644 --- a/programs/eosio-tester/main.cpp +++ b/programs/eosio-tester/main.cpp @@ -1059,17 +1059,16 @@ struct callbacks { std::memcpy(hash_val, hash.data(), hash.data_size()); } - int32_t recover_key( span digest_span, + int32_t recover_key( const void* digest_val, span sig, - void* pub ) { - fc::sha256 digest; - std::memcpy(digest.data(), digest_span.data(), digest.data_size()); + span pub ) { + + fc::sha256 digest((const char*)digest_val, fc::sha256().data_size()); fc::crypto::signature s; fc::datastream ds( sig.data(), sig.size() ); fc::raw::unpack(ds, s); - // TODO: enforce supported key types // EOS_ASSERT(static_cast(s.which()) < db.get().num_supported_key_types, // eosio::chain::unactivated_signature_type, // "Unactivated signature type used during assert_recover_key"); @@ -1082,19 +1081,19 @@ struct callbacks { // the key types newer than the first 2 may be varible in length if (static_cast(s.which()) >= eosio::chain::config::genesis_num_supported_key_types ) { - // EOS_ASSERT(pub.size() >= 33, eosio::chain::wasm_execution_error, - // "destination buffer must at least be able to hold an ECC public key"); + EOS_ASSERT(pub.size() >= 33, eosio::chain::wasm_execution_error, + "destination buffer must at least be able to hold an ECC public key"); auto packed_pubkey = fc::raw::pack(recovered); - auto copy_size = packed_pubkey.size(); - std::memcpy(pub, packed_pubkey.data(), copy_size); + auto copy_size = std::min(pub.size(), packed_pubkey.size()); + std::memcpy(pub.data(), packed_pubkey.data(), copy_size); return packed_pubkey.size(); } else { // legacy behavior, key types 0 and 1 always pack to 33 bytes. // this will do one less copy for those keys while maintaining the rules of // [0..33) dest sizes: assert (asserts in fc::raw::pack) // [33..inf) dest sizes: return packed size (always 33) - fc::datastream out_ds( (char*)pub, static_cast(33) ); + fc::datastream out_ds( (char*)pub.data(), pub.size() ); fc::raw::pack(out_ds, recovered); return out_ds.tellp(); }