Polish the code in ca-config.cpp

Change-Id: Id0ed31647ccf3b48639fae238f93d903097c5064
diff --git a/src/ca-config.cpp b/src/ca-config.cpp
index c615e49..1bd8e04 100644
--- a/src/ca-config.cpp
+++ b/src/ca-config.cpp
@@ -19,13 +19,13 @@
  */
 
 #include "ca-config.hpp"
-#include "challenge-module.hpp"
 
 #include <boost/filesystem.hpp>
-#include <ndn-cxx/util/io.hpp>
-#include <boost/property_tree/ptree.hpp>
 #include <boost/property_tree/json_parser.hpp>
-#include <boost/property_tree/info_parser.hpp>
+#include <boost/property_tree/ptree.hpp>
+#include <ndn-cxx/util/io.hpp>
+
+#include "challenge-module.hpp"
 
 namespace ndn {
 namespace ndncert {
@@ -38,10 +38,10 @@
     boost::property_tree::read_json(fileName, configJson);
   }
   catch (const std::exception& error) {
-    BOOST_THROW_EXCEPTION(Error("Failed to parse configuration file " + fileName + ", " + error.what()));
+    BOOST_THROW_EXCEPTION(std::runtime_error("Failed to parse configuration file " + fileName + ", " + error.what()));
   }
   if (configJson.begin() == configJson.end()) {
-    BOOST_THROW_EXCEPTION(Error("Error processing configuration file: " + fileName + " no data"));
+    BOOST_THROW_EXCEPTION(std::runtime_error("std::runtime_error processing configuration file: " + fileName + " no data"));
   }
   parse(configJson);
 }
@@ -52,7 +52,7 @@
   // CA prefix
   m_caPrefix = Name(configJson.get(CONFIG_CA_PREFIX, ""));
   if (m_caPrefix.empty()) {
-    BOOST_THROW_EXCEPTION(Error("Cannot parse ca-prefix from the config file"));
+    BOOST_THROW_EXCEPTION(std::runtime_error("Cannot parse ca-prefix from the config file"));
   }
   // CA info
   m_caInfo = configJson.get(CONFIG_CA_INFO, "");
@@ -68,7 +68,7 @@
   m_supportedChallenges.clear();
   auto challengeList = configJson.get_child_optional(CONFIG_SUPPORTED_CHALLENGES);
   if (!challengeList) {
-    BOOST_THROW_EXCEPTION(Error("Cannot parse challenge list"));
+    BOOST_THROW_EXCEPTION(std::runtime_error("Cannot parse challenge list"));
   }
   parseChallengeList(*challengeList);
 }
@@ -76,13 +76,12 @@
 void
 CaConfig::parseProbeParameters(const JsonSection& section)
 {
-  auto it = section.begin();
-  for (; it != section.end(); it++) {
-    auto probeParameter = it->second.get(CONFIG_PROBE_PARAMETER, "");
-    if (probeParameter == "") {
-      BOOST_THROW_EXCEPTION(Error("Cannot read probe-parameter-key in probe-parameters from the config file"));
-    }
+  for (const auto item : section) {
+    auto probeParameter = item.second.get(CONFIG_PROBE_PARAMETER, "");
     probeParameter = boost::algorithm::to_lower_copy(probeParameter);
+    if (probeParameter == "") {
+      BOOST_THROW_EXCEPTION(std::runtime_error("Cannot read probe-parameter-key in probe-parameters from the config file"));
+    }
     m_probeParameterKeys.push_back(probeParameter);
   }
 }
@@ -90,20 +89,19 @@
 void
 CaConfig::parseChallengeList(const JsonSection& section)
 {
-  auto it = section.begin();
-  for (; it != section.end(); it++) {
-    auto challengeType = it->second.get(CONFIG_CHALLENGE, "");
-    if (challengeType == "") {
-      BOOST_THROW_EXCEPTION(Error("Cannot read type in supported-challenges from the config file"));
-    }
+  for (const auto item : section) {
+    auto challengeType = item.second.get(CONFIG_CHALLENGE, "");
     challengeType = boost::algorithm::to_lower_copy(challengeType);
+    if (challengeType == "") {
+      BOOST_THROW_EXCEPTION(std::runtime_error("Cannot read type in supported-challenges from the config file"));
+    }
     if (!ChallengeModule::supportChallenge(challengeType)) {
-      BOOST_THROW_EXCEPTION(Error("Does not support challenge read from the config file"));
+      BOOST_THROW_EXCEPTION(std::runtime_error("Does not support challenge read from the config file"));
     }
     m_supportedChallenges.push_back(challengeType);
   }
   if (m_supportedChallenges.size() == 0) {
-    BOOST_THROW_EXCEPTION(Error("At least one challenge should be identified under supported-challenges"));
+    BOOST_THROW_EXCEPTION(std::runtime_error("At least one challenge should be identified under supported-challenges"));
   }
 }
 
diff --git a/src/ca-config.hpp b/src/ca-config.hpp
index 4855aca..e624e34 100644
--- a/src/ca-config.hpp
+++ b/src/ca-config.hpp
@@ -21,10 +21,9 @@
 #ifndef NDNCERT_CA_CONFIG_HPP
 #define NDNCERT_CA_CONFIG_HPP
 
-#include <ndn-cxx/security/v2/certificate.hpp>
-
 #include "certificate-request.hpp"
 #include "client-config.hpp"
+#include <ndn-cxx/security/v2/certificate.hpp>
 
 namespace ndn {
 namespace ndncert {
@@ -38,7 +37,6 @@
  * @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.
  */
-// using ProbeHandler = function<std::string /*identity name*/ (const Block& tlv /*requester input*/)>;
 using NameAssignmentFunc = function<std::vector<std::string>(const std::vector<std::tuple<std::string, std::string>>)>;
 
 /**
@@ -76,42 +74,17 @@
 class CaConfig {
 public:
   /**
-   * @brief Error that can be thrown from CaConfig
-   */
-  class Error : public std::runtime_error {
-  public:
-    using std::runtime_error::runtime_error;
-  };
-
-public:
-  /**
    * Load CA configuration from the file.
    *
    * @param fileName, the configuration file name.
-   * @throw CaConfig::Error when config file does not exist or the configuration
+   * @throw std::runtime_error when config file does not exist or the configuration
    *        in the file cannot be parsed correctly.
-   * @throw CaConfig::Error when the ca-prefix attribute in JSON text is empty.
-   * @throw CaConfig::Error when the challenge is not specified or is not supported.
+   * @throw std::runtime_error when the ca-prefix attribute in JSON text is empty.
+   * @throw std::runtime_error when the challenge is not specified or is not supported.
    */
   void
   load(const std::string& fileName);
 
-  /**
-   * Set the NameAssignmentFunction.
-   */
-  // void
-  // setNameAssignmentFunc(const NameAssignmentFunc& nameAssignmentFunc) {
-  //   m_nameAssignmentFunc = nameAssignmentFunc;
-  // }
-
-  /**
-   * Set the StatusUpdateCallback.
-   */
-  void
-  setStatusUpdateCallback(const StatusUpdateCallback& statusUpdateCallback) {
-    m_statusUpdateCallback = statusUpdateCallback;
-  }
-
 private:
   void
   parse(const JsonSection& configJson);
diff --git a/tests/unit-tests/ca-config.t.cpp b/tests/unit-tests/ca-config.t.cpp
index 0538cd8..ef48457 100644
--- a/tests/unit-tests/ca-config.t.cpp
+++ b/tests/unit-tests/ca-config.t.cpp
@@ -44,19 +44,19 @@
 BOOST_AUTO_TEST_CASE(ReadNonexistConfigFile)
 {
   CaConfig config;
-  BOOST_CHECK_THROW(config.load("tests/unit-tests/Nonexist"), CaConfig::Error);
+  BOOST_CHECK_THROW(config.load("tests/unit-tests/Nonexist"), std::runtime_error);
 }
 
 BOOST_AUTO_TEST_CASE(ReadConfigFileWithoutCaPrefix)
 {
   CaConfig config;
-  BOOST_CHECK_THROW(config.load("tests/unit-tests/ca.conf.test2"), CaConfig::Error);
+  BOOST_CHECK_THROW(config.load("tests/unit-tests/ca.conf.test2"), std::runtime_error);
 }
 
 BOOST_AUTO_TEST_CASE(ReadConfigFileWithChallengeNotSupported)
 {
   CaConfig config;
-  BOOST_CHECK_THROW(config.load("tests/unit-tests/ca.conf.test3"), CaConfig::Error);
+  BOOST_CHECK_THROW(config.load("tests/unit-tests/ca.conf.test3"), std::runtime_error);
 }
 
 BOOST_AUTO_TEST_CASE(InfoContentEncodingDecoding)
@@ -76,8 +76,8 @@
   BOOST_CHECK_EQUAL(cert.wireEncode(), decoded.m_anchor.wireEncode());
 }
 
-BOOST_AUTO_TEST_SUITE_END() // TestCaConfig
+BOOST_AUTO_TEST_SUITE_END()  // TestCaConfig
 
-} // namespace tests
-} // namespace ndncert
-} // namespace ndn
+}  // namespace tests
+}  // namespace ndncert
+}  // namespace ndn