encoding: Optimized Data packet encoding, preparation for memory-efficient signing operation
Change-Id: I6eb1f8acef917970790d1f228ade6212c45181fa
refs: #1172
diff --git a/src/util/string-helper.hpp b/src/util/string-helper.hpp
index de0c41f..14f499e 100644
--- a/src/util/string-helper.hpp
+++ b/src/util/string-helper.hpp
@@ -16,6 +16,29 @@
static const char *WHITESPACE_CHARS = " \n\r\t";
/**
+ * Return the hex representation of the bytes in array.
+ * @param array The array of bytes.
+ * @return Hex string.
+ */
+inline std::string
+toHex(const uint8_t* array, size_t arraySize)
+{
+ if (!&array)
+ return "";
+
+ std::ostringstream result;
+ result.flags(std::ios::hex | std::ios::uppercase);
+ for (size_t i = 0; i < arraySize; ++i) {
+ uint8_t x = array[i];
+ if (x < 16)
+ result << '0';
+ result << (unsigned int)x;
+ }
+
+ return result.str();
+}
+
+/**
* Modify str in place to erase whitespace on the left.
* @param str
*/