Add certificate field to client config and use bool for probe field in ca config
Change-Id: Ib1dcaf07cdb214ea777a26adaed12e488663b3b3
diff --git a/src/client-config.cpp b/src/client-config.cpp
index c75615d..7fd5280 100644
--- a/src/client-config.cpp
+++ b/src/client-config.cpp
@@ -19,6 +19,7 @@
*/
#include "client-config.hpp"
+#include <ndn-cxx/util/io.hpp>
namespace ndn {
namespace ndncert {
@@ -48,11 +49,14 @@
auto caList = m_config.get_child("ca-list");
auto it = caList.begin();
for (; it != caList.end(); it++) {
- CaItem item;
+ ClientCaItem item;
item.m_caName = Name(it->second.get<std::string>("ca-prefix"));
item.m_caInfo = it->second.get<std::string>("ca-info");
item.m_probe = it->second.get("probe", "");
+ std::istringstream ss(it->second.get<std::string>("certificate"));
+ item.m_anchor = *(io::load<security::v2::Certificate>(ss));
+
auto challengeList = it->second.get_child("supported-challenges");
item.m_supportedChallenges = parseChallengeList(challengeList);
@@ -61,7 +65,7 @@
}
std::list<std::string>
-ClientConfig::parseChallengeList(const ConfigSection& section)
+ClientConfig::parseChallengeList(const JsonSection& section)
{
std::list<std::string> result;
auto it = section.begin();
@@ -72,43 +76,15 @@
}
void
-ClientConfig::addNewCaItem(const CaItem& item)
+ClientConfig::addNewCaItem(const ClientCaItem& item)
{
- auto& caList = m_config.get_child("ca-list");
-
- ConfigSection newCaItem;
- ConfigSection newCaChallengeList;
- newCaItem.put("ca-prefix", item.m_caName.toUri());
- newCaItem.put("ca-info", item.m_caInfo);
- if (item.m_probe != "") {
- newCaItem.put("probe", item.m_probe);
- }
- for (const auto& challengeType : item.m_supportedChallenges) {
- ConfigSection challengeSection;
- challengeSection.put("type", challengeType);
- newCaChallengeList.push_back(std::make_pair("", challengeSection));
- }
- newCaItem.add_child("supported-challenges", newCaChallengeList);
- caList.push_back(std::make_pair("", newCaItem));
-
- parse();
+ m_caItems.push_back(item);
}
void
ClientConfig::removeCaItem(const Name& caName)
{
- auto& caList = m_config.get_child("ca-list");
- auto it = caList.begin();
- while (it != caList.end()) {
- if (it->second.get<std::string>("ca-prefix") == caName.toUri()) {
- it = caList.erase(it);
- break;
- }
- else {
- it++;
- }
- }
- parse();
+ m_caItems.remove_if([&] (const ClientCaItem& item) {return item.m_caName == caName;});
}
} // namespace ndncert