util: Add toString and operator<< for util::Digest
Change-Id: Id3695ad1d66dcc93f08085ee42556c71e3eb419c
diff --git a/src/util/digest.cpp b/src/util/digest.cpp
index bb2201d..ec27804 100644
--- a/src/util/digest.cpp
+++ b/src/util/digest.cpp
@@ -130,7 +130,36 @@
return result;
}
-template class Digest<CryptoPP::SHA256>;
+template<typename Hash>
+std::string
+Digest<Hash>::toString()
+{
+ std::ostringstream os;
+ os << *this;
+
+ return os.str();
+}
+
+template<typename Hash>
+std::ostream&
+operator<<(std::ostream& os, Digest<Hash>& digest)
+{
+ using namespace CryptoPP;
+
+ std::string output;
+ ConstBufferPtr buffer = digest.computeDigest();
+ StringSource(buffer->buf(), buffer->size(), true, new HexEncoder(new FileSink(os)));
+
+ return os;
+}
+
+template
+class Digest<CryptoPP::SHA256>;
+
+template
+std::ostream&
+operator<<(std::ostream& os, Digest<CryptoPP::SHA256>& digest);
+
} // namespace util
} // namespace ndn