define common name component and adjust code layout

Change-Id: Ibe7e0a92ab79b03c3d5aa4bb0f77f571f999958b
diff --git a/src/encryptor.cpp b/src/algo/encryptor.cpp
similarity index 92%
rename from src/encryptor.cpp
rename to src/algo/encryptor.cpp
index 06ee785..c3b8884 100644
--- a/src/encryptor.cpp
+++ b/src/algo/encryptor.cpp
@@ -48,10 +48,12 @@
   KeyLocator keyLocator(keyName);
 
   switch (algType) {
-    case tlv::AlgorithmAesCbc:
     case tlv::AlgorithmAesEcb: {
+      const Buffer& encryptedPayload = Aes::encrypt(key, keyLen, payload, payloadLen, params);
+      return EncryptedContent(algType, keyLocator, encryptedPayload.buf(), encryptedPayload.size(), iv.buf(), iv.size());
+    }
+    case tlv::AlgorithmAesCbc: {
       BOOST_ASSERT(iv.size() == static_cast<size_t>(AES::BLOCKSIZE));
-
       const Buffer& encryptedPayload = Aes::encrypt(key, keyLen, payload, payloadLen, params);
       return EncryptedContent(algType, keyLocator, encryptedPayload.buf(), encryptedPayload.size(), iv.buf(), iv.size());
     }
@@ -96,6 +98,9 @@
             const Name& keyName, const uint8_t* key, size_t keyLen,
             const EncryptParams& params)
 {
+  Name dataName = data.getName();
+  dataName.append(NAME_COMPONENT_FOR).append(keyName);
+  data.setName(dataName);
   switch(params.getAlgorithmType()) {
     case tlv::AlgorithmAesCbc:
     case tlv::AlgorithmAesEcb: {
diff --git a/src/encryptor.hpp b/src/algo/encryptor.hpp
similarity index 100%
rename from src/encryptor.hpp
rename to src/algo/encryptor.hpp
diff --git a/src/common.hpp b/src/common.hpp
index 4b39994..8844b72 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -101,6 +101,14 @@
 namespace time = ndn::time;
 namespace signal = ndn::util::signal;
 
+const ndn::name::Component NAME_COMPONENT_FOR("FOR");
+const ndn::name::Component NAME_COMPONENT_READ("READ");
+const ndn::name::Component NAME_COMPONENT_SAMPLE("SAMPLE");
+const ndn::name::Component NAME_COMPONENT_ACCESS("ACCESS");
+const ndn::name::Component NAME_COMPONENT_E_KEY("E-KEY");
+const ndn::name::Component NAME_COMPONENT_D_KEY("D-KEY");
+const ndn::name::Component NAME_COMPONENT_C_KEY("C-KEY");
+
 } // namespace gep
 } // namespace ndn
 
diff --git a/src/group-manager.cpp b/src/group-manager.cpp
index b19ac20..64a4e8c 100644
--- a/src/group-manager.cpp
+++ b/src/group-manager.cpp
@@ -20,7 +20,7 @@
  */
 
 #include "group-manager.hpp"
-#include "encryptor.hpp"
+#include "algo/encryptor.hpp"
 #include "encrypted-content.hpp"
 
 #include <map>
@@ -28,11 +28,6 @@
 namespace ndn {
 namespace gep {
 
-static const name::Component E_KEY_COMPONENT("E-KEY");
-static const name::Component D_KEY_COMPONENT("D-KEY");
-static const name::Component READ_COMPONENT("read");
-static const name::Component FOR_COMPONENT("FOR");
-
 GroupManager::GroupManager(const Name& prefix, const Name& dataType, const std::string& dbDir,
                            const int paramLength, const int freshPeriod)
   : m_namespace(prefix)
@@ -40,7 +35,7 @@
   , m_paramLength(paramLength)
   , m_freshPeriod(freshPeriod)
 {
-  m_namespace.append(READ_COMPONENT).append(dataType);
+  m_namespace.append(NAME_COMPONENT_READ).append(dataType);
 }
 
 std::list<Data>
@@ -181,7 +176,7 @@
                              const Buffer& pubKeyBuf)
 {
   Name name(m_namespace);
-  name.append(E_KEY_COMPONENT).append(startTs).append(endTs);
+  name.append(NAME_COMPONENT_E_KEY).append(startTs).append(endTs);
   Data data(name);
   data.setFreshnessPeriod(time::hours(m_freshPeriod));
   data.setContent(pubKeyBuf.get(), pubKeyBuf.size());
@@ -195,8 +190,8 @@
                              const Buffer& certKey)
 {
   Name name(m_namespace);
-  name.append(D_KEY_COMPONENT);
-  name.append(startTs).append(endTs).append(FOR_COMPONENT).append(keyName);
+  name.append(NAME_COMPONENT_D_KEY);
+  name.append(startTs).append(endTs);
   Data data = Data(name);
   data.setFreshnessPeriod(time::hours(m_freshPeriod));
   algo::EncryptParams eparams(tlv::AlgorithmRsaPkcs);
diff --git a/tests/unit-tests/aes.t.cpp b/tests/unit-tests/algo/aes.t.cpp
similarity index 100%
rename from tests/unit-tests/aes.t.cpp
rename to tests/unit-tests/algo/aes.t.cpp
diff --git a/tests/unit-tests/encryptor.t.cpp b/tests/unit-tests/algo/encryptor.t.cpp
similarity index 97%
rename from tests/unit-tests/encryptor.t.cpp
rename to tests/unit-tests/algo/encryptor.t.cpp
index 7c89d76..d6c0451 100644
--- a/tests/unit-tests/encryptor.t.cpp
+++ b/tests/unit-tests/algo/encryptor.t.cpp
@@ -19,7 +19,7 @@
 
 #include "random-number-generator.hpp"
 #include "encrypted-content.hpp"
-#include "encryptor.hpp"
+#include "algo/encryptor.hpp"
 #include "algo/rsa.hpp"
 #include "algo/aes.hpp"
 
@@ -137,7 +137,6 @@
 typedef boost::mpl::list<TestDataAesCbc,
                          TestDataAesEcb> EncryptorAesTestInputs;
 
-
 BOOST_AUTO_TEST_CASE_TEMPLATE(ContentSymmetricEncrypt, T, EncryptorAesTestInputs)
 {
   T input;
@@ -146,6 +145,8 @@
   encryptData(data, input.plainText.buf(), input.plainText.size(),
               input.keyName, input.key.buf(), input.key.size(), input.encryptParams);
 
+  BOOST_CHECK_EQUAL(data.getName(), Name("/FOR").append(input.keyName));
+
   BOOST_CHECK_EQUAL_COLLECTIONS(input.encryptedContent.begin(), input.encryptedContent.end(),
                                 data.getContent().wire(), data.getContent().wire() + data.getContent().size());
 
@@ -210,6 +211,8 @@
   encryptData(data, raw_content, sizeof(raw_content),
               keyName, eKey.buf(), eKey.size(), encryptParams);
 
+  BOOST_CHECK_EQUAL(data.getName(), Name("/FOR").append(keyName));
+
   Block dataContent = data.getContent();
   dataContent.parse();
   BOOST_CHECK_EQUAL(dataContent.elements_size(), 1);
@@ -284,6 +287,8 @@
   encryptData(data, large_content, sizeof(large_content),
               keyName, eKey.buf(), eKey.size(), encryptParams);
 
+  BOOST_CHECK_EQUAL(data.getName(), Name("/FOR").append(keyName));
+
   Block largeDataContent = data.getContent();
   largeDataContent.parse();
   BOOST_CHECK_EQUAL(largeDataContent.elements_size(), 2);
diff --git a/tests/unit-tests/rsa.t.cpp b/tests/unit-tests/algo/rsa.t.cpp
similarity index 100%
rename from tests/unit-tests/rsa.t.cpp
rename to tests/unit-tests/algo/rsa.t.cpp
diff --git a/tests/unit-tests/group-manager.t.cpp b/tests/unit-tests/group-manager.t.cpp
index 4564939..abf78e7 100644
--- a/tests/unit-tests/group-manager.t.cpp
+++ b/tests/unit-tests/group-manager.t.cpp
@@ -225,7 +225,7 @@
 
   Data data = manager.createEKeyData("20150825T090000", "20150825T110000", encryptKeyBuf);
   BOOST_CHECK_EQUAL(data.getName().toUri(),
-                    "/Alice/read/data_type/E-KEY/20150825T090000/20150825T110000");
+                    "/Alice/READ/data_type/E-KEY/20150825T090000/20150825T110000");
 
   Buffer contentBuf(data.getContent().value(), data.getContent().value_size());
   BOOST_CHECK_EQUAL_COLLECTIONS(encryptKeyBuf.begin(), encryptKeyBuf.end(),
@@ -285,14 +285,14 @@
   // first data contain the group encrypt key(public key)
   std::list<Data>::iterator dataIterator = result.begin();
   BOOST_CHECK_EQUAL(dataIterator->getName().toUri(),
-                    "/Alice/read/data_type/E-KEY/20150825T090000/20150825T100000");
+                    "/Alice/READ/data_type/E-KEY/20150825T090000/20150825T100000");
   EncryptKey<algo::Rsa> groupEKey(Buffer(dataIterator->getContent().value(),
                                          dataIterator->getContent().value_size()));
 
   // second data and decrypt
   dataIterator++;
   BOOST_CHECK_EQUAL(dataIterator->getName().toUri(),
-                    "/Alice/read/data_type/D-KEY/20150825T090000/20150825T100000/FOR/ndn/memberA/ksk-123");
+                    "/Alice/READ/data_type/D-KEY/20150825T090000/20150825T100000/FOR/ndn/memberA/ksk-123");
 
   //////////////////////////////////////////////////////////////////////// start decryption
   Block dataContent = dataIterator->getContent();
@@ -343,12 +343,12 @@
   // third data and decrypt
   dataIterator++;
   BOOST_CHECK_EQUAL(dataIterator->getName().toUri(),
-                    "/Alice/read/data_type/D-KEY/20150825T090000/20150825T100000/FOR/ndn/memberB/ksk-123");
+                    "/Alice/READ/data_type/D-KEY/20150825T090000/20150825T100000/FOR/ndn/memberB/ksk-123");
 
   // second data and decrypt
   dataIterator++;
   BOOST_CHECK_EQUAL(dataIterator->getName().toUri(),
-                    "/Alice/read/data_type/D-KEY/20150825T090000/20150825T100000/FOR/ndn/memberC/ksk-123");
+                    "/Alice/READ/data_type/D-KEY/20150825T090000/20150825T100000/FOR/ndn/memberC/ksk-123");
 
   // invalid time stamp to get group key
   TimeStamp tp2(from_iso_string("20150826T083000"));