some folder rename

Change-Id: I162718c60cab715d607211e0d1cc6302830211ff
diff --git a/src/name-assignment/assignment-func.cpp b/src/name-assignment/assignment-func.cpp
new file mode 100644
index 0000000..6a55cc2
--- /dev/null
+++ b/src/name-assignment/assignment-func.cpp
@@ -0,0 +1,59 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2017-2020, Regents of the University of California.
+ *
+ * This file is part of ndncert, a certificate management system based on NDN.
+ *
+ * ndncert is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * ndncert 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 General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License along with
+ * ndncert, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndncert authors and contributors.
+ */
+
+#include "assignment-func.hpp"
+#include <ndn-cxx/util/random.hpp>
+
+namespace ndn {
+namespace ndncert {
+
+NameAssignmentFunc::NameAssignmentFunc(const std::string& factoryType, const std::string& format)
+  : FACTORY_TYPE(factoryType)
+{
+  size_t index = 0, startIndex = 0;
+  while ((index = format.find("/", startIndex)) != std::string::npos) {
+    auto component = format.substr(startIndex, index - startIndex);
+    if (!component.empty()) {
+      m_nameFormat.push_back(component);
+    }
+    startIndex = index + 1;
+  }
+  if (startIndex != format.size()) {
+    m_nameFormat.push_back(format.substr(startIndex));
+  }
+}
+
+unique_ptr<NameAssignmentFunc>
+NameAssignmentFunc::createNameAssignmentFunc(const std::string& challengeType, const std::string& format)
+{
+  FuncFactoryFactory& factory = getFactory();
+  auto i = factory.find(challengeType);
+  return i == factory.end() ? nullptr : i->second(format);
+}
+
+NameAssignmentFunc::FuncFactoryFactory&
+NameAssignmentFunc::getFactory()
+{
+  static NameAssignmentFunc::FuncFactoryFactory factory;
+  return factory;
+}
+
+} // namespace ndncert
+} // namespace ndn
diff --git a/src/name-assignment/assignment-func.hpp b/src/name-assignment/assignment-func.hpp
new file mode 100644
index 0000000..355efdd
--- /dev/null
+++ b/src/name-assignment/assignment-func.hpp
@@ -0,0 +1,84 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2017-2020, Regents of the University of California.
+ *
+ * This file is part of ndncert, a certificate management system based on NDN.
+ *
+ * ndncert is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * ndncert 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 General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License along with
+ * ndncert, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndncert authors and contributors.
+ */
+
+#ifndef NDNCERT_ASSIGNMENT_FUNCS_HPP
+#define NDNCERT_ASSIGNMENT_FUNCS_HPP
+
+#include "../detail/ca-state.hpp"
+
+namespace ndn {
+namespace ndncert {
+
+class NameAssignmentFunc : noncopyable
+{
+public:
+  explicit NameAssignmentFunc(const std::string& factoryType, const std::string& format = "");
+
+  virtual ~NameAssignmentFunc() = default;
+
+  /**
+   * @brief The name assignment function provided by the CA operator to generate available
+   * namecomponents.
+   * The function does not guarantee that all the returned names are available. Therefore the
+   * CA should further check the availability of each returned name and remove unavailable results.
+   *
+   * @p vector, input, a list of parameter key-value pair used for name assignment.
+   * @return a vector containing the possible namespaces derived from the parameters.
+   */
+  virtual std::vector<PartialName>
+  assignName(const std::vector<std::tuple<std::string, std::string>>& params) = 0;
+
+  const std::string FACTORY_TYPE;
+  std::vector<std::string> m_nameFormat;
+
+public:
+  template <class ChallengeType>
+  static void
+  registerNameAssignmentFunc(const std::string& typeName)
+  {
+    FuncFactoryFactory& factory = getFactory();
+    BOOST_ASSERT(factory.count(typeName) == 0);
+    factory[typeName] = [](const std::string& format) { return std::make_unique<ChallengeType>(format); };
+  }
+
+  static unique_ptr<NameAssignmentFunc>
+  createNameAssignmentFunc(const std::string& challengeType, const std::string& format = "");
+
+private:
+  typedef function<unique_ptr<NameAssignmentFunc>(const std::string&)> FactoryCreateFunc;
+  typedef std::map<std::string, FactoryCreateFunc> FuncFactoryFactory;
+
+  static FuncFactoryFactory&
+  getFactory();
+};
+
+#define NDNCERT_REGISTER_FUNCFACTORY(C, T)                                        \
+  static class NdnCert##C##FuncFactoryRegistrationClass {                         \
+  public:                                                                         \
+    NdnCert##C##FuncFactoryRegistrationClass()                                    \
+    {                                                                             \
+      ::ndn::ndncert::NameAssignmentFunc::registerNameAssignmentFunc<C>(T);       \
+    }                                                                             \
+  } g_NdnCert##C##ChallengeRegistrationVariable
+
+} // namespace ndncert
+} // namespace ndn
+
+#endif // NDNCERT_ASSIGNMENT_FUNCS_HPP
diff --git a/src/name-assignment/assignment-hash.cpp b/src/name-assignment/assignment-hash.cpp
new file mode 100644
index 0000000..8f0e641
--- /dev/null
+++ b/src/name-assignment/assignment-hash.cpp
@@ -0,0 +1,55 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2017-2020, Regents of the University of California.
+ *
+ * This file is part of ndncert, a certificate management system based on NDN.
+ *
+ * ndncert is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * ndncert 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 General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License along with
+ * ndncert, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndncert authors and contributors.
+ */
+
+#include "assignment-hash.hpp"
+#include <ndn-cxx/util/sha256.hpp>
+
+namespace ndn {
+namespace ndncert {
+
+NDNCERT_REGISTER_FUNCFACTORY(AssignmentHash, "hash");
+
+AssignmentHash::AssignmentHash(const std::string& format)
+  : NameAssignmentFunc("hash", format)
+{}
+
+std::vector<PartialName>
+AssignmentHash::assignName(const std::vector<std::tuple<std::string, std::string>>& params)
+{
+  std::vector<PartialName> resultList;
+  Name result;
+  for (const auto& item : m_nameFormat) {
+    auto it = std::find_if(params.begin(), params.end(),
+                           [&](const std::tuple<std::string, std::string>& e) { return std::get<0>(e) == item; });
+    if (it != params.end()) {
+      util::Sha256 digest;
+      digest << std::get<1>(*it);
+      result.append(digest.toString());
+    }
+    else {
+      return resultList;
+    }
+  }
+  resultList.push_back(std::move(result));
+  return resultList;
+}
+
+} // namespace ndncert
+} // namespace ndn
diff --git a/src/name-assignment/assignment-hash.hpp b/src/name-assignment/assignment-hash.hpp
new file mode 100644
index 0000000..b0532f7
--- /dev/null
+++ b/src/name-assignment/assignment-hash.hpp
@@ -0,0 +1,46 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2017-2020, Regents of the University of California.
+ *
+ * This file is part of ndncert, a certificate management system based on NDN.
+ *
+ * ndncert is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * ndncert 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 General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License along with
+ * ndncert, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndncert authors and contributors.
+ */
+
+#ifndef NDNCERT_ASSIGNMENT_HASH_HPP
+#define NDNCERT_ASSIGNMENT_HASH_HPP
+
+#include "assignment-func.hpp"
+
+namespace ndn {
+namespace ndncert {
+
+/**
+ * assign names base on client probe parameter
+ */
+class AssignmentHash: public NameAssignmentFunc
+{
+public:
+  AssignmentHash(const std::string& format = "");
+
+  std::vector<PartialName>
+  assignName(const std::vector<std::tuple<std::string, std::string>>& params) override;
+
+};
+}
+}
+
+
+
+#endif //NDNCERT_ASSIGNMENT_HASH_HPP
diff --git a/src/name-assignment/assignment-param.cpp b/src/name-assignment/assignment-param.cpp
new file mode 100644
index 0000000..4ebe637
--- /dev/null
+++ b/src/name-assignment/assignment-param.cpp
@@ -0,0 +1,52 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2017-2020, Regents of the University of California.
+ *
+ * This file is part of ndncert, a certificate management system based on NDN.
+ *
+ * ndncert is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * ndncert 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 General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License along with
+ * ndncert, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndncert authors and contributors.
+ */
+
+#include "assignment-param.hpp"
+
+namespace ndn {
+namespace ndncert {
+
+NDNCERT_REGISTER_FUNCFACTORY(AssignmentParam, "param");
+
+AssignmentParam::AssignmentParam(const std::string& format)
+  : NameAssignmentFunc("param", format)
+{}
+
+std::vector<PartialName>
+AssignmentParam::assignName(const std::vector<std::tuple<std::string, std::string>>& params)
+{
+  std::vector<PartialName> resultList;
+  Name result;
+  for (const auto& item : m_nameFormat) {
+    auto it = std::find_if(params.begin(), params.end(),
+                           [&](const std::tuple<std::string, std::string>& e) { return std::get<0>(e) == item; });
+    if (it != params.end() && !std::get<1>(*it).empty()) {
+      result.append(std::get<1>(*it));
+    }
+    else {
+      return resultList;
+    }
+  }
+  resultList.push_back(std::move(result));
+  return resultList;
+}
+
+} // namespace ndncert
+} // namespace ndn
diff --git a/src/name-assignment/assignment-param.hpp b/src/name-assignment/assignment-param.hpp
new file mode 100644
index 0000000..cdbb410
--- /dev/null
+++ b/src/name-assignment/assignment-param.hpp
@@ -0,0 +1,44 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2017-2020, Regents of the University of California.
+ *
+ * This file is part of ndncert, a certificate management system based on NDN.
+ *
+ * ndncert is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * ndncert 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 General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License along with
+ * ndncert, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndncert authors and contributors.
+ */
+
+#ifndef NDNCERT_ASSIGNMENT_PARAM_HPP
+#define NDNCERT_ASSIGNMENT_PARAM_HPP
+
+#include "assignment-func.hpp"
+
+namespace ndn {
+namespace ndncert {
+
+/**
+ * assign names base on client probe parameter
+ */
+class AssignmentParam: public NameAssignmentFunc{
+public:
+  AssignmentParam(const std::string& format = "");
+
+  std::vector<PartialName>
+  assignName(const std::vector<std::tuple<std::string, std::string>>& params) override;
+};
+}
+}
+
+
+
+#endif //NDNCERT_ASSIGNMENT_PARAM_HPP
diff --git a/src/name-assignment/assignment-random.cpp b/src/name-assignment/assignment-random.cpp
new file mode 100644
index 0000000..7b24481
--- /dev/null
+++ b/src/name-assignment/assignment-random.cpp
@@ -0,0 +1,42 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2017-2020, Regents of the University of California.
+ *
+ * This file is part of ndncert, a certificate management system based on NDN.
+ *
+ * ndncert is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * ndncert 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 General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License along with
+ * ndncert, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndncert authors and contributors.
+ */
+
+#include "assignment-random.hpp"
+#include <ndn-cxx/util/random.hpp>
+
+namespace ndn {
+namespace ndncert {
+
+NDNCERT_REGISTER_FUNCFACTORY(AssignmentRandom, "random");
+
+AssignmentRandom::AssignmentRandom(const std::string& format)
+  : NameAssignmentFunc("random", format)
+{}
+
+std::vector<PartialName>
+AssignmentRandom::assignName(const std::vector<std::tuple<std::string, std::string>>& params)
+{
+  std::vector<PartialName> resultList;
+  resultList.emplace_back(to_string(random::generateSecureWord64()));
+  return resultList;
+}
+
+}
+}
diff --git a/src/name-assignment/assignment-random.hpp b/src/name-assignment/assignment-random.hpp
new file mode 100644
index 0000000..c65cd5d
--- /dev/null
+++ b/src/name-assignment/assignment-random.hpp
@@ -0,0 +1,44 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2017-2020, Regents of the University of California.
+ *
+ * This file is part of ndncert, a certificate management system based on NDN.
+ *
+ * ndncert is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * ndncert 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 General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License along with
+ * ndncert, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndncert authors and contributors.
+ */
+
+#ifndef NDNCERT_ASSIGNMENT_RANDOM_HPP
+#define NDNCERT_ASSIGNMENT_RANDOM_HPP
+
+#include "assignment-func.hpp"
+
+namespace ndn {
+namespace ndncert {
+
+/**
+ * assign names base on client probe parameter
+ */
+class AssignmentRandom: public NameAssignmentFunc
+{
+public:
+  AssignmentRandom(const std::string& format = "");
+
+  std::vector<PartialName>
+  assignName(const std::vector<std::tuple<std::string, std::string>>& params) override;
+};
+
+} // namespace ndncert
+} // namespace ndn
+
+#endif //NDNCERT_ASSIGNMENT_RANDOM_HPP