aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee/src
diff options
context:
space:
mode:
authorluigi1111 <luigi1111w@gmail.com>2020-04-04 12:55:02 -0500
committerluigi1111 <luigi1111w@gmail.com>2020-04-04 12:55:02 -0500
commitcfc0f4a7fa67dd880d51c0aa35baa1e73e5db423 (patch)
tree932e460664a6329d5b9906506d1d6951378768a2 /contrib/epee/src
parentMerge pull request #6347 (diff)
parentReduce template bloat in hex->bin for ZMQ json (diff)
downloadmonero-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 'contrib/epee/src')
-rw-r--r--contrib/epee/src/hex.cpp41
1 files changed, 39 insertions, 2 deletions
diff --git a/contrib/epee/src/hex.cpp b/contrib/epee/src/hex.cpp
index 558983f7e..b25ce5421 100644
--- a/contrib/epee/src/hex.cpp
+++ b/contrib/epee/src/hex.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2019, The Monero Project
+// Copyright (c) 2017-2020, The Monero Project
//
// All rights reserved.
//
@@ -33,6 +33,8 @@
#include <ostream>
#include <stdexcept>
+#include "storages/parserse_base_utils.h"
+
namespace epee
{
namespace
@@ -84,7 +86,42 @@ namespace epee
return write_hex(out, src);
}
- std::vector<uint8_t> from_hex::vector(boost::string_ref src)
+
+ bool from_hex::to_string(std::string& out, const boost::string_ref src)
+ {
+ out.resize(src.size() / 2);
+ return to_buffer_unchecked(reinterpret_cast<std::uint8_t*>(&out[0]), src);
+ }
+
+ bool from_hex::to_buffer(span<std::uint8_t> out, const boost::string_ref src) noexcept
+ {
+ if (src.size() / 2 != out.size())
+ return false;
+ return to_buffer_unchecked(out.data(), src);
+ }
+
+ bool from_hex::to_buffer_unchecked(std::uint8_t* dst, const boost::string_ref s) noexcept
+ {
+ if (s.size() % 2 != 0)
+ return false;
+
+ const unsigned char *src = (const unsigned char *)s.data();
+ for(size_t i = 0; i < s.size(); i += 2)
+ {
+ int tmp = *src++;
+ tmp = epee::misc_utils::parse::isx[tmp];
+ if (tmp == 0xff) return false;
+ int t2 = *src++;
+ t2 = epee::misc_utils::parse::isx[t2];
+ if (t2 == 0xff) return false;
+ *dst++ = (tmp << 4) | t2;
+ }
+
+ return true;
+ }
+
+
+ std::vector<uint8_t> from_hex_locale::to_vector(const boost::string_ref src)
{
// should we include a specific character
auto include = [](char input) {