update ndncert client command line tool

Change-Id: Icf8ca4b35fe8fea41178cc91df38c3971358fda9
diff --git a/src/ca-module.cpp b/src/ca-module.cpp
index 74985aa..b6233e9 100644
--- a/src/ca-module.cpp
+++ b/src/ca-module.cpp
@@ -127,7 +127,10 @@
     // if not a PROBE INFO, find an available name
     std::string availableId = "";
     const auto& parameterJson = jsonFromBlock(request.getApplicationParameters());
-    //m_config.m_probe
+    if (parameterJson.empty()) {
+      _LOG_ERROR("Empty JSON obtained from the Interest parameter.");
+      return;
+    }
 
     //std::string probeInfoStr = parameterJson.get(JSON_CLIENT_PROBE_INFO, "");
     if (m_config.m_probeHandler) {
@@ -144,8 +147,8 @@
       availableId = std::to_string(random::generateSecureWord64());
     }
     Name newIdentityName = m_config.m_caName;
-    _LOG_TRACE("Handle PROBE: generate an identity " << newIdentityName);
     newIdentityName.append(availableId);
+    _LOG_TRACE("Handle PROBE: generate an identity " << newIdentityName);
     contentJson = genProbeResponseJson(newIdentityName.toUri(), m_config.m_probe, parameterJson);
   }
 
@@ -161,9 +164,12 @@
 CaModule::onNew(const Interest& request)
 {
   // NEW Naming Convention: /<CA-prefix>/CA/NEW/[SignedInterestParameters_Digest]
-
   // get ECDH pub key and cert request
   const auto& parameterJson = jsonFromBlock(request.getApplicationParameters());
+  if (parameterJson.empty()) {
+    _LOG_ERROR("Empty JSON obtained from the Interest parameter.");
+    return;
+  }
   std::string peerKeyBase64 = parameterJson.get(JSON_CLIENT_ECDH, "");
 
   // get server's ECDH pub key
diff --git a/src/client-module.cpp b/src/client-module.cpp
index d107114..b3af7dd 100644
--- a/src/client-module.cpp
+++ b/src/client-module.cpp
@@ -304,39 +304,34 @@
   return json;
 }
 
-const JsonSection
-ClientModule::genProbeRequestJson(const ClientCaItem& ca, const std::string& probeInfo)
+std::vector<std::string>
+ClientModule::parseProbeComponents(const std::string& probe)
 {
+  std::vector<std::string> components;
   std::string delimiter = ":";
   size_t last = 0;
   size_t next = 0;
+  while ((next = probe.find(delimiter, last)) != std::string::npos) {
+    components.push_back(probe.substr(last, next - last));
+    last = next + 1;
+  }
+  components.push_back(probe.substr(last));
+  return components;
+}
 
+const JsonSection
+ClientModule::genProbeRequestJson(const ClientCaItem& ca, const std::string& probeInfo)
+{
   JsonSection root;
-
-  std::vector<std::string> fields;
-  while ((next = ca.m_probe.find(delimiter, last)) != std::string::npos) {
-    fields.push_back(ca.m_probe.substr(last, next - last));
-    last = next + 1;
-  }
-  fields.push_back(ca.m_probe.substr(last));
-
-  std::vector<std::string> arguments;
-  last = 0;
-  next = 0;
-  while ((next = probeInfo.find(delimiter, last)) != std::string::npos) {
-    arguments.push_back(probeInfo.substr(last, next - last));
-    last = next + 1;
-  }
-  arguments.push_back(probeInfo.substr(last));
+  std::vector<std::string> fields = parseProbeComponents(ca.m_probe);
+  std::vector<std::string> arguments  = parseProbeComponents(probeInfo);;
 
   if (arguments.size() != fields.size()) {
     BOOST_THROW_EXCEPTION(Error("Error in genProbeRequestJson: argument list does not match field list in the config file."));
   }
-
   for (size_t i = 0; i < fields.size(); ++i) {
       root.put(fields.at(i), arguments.at(i));
   }
-
   return root;
 }
 
diff --git a/src/client-module.hpp b/src/client-module.hpp
index 388ad85..330b3c6 100644
--- a/src/client-module.hpp
+++ b/src/client-module.hpp
@@ -119,6 +119,9 @@
   static Block
   paramFromJson(const JsonSection& json);
 
+  static std::vector<std::string>
+  parseProbeComponents(const std::string& probe);
+
 PUBLIC_WITH_TESTS_ELSE_PRIVATE:
   const JsonSection
   genProbeRequestJson(const ClientCaItem& ca, const std::string& probeInfo);