util: reimplement computeSha256Digest using security::transform

Change-Id: I36401dbf9ecc74de42c76f6f78d9e25ad00ed4d8
Refs: #3946
diff --git a/src/util/crypto.cpp b/src/util/crypto.cpp
index 1e22c0e..3083e40 100644
--- a/src/util/crypto.cpp
+++ b/src/util/crypto.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2013-2016 Regents of the University of California.
+ * Copyright (c) 2013-2017 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -21,8 +21,9 @@
 
 #include "crypto.hpp"
 #include "../encoding/buffer-stream.hpp"
-
-#include "../security/v1/cryptopp.hpp"
+#include "../security/transform/buffer-source.hpp"
+#include "../security/transform/digest-filter.hpp"
+#include "../security/transform/stream-sink.hpp"
 
 namespace ndn {
 namespace crypto {
@@ -30,15 +31,15 @@
 ConstBufferPtr
 computeSha256Digest(const uint8_t* data, size_t dataLength)
 {
+  namespace tr = security::transform;
   try {
-    CryptoPP::SHA256 hash;
     OBufferStream os;
-    CryptoPP::StringSource(data, dataLength, true,
-      new CryptoPP::HashFilter(hash, new CryptoPP::FileSink(os)));
+    tr::bufferSource(data, dataLength) >> tr::digestFilter(DigestAlgorithm::SHA256)
+                                       >> tr::streamSink(os);
     return os.buf();
   }
-  catch (CryptoPP::Exception& e) {
-    return ConstBufferPtr();
+  catch (const tr::Error&) {
+    return nullptr;
   }
 }
 
diff --git a/src/util/crypto.hpp b/src/util/crypto.hpp
index e406006..d5ce89b 100644
--- a/src/util/crypto.hpp
+++ b/src/util/crypto.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2013-2016 Regents of the University of California.
+ * Copyright (c) 2013-2017 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -29,14 +29,14 @@
 namespace crypto {
 
 /// @brief number of octets in a SHA256 digest
-static const size_t SHA256_DIGEST_SIZE = 32;
+const size_t SHA256_DIGEST_SIZE = 32;
 
 /**
- * @brief Compute the sha-256 digest of data.
+ * @brief Compute the SHA-256 digest of data.
  *
  * @param data Pointer to the input byte array.
  * @param dataLength The length of data.
- * @return A pointer to a buffer of SHA256_DIGEST.
+ * @return A pointer to a buffer of SHA256_DIGEST_SIZE bytes.
  */
 ConstBufferPtr
 computeSha256Digest(const uint8_t* data, size_t dataLength);
@@ -53,7 +53,6 @@
 }
 
 } // namespace crypto
-
 } // namespace ndn
 
 #endif // NDN_UTIL_CRYPTO_HPP
diff --git a/tests/unit-tests/util/crypto.t.cpp b/tests/unit-tests/util/crypto.t.cpp
index 9bf9f59..7770245 100644
--- a/tests/unit-tests/util/crypto.t.cpp
+++ b/tests/unit-tests/util/crypto.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2013-2016 Regents of the University of California.
+ * Copyright (c) 2013-2017 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -33,9 +33,8 @@
 BOOST_AUTO_TEST_CASE(Basic)
 {
   const std::string testString = "Hello, world!";
-  ConstBufferPtr result;
-  BOOST_CHECK_NO_THROW(result = computeSha256Digest(reinterpret_cast<const uint8_t*>(testString.data()),
-                                                    testString.size()));
+  auto result = computeSha256Digest(reinterpret_cast<const uint8_t*>(testString.data()),
+                                    testString.size());
 
   BOOST_CHECK_EQUAL(result->size(), SHA256_DIGEST_SIZE);