security: Reorganizing source code to prepare for support of two version of NDN certificates

This commit also removes unused ndn_digestSha256 function and deprecates
crypto::sha256 in favor of crypto::computeSha256Digest in util/crypto.hpp.

Change-Id: I24ee50ff073a96b868633bdf2cfade412d3605f3
Refs: #3098
diff --git a/tests/unit-tests/util/command-interest-validator.t.cpp b/tests/unit-tests/util/command-interest-validator.t.cpp
new file mode 100644
index 0000000..029a163
--- /dev/null
+++ b/tests/unit-tests/util/command-interest-validator.t.cpp
@@ -0,0 +1,33 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2016 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#include "util/command-interest-validator.hpp"
+
+namespace ndn {
+namespace util {
+namespace tests {
+
+// CommandInterestValidator is deprecated, therefore no tests added
+// (just checking that code with header can be compiled)
+
+} // namespace tests
+} // namespace util
+} // namespace ndn
diff --git a/tests/unit-tests/util/crypto.t.cpp b/tests/unit-tests/util/crypto.t.cpp
new file mode 100644
index 0000000..9bf9f59
--- /dev/null
+++ b/tests/unit-tests/util/crypto.t.cpp
@@ -0,0 +1,55 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2016 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#include "util/crypto.hpp"
+
+#include "boost-test.hpp"
+
+namespace ndn {
+namespace crypto {
+namespace tests {
+
+BOOST_AUTO_TEST_SUITE(Util)
+BOOST_AUTO_TEST_SUITE(TestCrypto)
+
+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()));
+
+  BOOST_CHECK_EQUAL(result->size(), SHA256_DIGEST_SIZE);
+
+  const uint8_t expectedSha256[] = {0x31, 0x5f, 0x5b, 0xdb, 0x76, 0xd0, 0x78, 0xc4,
+                                    0x3b, 0x8a, 0xc0, 0x06, 0x4e, 0x4a, 0x01, 0x64,
+                                    0x61, 0x2b, 0x1f, 0xce, 0x77, 0xc8, 0x69, 0x34,
+                                    0x5b, 0xfc, 0x94, 0xc7, 0x58, 0x94, 0xed, 0xd3};
+  BOOST_CHECK_EQUAL_COLLECTIONS(result->begin(), result->end(),
+                                expectedSha256, expectedSha256 + sizeof(expectedSha256));
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestCrypto
+BOOST_AUTO_TEST_SUITE_END() // Util
+
+} // namespace tests
+} // namespace crypto
+} // namespace ndn
diff --git a/tests/unit-tests/util/digest.t.cpp b/tests/unit-tests/util/digest.t.cpp
index e1b3278..62be5d4 100644
--- a/tests/unit-tests/util/digest.t.cpp
+++ b/tests/unit-tests/util/digest.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2013-2015 Regents of the University of California.
+ * Copyright (c) 2013-2016 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -34,7 +34,7 @@
 BOOST_AUTO_TEST_CASE(Sha256Digest)
 {
   uint8_t origin[4] = {0x01, 0x02, 0x03, 0x04};
-  ConstBufferPtr digest1 = crypto::sha256(origin, 4);
+  ConstBufferPtr digest1 = crypto::computeSha256Digest(origin, 4);
 
   Sha256 statefulSha256;
   statefulSha256.update(origin, 1);
@@ -52,8 +52,8 @@
 BOOST_AUTO_TEST_CASE(Compute)
 {
   std::string input = "Hello, World!";
-  ConstBufferPtr digest1 = crypto::sha256(reinterpret_cast<const uint8_t*>(input.data()),
-                                          input.size());
+  ConstBufferPtr digest1 = crypto::computeSha256Digest(reinterpret_cast<const uint8_t*>(input.data()),
+                                                       input.size());
 
   Sha256 hashObject;
   hashObject << input;
@@ -69,8 +69,8 @@
 BOOST_AUTO_TEST_CASE(ConstructFromStream)
 {
   std::string input = "Hello, World!";
-  ConstBufferPtr digest1 = crypto::sha256(reinterpret_cast<const uint8_t*>(input.data()),
-                                          input.size());
+  ConstBufferPtr digest1 = crypto::computeSha256Digest(reinterpret_cast<const uint8_t*>(input.data()),
+                                                       input.size());
 
   std::istringstream is(input);
   Sha256 hashObject(is);
@@ -107,7 +107,7 @@
                         0x01, 0xCC, 0x4B, 0xF9, 0x06, 0x13, 0xE0, 0x81,
                         0x4F, 0x00, 0xA7, 0xB0, 0x8B, 0xC7, 0xC6, 0x48,
                         0xFD, 0x86, 0x5A, 0x2A, 0xF6, 0xA2, 0x2C, 0xC2};
-  ConstBufferPtr digest1 = crypto::sha256(origin, 32);
+  ConstBufferPtr digest1 = crypto::computeSha256Digest(origin, 32);
 
   std::string str("TEST");
   Sha256 metaDigest;
@@ -126,7 +126,7 @@
 BOOST_AUTO_TEST_CASE(OperatorString)
 {
   uint8_t origin[4] = {0x54, 0x45, 0x53, 0x54};
-  ConstBufferPtr digest1 = crypto::sha256(origin, 4);
+  ConstBufferPtr digest1 = crypto::computeSha256Digest(origin, 4);
 
   std::string str("TEST");
   Sha256 statefulSha256;
@@ -154,7 +154,7 @@
           0x08, 0x07,
             0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72
   };
-  ConstBufferPtr digest1 = crypto::sha256(origin, sizeof(origin));
+  ConstBufferPtr digest1 = crypto::computeSha256Digest(origin, sizeof(origin));
 
   Sha256 statefulSha256;
   Block block(origin, sizeof(origin));
@@ -170,7 +170,7 @@
 BOOST_AUTO_TEST_CASE(OperatorUint64t)
 {
   uint64_t origin[4] = {1, 2, 3, 4};
-  ConstBufferPtr digest1 = crypto::sha256(reinterpret_cast<uint8_t*>(origin), 32);
+  ConstBufferPtr digest1 = crypto::computeSha256Digest(reinterpret_cast<uint8_t*>(origin), 32);
 
   Sha256 statefulSha256;
   statefulSha256 << origin[0];
@@ -204,7 +204,7 @@
 BOOST_AUTO_TEST_CASE(ComputeDigest)
 {
   uint8_t origin[4] = {0x01, 0x02, 0x03, 0x04};
-  ConstBufferPtr digest1 = crypto::sha256(origin, 4);
+  ConstBufferPtr digest1 = crypto::computeSha256Digest(origin, 4);
 
   ConstBufferPtr digest2 = Sha256::computeDigest(origin, 4);
 
diff --git a/tests/unit-tests/util/in-memory-storage-common.t.cpp b/tests/unit-tests/util/in-memory-storage-common.t.cpp
index 9e7c814..da87929 100644
--- a/tests/unit-tests/util/in-memory-storage-common.t.cpp
+++ b/tests/unit-tests/util/in-memory-storage-common.t.cpp
@@ -278,8 +278,8 @@
 {
   shared_ptr<Data> data = makeData("/digest/compute");
 
-  ndn::ConstBufferPtr digest1 = ndn::crypto::sha256(data->wireEncode().wire(),
-                                                    data->wireEncode().size());
+  ndn::ConstBufferPtr digest1 = ndn::crypto::computeSha256Digest(data->wireEncode().wire(),
+                                                                 data->wireEncode().size());
   BOOST_CHECK_EQUAL(digest1->size(), 32);
 
   InMemoryStorageEntry* entry = new InMemoryStorageEntry();
@@ -374,8 +374,8 @@
   shared_ptr<Data> data7 = makeData("/c/c/1");
   ims.insert(*data7);
 
-  ndn::ConstBufferPtr digest1 = ndn::crypto::sha256(data->wireEncode().wire(),
-                                                    data->wireEncode().size());
+  ndn::ConstBufferPtr digest1 = ndn::crypto::computeSha256Digest(data->wireEncode().wire(),
+                                                                 data->wireEncode().size());
 
   Name name("/a");
   ims.erase(name);
@@ -396,8 +396,8 @@
   shared_ptr<Data> data3 = makeData("/z/z/z");
   ims.insert(*data3);
 
-  ndn::ConstBufferPtr digest1 = ndn::crypto::sha256(data->wireEncode().wire(),
-                                                    data->wireEncode().size());
+  ndn::ConstBufferPtr digest1 = ndn::crypto::computeSha256Digest(data->wireEncode().wire(),
+                                                                 data->wireEncode().size());
 
   shared_ptr<Interest> interest = makeInterest("");
   interest->setName(Name(name).appendImplicitSha256Digest(digest1->buf(), digest1->size()));
diff --git a/tests/unit-tests/util/io.t.cpp b/tests/unit-tests/util/io.t.cpp
index f8ea2ae..b789020 100644
--- a/tests/unit-tests/util/io.t.cpp
+++ b/tests/unit-tests/util/io.t.cpp
@@ -248,11 +248,11 @@
   identity.appendVersion();
   BOOST_REQUIRE(addIdentity(identity, RsaKeyParams()));
   Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
-  shared_ptr<IdentityCertificate> idCert;
+  shared_ptr<security::v1::IdentityCertificate> idCert;
   BOOST_REQUIRE_NO_THROW(idCert = m_keyChain.getCertificate(certName));
 
   io::save(*idCert, filename);
-  shared_ptr<IdentityCertificate> readCert = io::load<IdentityCertificate>(filename);
+  shared_ptr<security::v1::IdentityCertificate> readCert = io::load<security::v1::IdentityCertificate>(filename);
 
   BOOST_CHECK(readCert != nullptr);
   BOOST_CHECK_EQUAL(idCert->getName(), readCert->getName());