mirror of
https://github.com/wownero/wownero.git
synced 2026-10-31 21:38:39 +01:00
serialization: avoid blob memcpy of secret_key vector
This commit is contained in:
@@ -32,6 +32,7 @@
|
|||||||
#include <list>
|
#include <list>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
#include <type_traits>
|
||||||
#include <boost/mpl/vector.hpp>
|
#include <boost/mpl/vector.hpp>
|
||||||
#include <boost/mpl/contains_fwd.hpp>
|
#include <boost/mpl/contains_fwd.hpp>
|
||||||
|
|
||||||
@@ -114,6 +115,9 @@ namespace epee
|
|||||||
template<class stl_container, class t_storage>
|
template<class stl_container, class t_storage>
|
||||||
static bool serialize_stl_container_pod_val_as_blob(const stl_container& container, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
|
static bool serialize_stl_container_pod_val_as_blob(const stl_container& container, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
|
||||||
{
|
{
|
||||||
|
static_assert(std::is_trivially_copyable_v<typename stl_container::value_type>,
|
||||||
|
"serialize_stl_container_pod_val_as_blob requires trivially copyable value_type");
|
||||||
|
|
||||||
if(!container.size()) return true;
|
if(!container.size()) return true;
|
||||||
std::string mb;
|
std::string mb;
|
||||||
mb.resize(sizeof(typename stl_container::value_type)*container.size());
|
mb.resize(sizeof(typename stl_container::value_type)*container.size());
|
||||||
@@ -129,6 +133,9 @@ namespace epee
|
|||||||
template<class stl_container, class t_storage>
|
template<class stl_container, class t_storage>
|
||||||
static bool unserialize_stl_container_pod_val_as_blob(stl_container& container, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
|
static bool unserialize_stl_container_pod_val_as_blob(stl_container& container, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
|
||||||
{
|
{
|
||||||
|
static_assert(std::is_trivially_copyable_v<typename stl_container::value_type>,
|
||||||
|
"unserialize_stl_container_pod_val_as_blob requires trivially copyable value_type");
|
||||||
|
|
||||||
container.clear();
|
container.clear();
|
||||||
std::string buff;
|
std::string buff;
|
||||||
bool res = stg.get_value(pname, buff, hparent_section);
|
bool res = stg.get_value(pname, buff, hparent_section);
|
||||||
|
|||||||
@@ -50,7 +50,25 @@ namespace cryptonote
|
|||||||
KV_SERIALIZE(m_account_address)
|
KV_SERIALIZE(m_account_address)
|
||||||
KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(m_spend_secret_key)
|
KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(m_spend_secret_key)
|
||||||
KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(m_view_secret_key)
|
KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(m_view_secret_key)
|
||||||
KV_SERIALIZE_CONTAINER_POD_AS_BLOB(m_multisig_keys)
|
if constexpr (is_store)
|
||||||
|
{
|
||||||
|
std::vector<crypto::ec_scalar> multisig_keys;
|
||||||
|
multisig_keys.reserve(this_ref.m_multisig_keys.size());
|
||||||
|
for (const crypto::secret_key& key : this_ref.m_multisig_keys)
|
||||||
|
multisig_keys.push_back(unwrap(unwrap(key)));
|
||||||
|
epee::serialization::selector<is_store>::serialize_stl_container_pod_val_as_blob(
|
||||||
|
multisig_keys, stg, hparent_section, "m_multisig_keys");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::vector<crypto::ec_scalar> multisig_keys;
|
||||||
|
epee::serialization::selector<is_store>::serialize_stl_container_pod_val_as_blob(
|
||||||
|
multisig_keys, stg, hparent_section, "m_multisig_keys");
|
||||||
|
this_ref.m_multisig_keys.clear();
|
||||||
|
this_ref.m_multisig_keys.reserve(multisig_keys.size());
|
||||||
|
for (const crypto::ec_scalar& key : multisig_keys)
|
||||||
|
this_ref.m_multisig_keys.emplace_back(tools::scrubbed<crypto::ec_scalar>{key});
|
||||||
|
}
|
||||||
const crypto::chacha_iv default_iv{{0, 0, 0, 0, 0, 0, 0, 0}};
|
const crypto::chacha_iv default_iv{{0, 0, 0, 0, 0, 0, 0, 0}};
|
||||||
KV_SERIALIZE_VAL_POD_AS_BLOB_OPT(m_encryption_iv, default_iv)
|
KV_SERIALIZE_VAL_POD_AS_BLOB_OPT(m_encryption_iv, default_iv)
|
||||||
END_KV_SERIALIZE_MAP()
|
END_KV_SERIALIZE_MAP()
|
||||||
|
|||||||
Reference in New Issue
Block a user