diff options
author | luigi1111 <luigi1111w@gmail.com> | 2023-06-27 11:45:48 -0500 |
---|---|---|
committer | luigi1111 <luigi1111w@gmail.com> | 2023-06-27 11:45:48 -0500 |
commit | e4e8edd9c981e4e00e36bba282c1417f5bfdcd4e (patch) | |
tree | da9263a2f2b1250bedc6eaa1b4acf4ab8e1b2f81 /contrib | |
parent | Merge pull request #8869 (diff) | |
parent | Add to_hex::buffer (diff) | |
download | monero-e4e8edd9c981e4e00e36bba282c1417f5bfdcd4e.tar.xz |
Merge pull request #8870
eb94356 Add to_hex::buffer (Lee *!* Clagett)
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/epee/include/hex.h | 3 | ||||
-rw-r--r-- | contrib/epee/src/hex.cpp | 8 |
2 files changed, 11 insertions, 0 deletions
diff --git a/contrib/epee/include/hex.h b/contrib/epee/include/hex.h index d9eb93d51..d27c127c1 100644 --- a/contrib/epee/include/hex.h +++ b/contrib/epee/include/hex.h @@ -67,6 +67,9 @@ namespace epee return out; } + //! Write `src` as hex to `out`. `out` must be exactly 2x in size. + static bool buffer(span<char> out, const span<const std::uint8_t> src) noexcept; + //! Append `src` as hex to `out`. static void buffer(std::ostream& out, const span<const std::uint8_t> src); diff --git a/contrib/epee/src/hex.cpp b/contrib/epee/src/hex.cpp index edc7d46f4..625f37c2f 100644 --- a/contrib/epee/src/hex.cpp +++ b/contrib/epee/src/hex.cpp @@ -69,6 +69,14 @@ namespace epee std::string to_hex::string(const span<const std::uint8_t> src) { return convert<std::string>(src); } epee::wipeable_string to_hex::wipeable_string(const span<const std::uint8_t> src) { return convert<epee::wipeable_string>(src); } + bool to_hex::buffer(span<char> out, const span<const std::uint8_t> src) noexcept + { + if (out.size() % 2 != 0 || out.size() / 2 != src.size()) + return false; + to_hex::buffer_unchecked(out.data(), src); + return true; + } + void to_hex::buffer(std::ostream& out, const span<const std::uint8_t> src) { write_hex(std::ostreambuf_iterator<char>{out}, src); |