summaryrefslogtreecommitdiff
path: root/src/common/hex_util.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/hex_util.h')
-rw-r--r--src/common/hex_util.h11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/common/hex_util.h b/src/common/hex_util.h
index 68f003cb6..a64c9b485 100644
--- a/src/common/hex_util.h
+++ b/src/common/hex_util.h
@@ -7,6 +7,7 @@
7#include <array> 7#include <array>
8#include <cstddef> 8#include <cstddef>
9#include <string> 9#include <string>
10#include <type_traits>
10#include <vector> 11#include <vector>
11#include <fmt/format.h> 12#include <fmt/format.h>
12#include "common/common_types.h" 13#include "common/common_types.h"
@@ -30,13 +31,15 @@ std::array<u8, Size> HexStringToArray(std::string_view str) {
30 return out; 31 return out;
31} 32}
32 33
33std::string HexVectorToString(const std::vector<u8>& vector, bool upper = true); 34template <typename ContiguousContainer>
35std::string HexToString(const ContiguousContainer& data, bool upper = true) {
36 static_assert(std::is_same_v<typename ContiguousContainer::value_type, u8>,
37 "Underlying type within the contiguous container must be u8.");
34 38
35template <std::size_t Size>
36std::string HexArrayToString(std::array<u8, Size> array, bool upper = true) {
37 std::string out; 39 std::string out;
38 for (u8 c : array) 40 for (const u8 c : data) {
39 out += fmt::format(upper ? "{:02X}" : "{:02x}", c); 41 out += fmt::format(upper ? "{:02X}" : "{:02x}", c);
42 }
40 return out; 43 return out;
41} 44}
42 45