Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Fix interface of recover_key
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Aug 4, 2021
1 parent 722eae5 commit b65969c
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions programs/eosio-tester/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1059,17 +1059,16 @@ struct callbacks {
std::memcpy(hash_val, hash.data(), hash.data_size());
}

int32_t recover_key( span<const char> digest_span,
int32_t recover_key( const void* digest_val,
span<const char> sig,
void* pub ) {
fc::sha256 digest;
std::memcpy(digest.data(), digest_span.data(), digest.data_size());
span<char> pub ) {

fc::sha256 digest((const char*)digest_val, fc::sha256().data_size());

fc::crypto::signature s;
fc::datastream<const char*> ds( sig.data(), sig.size() );
fc::raw::unpack(ds, s);

// TODO: enforce supported key types
// EOS_ASSERT(static_cast<unsigned>(s.which()) < db.get<protocol_state_object>().num_supported_key_types,
// eosio::chain::unactivated_signature_type,
// "Unactivated signature type used during assert_recover_key");
Expand All @@ -1082,19 +1081,19 @@ struct callbacks {

// the key types newer than the first 2 may be varible in length
if (static_cast<unsigned>(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<size_t>(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<char*> out_ds( (char*)pub, static_cast<size_t>(33) );
fc::datastream<char*> out_ds( (char*)pub.data(), pub.size() );
fc::raw::pack(out_ds, recovered);
return out_ds.tellp();
}
Expand Down

0 comments on commit b65969c

Please sign in to comment.