diff options
author | luigi1111 <luigi1111w@gmail.com> | 2020-04-04 12:55:02 -0500 |
---|---|---|
committer | luigi1111 <luigi1111w@gmail.com> | 2020-04-04 12:55:02 -0500 |
commit | cfc0f4a7fa67dd880d51c0aa35baa1e73e5db423 (patch) | |
tree | 932e460664a6329d5b9906506d1d6951378768a2 /src | |
parent | Merge pull request #6347 (diff) | |
parent | Reduce template bloat in hex->bin for ZMQ json (diff) | |
download | monero-cfc0f4a7fa67dd880d51c0aa35baa1e73e5db423.tar.xz |
Merge pull request #6351
81c5943 Remove temporary std::string creation in some hex->bin calls (vtnerd)
5fcc23a Move hex->bin conversion to monero copyright files and with less includes (vtnerd)
3387f0e Reduce template bloat in hex->bin for ZMQ json (vtnerd)
Diffstat (limited to 'src')
-rw-r--r-- | src/rpc/rpc_args.cpp | 4 | ||||
-rw-r--r-- | src/serialization/json_object.cpp | 21 | ||||
-rw-r--r-- | src/serialization/json_object.h | 21 | ||||
-rw-r--r-- | src/wallet/wallet2.cpp | 2 |
4 files changed, 29 insertions, 19 deletions
diff --git a/src/rpc/rpc_args.cpp b/src/rpc/rpc_args.cpp index dcb804d3e..9153e76ea 100644 --- a/src/rpc/rpc_args.cpp +++ b/src/rpc/rpc_args.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2019, The Monero Project +// Copyright (c) 2014-2020, The Monero Project // // All rights reserved. // @@ -51,7 +51,7 @@ namespace cryptonote const std::vector<std::string> ssl_allowed_fingerprints = command_line::get_arg(vm, arg.rpc_ssl_allowed_fingerprints); std::vector<std::vector<uint8_t>> allowed_fingerprints{ ssl_allowed_fingerprints.size() }; - std::transform(ssl_allowed_fingerprints.begin(), ssl_allowed_fingerprints.end(), allowed_fingerprints.begin(), epee::from_hex::vector); + std::transform(ssl_allowed_fingerprints.begin(), ssl_allowed_fingerprints.end(), allowed_fingerprints.begin(), epee::from_hex_locale::to_vector); for (const auto &fpr: allowed_fingerprints) { if (fpr.size() != SSL_FINGERPRINT_SIZE) diff --git a/src/serialization/json_object.cpp b/src/serialization/json_object.cpp index e98ba0483..926eb18c0 100644 --- a/src/serialization/json_object.cpp +++ b/src/serialization/json_object.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2019, The Monero Project +// Copyright (c) 2016-2020, The Monero Project // // All rights reserved. // @@ -32,7 +32,11 @@ #include <boost/variant/apply_visitor.hpp> #include <limits> #include <type_traits> -#include "string_tools.h" + +// drop macro from windows.h +#ifdef GetObject + #undef GetObject +#endif namespace cryptonote { @@ -109,6 +113,19 @@ namespace } } +void read_hex(const rapidjson::Value& val, epee::span<std::uint8_t> dest) +{ + if (!val.IsString()) + { + throw WRONG_TYPE("string"); + } + + if (!epee::from_hex::to_buffer(dest, {val.GetString(), val.Size()})) + { + throw BAD_INPUT(); + } +} + void toJsonValue(rapidjson::Writer<rapidjson::StringBuffer>& dest, const rapidjson::Value& src) { src.Accept(dest); diff --git a/src/serialization/json_object.h b/src/serialization/json_object.h index a1a5105d5..664b539b5 100644 --- a/src/serialization/json_object.h +++ b/src/serialization/json_object.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2019, The Monero Project +// Copyright (c) 2016-2020, The Monero Project // // All rights reserved. // @@ -30,7 +30,6 @@ #include <boost/utility/string_ref.hpp> #include <cstring> -#include "string_tools.h" // out of order because windows.h GetObject macro conflicts with GenericValue<..>::GetObject() #include <rapidjson/document.h> #include <rapidjson/stringbuffer.h> #include <rapidjson/writer.h> @@ -39,6 +38,8 @@ #include "rpc/message_data_structs.h" #include "cryptonote_protocol/cryptonote_protocol_defs.h" #include "common/sfinae_helpers.h" +#include "hex.h" +#include "span.h" #define OBJECT_HAS_MEMBER_OR_THROW(val, key) \ do \ @@ -118,6 +119,8 @@ inline constexpr bool is_to_hex() return std::is_pod<Type>() && !std::is_integral<Type>(); } +void read_hex(const rapidjson::Value& val, epee::span<std::uint8_t> dest); + // POD to json key template <class Type> inline typename std::enable_if<is_to_hex<Type>()>::type toJsonKey(rapidjson::Writer<rapidjson::StringBuffer>& dest, const Type& pod) @@ -137,18 +140,8 @@ inline typename std::enable_if<is_to_hex<Type>()>::type toJsonValue(rapidjson::W template <class Type> inline typename std::enable_if<is_to_hex<Type>()>::type fromJsonValue(const rapidjson::Value& val, Type& t) { - if (!val.IsString()) - { - throw WRONG_TYPE("string"); - } - - //TODO: handle failure to convert hex string to POD type - bool success = epee::string_tools::hex_to_pod(val.GetString(), t); - - if (!success) - { - throw BAD_INPUT(); - } + static_assert(std::is_standard_layout<Type>(), "expected standard layout type"); + json::read_hex(val, epee::as_mut_byte_span(t)); } void toJsonValue(rapidjson::Writer<rapidjson::StringBuffer>& dest, const rapidjson::Value& src); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 70ceddad3..f05a67315 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -355,7 +355,7 @@ std::unique_ptr<tools::wallet2> make_basic(const boost::program_options::variabl else if (!daemon_ssl_ca_file.empty() || !daemon_ssl_allowed_fingerprints.empty()) { std::vector<std::vector<uint8_t>> ssl_allowed_fingerprints{ daemon_ssl_allowed_fingerprints.size() }; - std::transform(daemon_ssl_allowed_fingerprints.begin(), daemon_ssl_allowed_fingerprints.end(), ssl_allowed_fingerprints.begin(), epee::from_hex::vector); + std::transform(daemon_ssl_allowed_fingerprints.begin(), daemon_ssl_allowed_fingerprints.end(), ssl_allowed_fingerprints.begin(), epee::from_hex_locale::to_vector); for (const auto &fpr: ssl_allowed_fingerprints) { THROW_WALLET_EXCEPTION_IF(fpr.size() != SSL_FINGERPRINT_SIZE, tools::error::wallet_internal_error, |