util: Improvements of string helpers
Improvements include:
- test cases for every string helper
- a new `printHex` helper to output hex conversion directly to std::ostream
- new `toHex` and `printHex` helpers that accept Buffer as input parameter
- a new `fromHex` helper to convert the supplied string to shared_ptr<const Buffer>
- replaced uses of CryptoPP routines with `toHex` and `fromHex` helpers where applicable
Change-Id: I092c9fa8fd21c413b53ea5624b82f769287bb42c
Refs: #3006
diff --git a/tests/unit-tests/util/digest.t.cpp b/tests/unit-tests/util/digest.t.cpp
index 531868f..e1b3278 100644
--- a/tests/unit-tests/util/digest.t.cpp
+++ b/tests/unit-tests/util/digest.t.cpp
@@ -21,6 +21,7 @@
#include "util/digest.hpp"
#include "util/crypto.hpp"
+#include "util/string-helper.hpp"
#include "boost-test.hpp"
@@ -215,15 +216,12 @@
BOOST_AUTO_TEST_CASE(Print)
{
- using namespace CryptoPP;
-
uint8_t origin[32] = {0x94, 0xEE, 0x05, 0x93, 0x35, 0xE5, 0x87, 0xE5,
0x01, 0xCC, 0x4B, 0xF9, 0x06, 0x13, 0xE0, 0x81,
0x4F, 0x00, 0xA7, 0xB0, 0x8B, 0xC7, 0xC6, 0x48,
0xFD, 0x86, 0x5A, 0x2A, 0xF6, 0xA2, 0x2C, 0xC2};
- std::string hexString;
- StringSource(origin, 32, true, new HexEncoder(new StringSink(hexString)));
+ std::string hexString = toHex(origin, 32);
std::string str("TEST");
Sha256 digest;
@@ -234,7 +232,6 @@
BOOST_CHECK_EQUAL(os.str(), hexString);
BOOST_CHECK_EQUAL(digest.toString(), hexString);
-
}
BOOST_AUTO_TEST_SUITE_END()