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/security/digest-sha256.t.cpp b/tests/unit-tests/security/digest-sha256.t.cpp
index ebf50c7..ffc6908 100644
--- a/tests/unit-tests/security/digest-sha256.t.cpp
+++ b/tests/unit-tests/security/digest-sha256.t.cpp
@@ -22,7 +22,8 @@
#include "security/digest-sha256.hpp"
#include "security/key-chain.hpp"
#include "security/validator.hpp"
-#include "security/cryptopp.hpp"
+#include "util/string-helper.hpp"
+
#include "identity-management-fixture.hpp"
#include "boost-test.hpp"
@@ -39,10 +40,8 @@
char content[6] = "1234\n";
ConstBufferPtr buf = crypto::sha256(reinterpret_cast<uint8_t*>(content), 5);
- std::string result;
- StringSource(buf->buf(), buf->size(), true, new HexEncoder(new StringSink(result), false));
- BOOST_CHECK_EQUAL(SHA256_RESULT, result);
+ BOOST_CHECK_EQUAL(SHA256_RESULT, toHex(buf->buf(), buf->size(), false));
}
BOOST_AUTO_TEST_CASE(DataSignature)
diff --git a/tests/unit-tests/security/pib-data-fixture.cpp b/tests/unit-tests/security/pib-data-fixture.cpp
index a42c0e3..dfb5304 100644
--- a/tests/unit-tests/security/pib-data-fixture.cpp
+++ b/tests/unit-tests/security/pib-data-fixture.cpp
@@ -79,10 +79,7 @@
* {
* using namespace CryptoPP;
*
- * std::stringstream ss;
- * StringSource(buf, size, true, new HexEncoder(new FileSink(ss)));
- *
- * std::string hex = ss.str();
+ * std::string hex = toHex(buf, size);
*
* for (int i = 0; i < hex.size(); i++) {
* if (i % 40 == 0)