CR fix 3
Change-Id: If6802a52f48870a1fe3c42d57d7797a5f5248b26
diff --git a/src/detail/probe-encoder.cpp b/src/detail/probe-encoder.cpp
index 2a5fa08..f040d2e 100644
--- a/src/detail/probe-encoder.cpp
+++ b/src/detail/probe-encoder.cpp
@@ -24,25 +24,25 @@
namespace ndncert {
Block
-probeEncoder::encodeApplicationParameters(std::vector<std::tuple<std::string, std::string>>&& parameters)
+probeEncoder::encodeApplicationParameters(std::multimap<std::string, std::string>&& parameters)
{
Block content(ndn::tlv::ApplicationParameters);
- for (size_t i = 0; i < parameters.size(); ++i) {
- content.push_back(makeStringBlock(tlv::ParameterKey, std::get<0>(parameters[i])));
- content.push_back(makeStringBlock(tlv::ParameterValue, std::get<1>(parameters[i])));
+ for (const auto& items : parameters) {
+ content.push_back(makeStringBlock(tlv::ParameterKey, items.first));
+ content.push_back(makeStringBlock(tlv::ParameterValue, items.second));
}
content.encode();
return content;
}
-std::vector<std::tuple<std::string, std::string>>
+std::multimap<std::string, std::string>
probeEncoder::decodeApplicationParameters(const Block& block)
{
- std::vector<std::tuple<std::string, std::string>> result;
+ std::multimap<std::string, std::string> result;
block.parse();
for (size_t i = 0; i < block.elements().size() - 1; i++) {
if (block.elements()[i].type() == tlv::ParameterKey && block.elements()[i + 1].type() == tlv::ParameterValue) {
- result.emplace_back(readString(block.elements().at(i)), readString(block.elements().at(i + 1)));
+ result.emplace(readString(block.elements().at(i)), readString(block.elements().at(i + 1)));
i ++;
}
}
diff --git a/src/detail/probe-encoder.hpp b/src/detail/probe-encoder.hpp
index 03d216e..3985f93 100644
--- a/src/detail/probe-encoder.hpp
+++ b/src/detail/probe-encoder.hpp
@@ -29,7 +29,7 @@
// For Client use
Block
- encodeApplicationParameters(std::vector<std::tuple<std::string, std::string>>&& parameters);
+ encodeApplicationParameters(std::multimap<std::string, std::string>&& parameters);
void
decodeDataContent(const Block& block, std::vector<std::pair<Name, int>>& availableNames,
@@ -41,7 +41,7 @@
optional<size_t> maxSuffixLength = nullopt,
optional<std::vector<std::shared_ptr<security::Certificate>>> redirectionItems = nullopt);
- std::vector<std::tuple<std::string, std::string>>
+ std::multimap<std::string, std::string>
decodeApplicationParameters(const Block& block);
} // namespace ProbeEncoder
} // namespace ndncert
diff --git a/src/identity-challenge/challenge-credential.cpp b/src/identity-challenge/challenge-credential.cpp
index 7e72805..a9ebe1c 100644
--- a/src/identity-challenge/challenge-credential.cpp
+++ b/src/identity-challenge/challenge-credential.cpp
@@ -121,13 +121,13 @@
}
// For Client
-std::vector<std::tuple<std::string, std::string>>
+std::multimap<std::string, std::string>
ChallengeCredential::getRequestedParameterList(Status status, const std::string& challengeStatus)
{
- std::vector<std::tuple<std::string, std::string>> result;
+ std::multimap<std::string, std::string> result;
if (status == Status::BEFORE_CHALLENGE) {
- result.push_back(std::make_tuple(PARAMETER_KEY_CREDENTIAL_CERT, "Please provide the certificate issued by a trusted CA."));
- result.push_back(std::make_tuple(PARAMETER_KEY_PROOF_OF_PRIVATE_KEY, "Please sign a Data packet with request ID as the content."));
+ result.emplace(PARAMETER_KEY_CREDENTIAL_CERT, "Please provide the certificate issued by a trusted CA.");
+ result.emplace(PARAMETER_KEY_PROOF_OF_PRIVATE_KEY, "Please sign a Data packet with request ID as the content.");
return result;
}
NDN_THROW(std::runtime_error("Unexpected status or challenge status."));
@@ -135,7 +135,7 @@
Block
ChallengeCredential::genChallengeRequestTLV(Status status, const std::string& challengeStatus,
- std::vector<std::tuple<std::string, std::string>>&& params)
+ std::multimap<std::string, std::string>&& params)
{
Block request(tlv::EncryptedPayload);
if (status == Status::BEFORE_CHALLENGE) {
@@ -170,7 +170,7 @@
}
void
-ChallengeCredential::fulfillParameters(std::vector<std::tuple<std::string, std::string>>& params,
+ChallengeCredential::fulfillParameters(std::multimap<std::string, std::string>& params,
KeyChain& keyChain, const Name& issuedCertName, const RequestId& requestId)
{
auto& pib = keyChain.getPib();
diff --git a/src/identity-challenge/challenge-credential.hpp b/src/identity-challenge/challenge-credential.hpp
index 72db981..7b48483 100644
--- a/src/identity-challenge/challenge-credential.hpp
+++ b/src/identity-challenge/challenge-credential.hpp
@@ -56,15 +56,15 @@
handleChallengeRequest(const Block& params, ca::RequestState& request) override;
// For Client
- std::vector<std::tuple<std::string, std::string>>
+ std::multimap<std::string, std::string>
getRequestedParameterList(Status status, const std::string& challengeStatus) override;
Block
genChallengeRequestTLV(Status status, const std::string& challengeStatus,
- std::vector<std::tuple<std::string, std::string>>&& params) override;
+ std::multimap<std::string, std::string>&& params) override;
static void
- fulfillParameters(std::vector<std::tuple<std::string, std::string>>& params,
+ fulfillParameters(std::multimap<std::string, std::string>& params,
KeyChain& keyChain, const Name& issuedCertName, const RequestId& requestId);
// challenge parameters
diff --git a/src/identity-challenge/challenge-email.cpp b/src/identity-challenge/challenge-email.cpp
index 332ef96..8b08d82 100644
--- a/src/identity-challenge/challenge-email.cpp
+++ b/src/identity-challenge/challenge-email.cpp
@@ -103,18 +103,18 @@
}
// For Client
-std::vector<std::tuple<std::string, std::string>>
+std::multimap<std::string, std::string>
ChallengeEmail::getRequestedParameterList(Status status, const std::string& challengeStatus)
{
- std::vector<std::tuple<std::string, std::string>> result;
+ std::multimap<std::string, std::string> result;
if (status == Status::BEFORE_CHALLENGE && challengeStatus == "") {
- result.push_back(std::make_tuple(PARAMETER_KEY_EMAIL, "Please input your email address"));
+ result.emplace(PARAMETER_KEY_EMAIL, "Please input your email address");
}
else if (status == Status::CHALLENGE && challengeStatus == NEED_CODE) {
- result.push_back(std::make_tuple(PARAMETER_KEY_CODE, "Please input your verification code"));
+ result.emplace(PARAMETER_KEY_CODE, "Please input your verification code");
}
else if (status == Status::CHALLENGE && challengeStatus == WRONG_CODE) {
- result.push_back(std::make_tuple(PARAMETER_KEY_CODE, "Incorrect code, please try again"));
+ result.emplace(PARAMETER_KEY_CODE, "Incorrect code, please try again");
}
else {
NDN_THROW(std::runtime_error("Unexpected status or challenge status."));
@@ -124,24 +124,24 @@
Block
ChallengeEmail::genChallengeRequestTLV(Status status, const std::string& challengeStatus,
- std::vector<std::tuple<std::string, std::string>>&& params)
+ std::multimap<std::string, std::string>&& params)
{
Block request(tlv::EncryptedPayload);
if (status == Status::BEFORE_CHALLENGE) {
- if (params.size() != 1 || std::get<0>(params[0]) != PARAMETER_KEY_EMAIL) {
+ if (params.size() != 1 || params.find(PARAMETER_KEY_EMAIL) == params.end()) {
NDN_THROW(std::runtime_error("Wrong parameter provided."));
}
request.push_back(makeStringBlock(tlv::SelectedChallenge, CHALLENGE_TYPE));
request.push_back(makeStringBlock(tlv::ParameterKey, PARAMETER_KEY_EMAIL));
- request.push_back(makeStringBlock(tlv::ParameterValue, std::get<1>(params[0])));
+ request.push_back(makeStringBlock(tlv::ParameterValue, params.find(PARAMETER_KEY_EMAIL)->second));
}
else if (status == Status::CHALLENGE && (challengeStatus == NEED_CODE || challengeStatus == WRONG_CODE)) {
- if (params.size() != 1 || std::get<0>(params[0]) != PARAMETER_KEY_CODE) {
+ if (params.size() != 1 || params.find(PARAMETER_KEY_CODE) == params.end()) {
NDN_THROW(std::runtime_error("Wrong parameter provided."));
}
request.push_back(makeStringBlock(tlv::SelectedChallenge, CHALLENGE_TYPE));
request.push_back(makeStringBlock(tlv::ParameterKey, PARAMETER_KEY_CODE));
- request.push_back(makeStringBlock(tlv::ParameterValue, std::get<1>(params[0])));
+ request.push_back(makeStringBlock(tlv::ParameterValue, params.find(PARAMETER_KEY_CODE)->second));
}
else {
NDN_THROW(std::runtime_error("Unexpected status or challenge status."));
diff --git a/src/identity-challenge/challenge-email.hpp b/src/identity-challenge/challenge-email.hpp
index 9dbcedd..c005b7e 100644
--- a/src/identity-challenge/challenge-email.hpp
+++ b/src/identity-challenge/challenge-email.hpp
@@ -60,12 +60,12 @@
handleChallengeRequest(const Block& params, ca::RequestState& request) override;
// For Client
- std::vector<std::tuple<std::string, std::string>>
+ std::multimap<std::string, std::string>
getRequestedParameterList(Status status, const std::string& challengeStatus) override;
Block
genChallengeRequestTLV(Status status, const std::string& challengeStatus,
- std::vector<std::tuple<std::string, std::string>>&& params) override;
+ std::multimap<std::string, std::string>&& params) override;
// challenge status
static const std::string NEED_CODE;
diff --git a/src/identity-challenge/challenge-module.hpp b/src/identity-challenge/challenge-module.hpp
index 1e2ca81..02e5027 100644
--- a/src/identity-challenge/challenge-module.hpp
+++ b/src/identity-challenge/challenge-module.hpp
@@ -54,12 +54,12 @@
handleChallengeRequest(const Block& params, ca::RequestState& request) = 0;
// For Client
- virtual std::vector<std::tuple<std::string, std::string>>
+ virtual std::multimap<std::string, std::string>
getRequestedParameterList(Status status, const std::string& challengeStatus) = 0;
virtual Block
genChallengeRequestTLV(Status status, const std::string& challengeStatus,
- std::vector<std::tuple<std::string, std::string>>&& params) = 0;
+ std::multimap<std::string, std::string>&& params) = 0;
// helpers
static std::string
diff --git a/src/identity-challenge/challenge-pin.cpp b/src/identity-challenge/challenge-pin.cpp
index 34b987d..1ae6753 100644
--- a/src/identity-challenge/challenge-pin.cpp
+++ b/src/identity-challenge/challenge-pin.cpp
@@ -84,18 +84,18 @@
}
// For Client
-std::vector<std::tuple<std::string, std::string>>
+std::multimap<std::string, std::string>
ChallengePin::getRequestedParameterList(Status status, const std::string& challengeStatus)
{
- std::vector<std::tuple<std::string, std::string>> result;
+ std::multimap<std::string, std::string> result;
if (status == Status::BEFORE_CHALLENGE) {
// do nothing
}
else if (status == Status::CHALLENGE && challengeStatus == NEED_CODE) {
- result.push_back(std::make_tuple(PARAMETER_KEY_CODE, "Please input your PIN code"));
+ result.emplace(PARAMETER_KEY_CODE, "Please input your PIN code");
}
else if (status == Status::CHALLENGE && challengeStatus == WRONG_CODE) {
- result.push_back(std::make_tuple(PARAMETER_KEY_CODE, "Incorrect PIN code, please try again"));
+ result.emplace(PARAMETER_KEY_CODE, "Incorrect PIN code, please try again");
}
else {
NDN_THROW(std::runtime_error("Unexpected status or challenge status."));
@@ -105,19 +105,19 @@
Block
ChallengePin::genChallengeRequestTLV(Status status, const std::string& challengeStatus,
- std::vector<std::tuple<std::string, std::string>>&& params)
+ std::multimap<std::string, std::string>&& params)
{
Block request(tlv::EncryptedPayload);
if (status == Status::BEFORE_CHALLENGE) {
request.push_back(makeStringBlock(tlv::SelectedChallenge, CHALLENGE_TYPE));
}
else if (status == Status::CHALLENGE && (challengeStatus == NEED_CODE || challengeStatus == WRONG_CODE)) {
- if (params.size() != 1 || std::get<0>(params[0]) != PARAMETER_KEY_CODE) {
+ if (params.size() != 1 || params.find(PARAMETER_KEY_CODE) == params.end()) {
NDN_THROW(std::runtime_error("Wrong parameter provided."));
}
request.push_back(makeStringBlock(tlv::SelectedChallenge, CHALLENGE_TYPE));
request.push_back(makeStringBlock(tlv::ParameterKey, PARAMETER_KEY_CODE));
- request.push_back(makeStringBlock(tlv::ParameterValue, std::get<1>(params[0])));
+ request.push_back(makeStringBlock(tlv::ParameterValue, params.find(PARAMETER_KEY_CODE)->second));
}
else {
NDN_THROW(std::runtime_error("Unexpected status or challenge status."));
diff --git a/src/identity-challenge/challenge-pin.hpp b/src/identity-challenge/challenge-pin.hpp
index 10b23d4..757870d 100644
--- a/src/identity-challenge/challenge-pin.hpp
+++ b/src/identity-challenge/challenge-pin.hpp
@@ -55,12 +55,12 @@
handleChallengeRequest(const Block& params, ca::RequestState& request) override;
// For Client
- std::vector<std::tuple<std::string, std::string>>
+ std::multimap<std::string, std::string>
getRequestedParameterList(Status status, const std::string& challengeStatus) override;
Block
genChallengeRequestTLV(Status status, const std::string& challengeStatus,
- std::vector<std::tuple<std::string, std::string>>&& params) override;
+ std::multimap<std::string, std::string>&& params) override;
// challenge status
static const std::string NEED_CODE;
diff --git a/src/name-assignment/assignment-func.cpp b/src/name-assignment/assignment-func.cpp
index 22eb35e..d65eefd 100644
--- a/src/name-assignment/assignment-func.cpp
+++ b/src/name-assignment/assignment-func.cpp
@@ -24,8 +24,7 @@
namespace ndn {
namespace ndncert {
-NameAssignmentFunc::NameAssignmentFunc(const std::string& factoryType, const std::string& format)
- : FACTORY_TYPE(factoryType)
+NameAssignmentFunc::NameAssignmentFunc(const std::string& format)
{
size_t index = 0, startIndex = 0;
while ((index = format.find("/", startIndex)) != std::string::npos) {
diff --git a/src/name-assignment/assignment-func.hpp b/src/name-assignment/assignment-func.hpp
index e122ed2..9ed8e22 100644
--- a/src/name-assignment/assignment-func.hpp
+++ b/src/name-assignment/assignment-func.hpp
@@ -22,6 +22,7 @@
#define NDNCERT_ASSIGNMENT_FUNC_HPP
#include "detail/ca-request-state.hpp"
+#include <map>
namespace ndn {
namespace ndncert {
@@ -29,7 +30,7 @@
class NameAssignmentFunc : noncopyable
{
protected:
- explicit NameAssignmentFunc(const std::string& factoryType, const std::string& format = "");
+ explicit NameAssignmentFunc(const std::string& format = "");
public:
virtual ~NameAssignmentFunc() = default;
@@ -45,9 +46,7 @@
* @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;
+ assignName(const std::multimap<std::string, std::string> ¶ms) = 0;
public:
template <class AssignmentType>
@@ -62,7 +61,7 @@
static unique_ptr<NameAssignmentFunc>
createNameAssignmentFunc(const std::string& challengeType, const std::string& format = "");
-NDNCERT_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
+NDNCERT_PUBLIC_WITH_TESTS_ELSE_PROTECTED:
std::vector<std::string> m_nameFormat;
private:
diff --git a/src/name-assignment/assignment-hash.cpp b/src/name-assignment/assignment-hash.cpp
index 8f0e641..0dec488 100644
--- a/src/name-assignment/assignment-hash.cpp
+++ b/src/name-assignment/assignment-hash.cpp
@@ -27,20 +27,19 @@
NDNCERT_REGISTER_FUNCFACTORY(AssignmentHash, "hash");
AssignmentHash::AssignmentHash(const std::string& format)
- : NameAssignmentFunc("hash", format)
+ : NameAssignmentFunc(format)
{}
std::vector<PartialName>
-AssignmentHash::assignName(const std::vector<std::tuple<std::string, std::string>>& params)
+AssignmentHash::assignName(const std::multimap<std::string, std::string> ¶ms)
{
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; });
+ auto it = params.find(item);
if (it != params.end()) {
util::Sha256 digest;
- digest << std::get<1>(*it);
+ digest << it->second;
result.append(digest.toString());
}
else {
diff --git a/src/name-assignment/assignment-hash.hpp b/src/name-assignment/assignment-hash.hpp
index 77e5e91..6acb30c 100644
--- a/src/name-assignment/assignment-hash.hpp
+++ b/src/name-assignment/assignment-hash.hpp
@@ -35,7 +35,7 @@
AssignmentHash(const std::string& format = "");
std::vector<PartialName>
- assignName(const std::vector<std::tuple<std::string, std::string>>& params) override;
+ assignName(const std::multimap<std::string, std::string> ¶ms) override;
};
diff --git a/src/name-assignment/assignment-param.cpp b/src/name-assignment/assignment-param.cpp
index 4ebe637..b99d685 100644
--- a/src/name-assignment/assignment-param.cpp
+++ b/src/name-assignment/assignment-param.cpp
@@ -26,19 +26,19 @@
NDNCERT_REGISTER_FUNCFACTORY(AssignmentParam, "param");
AssignmentParam::AssignmentParam(const std::string& format)
- : NameAssignmentFunc("param", format)
+ : NameAssignmentFunc(format)
{}
std::vector<PartialName>
-AssignmentParam::assignName(const std::vector<std::tuple<std::string, std::string>>& params)
+AssignmentParam::assignName(const std::multimap<std::string, std::string> ¶ms)
{
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));
+ if (it != params.end() && !it->second.empty()) {
+ result.append(it->second);
}
else {
return resultList;
diff --git a/src/name-assignment/assignment-param.hpp b/src/name-assignment/assignment-param.hpp
index 8a31dc6..cdf2cc5 100644
--- a/src/name-assignment/assignment-param.hpp
+++ b/src/name-assignment/assignment-param.hpp
@@ -35,7 +35,7 @@
AssignmentParam(const std::string& format = "");
std::vector<PartialName>
- assignName(const std::vector<std::tuple<std::string, std::string>>& params) override;
+ assignName(const std::multimap<std::string, std::string> ¶ms) override;
};
diff --git a/src/name-assignment/assignment-random.cpp b/src/name-assignment/assignment-random.cpp
index 59f6477..eaed861 100644
--- a/src/name-assignment/assignment-random.cpp
+++ b/src/name-assignment/assignment-random.cpp
@@ -27,11 +27,11 @@
NDNCERT_REGISTER_FUNCFACTORY(AssignmentRandom, "random");
AssignmentRandom::AssignmentRandom(const std::string& format)
- : NameAssignmentFunc("random", format)
+ : NameAssignmentFunc(format)
{}
std::vector<PartialName>
-AssignmentRandom::assignName(const std::vector<std::tuple<std::string, std::string>>& params)
+AssignmentRandom::assignName(const std::multimap<std::string, std::string> ¶ms)
{
std::vector<PartialName> resultList;
resultList.emplace_back(to_string(random::generateSecureWord64()));
diff --git a/src/name-assignment/assignment-random.hpp b/src/name-assignment/assignment-random.hpp
index cf6509f..978a0b7 100644
--- a/src/name-assignment/assignment-random.hpp
+++ b/src/name-assignment/assignment-random.hpp
@@ -35,7 +35,7 @@
AssignmentRandom(const std::string& format = "");
std::vector<PartialName>
- assignName(const std::vector<std::tuple<std::string, std::string>>& params) override;
+ assignName(const std::multimap<std::string, std::string> ¶ms) override;
};
} // namespace ndncert
diff --git a/src/requester.cpp b/src/requester.cpp
index 7ace36c..5372db3 100644
--- a/src/requester.cpp
+++ b/src/requester.cpp
@@ -88,7 +88,7 @@
}
shared_ptr<Interest>
-Requester::genProbeInterest(const CaProfile& ca, std::vector<std::tuple<std::string, std::string>>&& probeInfo)
+Requester::genProbeInterest(const CaProfile& ca, std::multimap<std::string, std::string>&& probeInfo)
{
Name interestName = ca.m_caPrefix;
interestName.append("CA").append("PROBE");
@@ -212,7 +212,7 @@
return challenges;
}
-std::vector<std::tuple<std::string, std::string>>
+std::multimap<std::string, std::string>
Requester::selectOrContinueChallenge(RequestState& state, const std::string& challengeSelected)
{
auto challenge = ChallengeModule::createChallengeModule(challengeSelected);
@@ -225,7 +225,7 @@
shared_ptr<Interest>
Requester::genChallengeInterest(RequestState& state,
- std::vector<std::tuple<std::string, std::string>>&& parameters)
+ std::multimap<std::string, std::string>&& parameters)
{
if (state.m_challengeType == "") {
NDN_THROW(std::runtime_error("The challenge has not been selected."));
diff --git a/src/requester.hpp b/src/requester.hpp
index 825efd9..92cf00b 100644
--- a/src/requester.hpp
+++ b/src/requester.hpp
@@ -84,7 +84,7 @@
* @return A shared pointer of to the encoded interest, ready to be sent.
*/
static shared_ptr<Interest>
- genProbeInterest(const CaProfile& ca, std::vector<std::tuple<std::string, std::string>>&& probeInfo);
+ genProbeInterest(const CaProfile& ca, std::multimap<std::string, std::string>&& probeInfo);
/**
* @brief Decodes the replied data for PROBE process from the CA.
@@ -147,7 +147,7 @@
* @return The requirement list for the current stage of the challenge, in name, prompt mapping.
* @throw std::runtime_error if the challenge is not supported.
*/
- static std::vector<std::tuple<std::string, std::string>>
+ static std::multimap<std::string, std::string>
selectOrContinueChallenge(RequestState& state, const std::string& challengeSelected);
/**
@@ -160,7 +160,7 @@
*/
static shared_ptr<Interest>
genChallengeInterest(RequestState& state,
- std::vector<std::tuple<std::string, std::string>>&& parameters);
+ std::multimap<std::string, std::string>&& parameters);
/**
* @brief Decodes the responded data from the CHALLENGE interest.