merge ca config and client config, remove old format of probe
Change-Id: I73500f532f166851d82c1bf1cc008c7ffc241ef3
diff --git a/src/protocol-detail/error.hpp b/src/protocol-detail/error.hpp
index 1234233..8a2cda0 100644
--- a/src/protocol-detail/error.hpp
+++ b/src/protocol-detail/error.hpp
@@ -21,8 +21,7 @@
#ifndef NDNCERT_PROTOCOL_DETAIL_ERROR_HPP
#define NDNCERT_PROTOCOL_DETAIL_ERROR_HPP
-#include "../ca-config.hpp"
-#include "../client-config.hpp"
+#include "../configuration.hpp"
namespace ndn {
namespace ndncert {
diff --git a/src/protocol-detail/info.cpp b/src/protocol-detail/info.cpp
index 59cc48e..306d060 100644
--- a/src/protocol-detail/info.cpp
+++ b/src/protocol-detail/info.cpp
@@ -24,14 +24,15 @@
namespace ndncert {
Block
-INFO::encodeDataContent(const CaConfig& caConfig, const security::v2::Certificate& certificate)
+INFO::encodeDataContent(const CaConfigItem& caConfig, const security::v2::Certificate& certificate)
{
auto content = makeEmptyBlock(tlv::Content);
content.push_back(makeNestedBlock(tlv_ca_prefix, caConfig.m_caPrefix));
std::string caInfo = "";
if (caConfig.m_caInfo == "") {
caInfo = "Issued by " + certificate.getSignature().getKeyLocator().getName().toUri();
- } else {
+ }
+ else {
caInfo = caConfig.m_caInfo;
}
content.push_back(makeStringBlock(tlv_ca_info, caInfo));
@@ -41,38 +42,42 @@
}
content.push_back(makeNonNegativeIntegerBlock(tlv_max_validity_period, caConfig.m_maxValidityPeriod.count()));
content.push_back(makeNestedBlock(tlv_ca_certificate, certificate));
- content.push_back(makeNonNegativeIntegerBlock(tlv_max_suffix_length, caConfig.m_maxSuffixLength));
+ if (caConfig.m_maxSuffixLength) {
+ content.push_back(makeNonNegativeIntegerBlock(tlv_max_suffix_length, *caConfig.m_maxSuffixLength));
+ }
content.encode();
return content;
}
-ClientCaItem
-INFO::decodeClientConfigFromContent(const Block& block)
+CaConfigItem
+INFO::decodeDataContentToCaProfile(const Block& block)
{
- ClientCaItem result;
+ CaConfigItem result;
block.parse();
for (auto const& item : block.elements()) {
- if (item.type() == tlv_ca_prefix) {
- item.parse();
+ item.parse();
+ switch (item.type()) {
+ case tlv_ca_prefix:
result.m_caPrefix.wireDecode(item.get(tlv::Name));
- }
- else if (item.type() == tlv_ca_info) {
+ break;
+ case tlv_ca_info:
result.m_caInfo = readString(item);
- }
- else if (item.type() == tlv_parameter_key) {
+ break;
+ case tlv_parameter_key:
result.m_probeParameterKeys.push_back(readString(item));
- }
- else if (item.type() == tlv_max_validity_period) {
+ break;
+ case tlv_max_validity_period:
result.m_maxValidityPeriod = time::seconds(readNonNegativeInteger(item));
- }
- else if (item.type() == tlv_ca_certificate) {
- item.parse();
- result.m_anchor.wireDecode(item.get(tlv::Data));
- } else if (item.type() == tlv_max_suffix_length) {
+ break;
+ case tlv_max_suffix_length:
result.m_maxSuffixLength = readNonNegativeInteger(item);
- }
- else {
+ break;
+ case tlv_ca_certificate:
+ result.m_cert->wireDecode(item.get(tlv::Data));
+ break;
+ default:
continue;
+ break;
}
}
return result;
diff --git a/src/protocol-detail/info.hpp b/src/protocol-detail/info.hpp
index a21040e..1c375bb 100644
--- a/src/protocol-detail/info.hpp
+++ b/src/protocol-detail/info.hpp
@@ -21,8 +21,7 @@
#ifndef NDNCERT_PROTOCOL_DETAIL_INFO_HPP
#define NDNCERT_PROTOCOL_DETAIL_INFO_HPP
-#include "../ca-config.hpp"
-#include "../client-config.hpp"
+#include "../configuration.hpp"
namespace ndn {
namespace ndncert {
@@ -33,13 +32,13 @@
* Encode CA configuration and its certificate into a TLV block as INFO Data packet content.
*/
static Block
- encodeDataContent(const CaConfig& caConfig, const security::v2::Certificate& certificate);
+ encodeDataContent(const CaConfigItem& caConfig, const security::v2::Certificate& certificate);
/**
* Decode CA configuration from the TLV block of INFO Data packet content.
*/
- static ClientCaItem
- decodeClientConfigFromContent(const Block& block);
+ static CaConfigItem
+ decodeDataContentToCaProfile(const Block& block);
};
} // namespace ndncert
diff --git a/src/protocol-detail/probe.cpp b/src/protocol-detail/probe.cpp
index 34b769e..93ba020 100644
--- a/src/protocol-detail/probe.cpp
+++ b/src/protocol-detail/probe.cpp
@@ -26,39 +26,13 @@
namespace ndncert {
// For Client
-std::vector<std::string>
-PROBE::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;
-}
-
Block
-PROBE::encodeApplicationParametersFromProbeInfo(const ClientCaItem& ca, const std::string& probeInfo)
+PROBE::encodeApplicationParameters(std::vector<std::tuple<std::string, std::string>>&& parameters)
{
auto content = makeEmptyBlock(tlv::ApplicationParameters);
-
- std::vector<std::string> fields = parseProbeComponents(ca.m_probe);
- std::vector<std::string> arguments = parseProbeComponents(probeInfo);
- ;
-
- if (arguments.size() != fields.size()) {
- BOOST_THROW_EXCEPTION(std::runtime_error("Error in genProbeRequestJson: argument list does not match field list in the config file."));
- }
-
- for (size_t i = 0; i < fields.size(); ++i) {
- content.push_back(
- makeStringBlock(tlv_parameter_key, fields.at(i)));
- content.push_back(
- makeStringBlock(tlv_parameter_value, arguments.at(i)));
+ for (size_t i = 0; i < parameters.size(); ++i) {
+ content.push_back(makeStringBlock(tlv_parameter_key, std::get<0>(parameters[i])));
+ content.push_back(makeStringBlock(tlv_parameter_value, std::get<1>(parameters[i])));
}
content.encode();
return content;
@@ -66,29 +40,15 @@
// For CA
Block
-PROBE::encodeDataContent(const Name& identifier, const std::string& m_probe, const Block& parameterTLV)
+PROBE::encodeDataContent(const std::vector<Name>& identifiers, boost::optional<size_t> maxSuffixLength)
{
- std::vector<std::string> fields;
- std::string delimiter = ":";
- size_t last = 0;
- size_t next = 0;
- while ((next = m_probe.find(delimiter, last)) != std::string::npos) {
- fields.push_back(m_probe.substr(last, next - last));
- last = next + 1;
- }
- fields.push_back(m_probe.substr(last));
-
Block content = makeEmptyBlock(tlv::Content);
-
- // TODO: Currently have no mechanism to utilize the given params to determine name
- //for (size_t i = 0; i < fields.size(); ++i) {
- // root.put(fields.at(i), parameterJson.get(fields.at(i), ""));
- //}
-
- content.push_back(makeNestedBlock(tlv_probe_response, identifier));
-
- // TODO: Must be determined based on CA config
- content.push_back(makeEmptyBlock(tlv_allow_longer_name));
+ for (const auto& name : identifiers) {
+ content.push_back(makeNestedBlock(tlv_probe_response, name));
+ }
+ if (maxSuffixLength) {
+ content.push_back(makeNonNegativeIntegerBlock(tlv_max_suffix_length, *maxSuffixLength));
+ }
content.encode();
return content;
}
diff --git a/src/protocol-detail/probe.hpp b/src/protocol-detail/probe.hpp
index 41b73c8..126fba4 100644
--- a/src/protocol-detail/probe.hpp
+++ b/src/protocol-detail/probe.hpp
@@ -21,22 +21,18 @@
#ifndef NDNCERT_PROTOCOL_DETAIL_PROBE_HPP
#define NDNCERT_PROTOCOL_DETAIL_PROBE_HPP
-#include "../ca-config.hpp"
-#include "../client-config.hpp"
+#include "../configuration.hpp"
namespace ndn {
namespace ndncert {
class PROBE {
public:
- static std::vector<std::string>
- parseProbeComponents(const std::string& probe);
+ static Block
+ encodeApplicationParameters(std::vector<std::tuple<std::string, std::string>>&& parameters);
static Block
- encodeApplicationParametersFromProbeInfo(const ClientCaItem& ca, const std::string& probeInfo);
-
- static Block
- encodeDataContent(const Name& identifier, const std::string& m_probe, const Block& parameterTLV);
+ encodeDataContent(const std::vector<Name>& identifiers, boost::optional<size_t> maxSuffixLength);
};
} // namespace ndncert