Migrate to C++17 and refactor
Change-Id: I53407266939258990a1c3a9363c3ebe9ea113fd2
diff --git a/.waf-tools/default-compiler-flags.py b/.waf-tools/default-compiler-flags.py
index f086c17..7c6d282 100644
--- a/.waf-tools/default-compiler-flags.py
+++ b/.waf-tools/default-compiler-flags.py
@@ -136,7 +136,7 @@
"""
def getGeneralFlags(self, conf):
flags = super(GccBasicFlags, self).getGeneralFlags(conf)
- flags['CXXFLAGS'] += ['-std=c++14']
+ flags['CXXFLAGS'] += ['-std=c++17']
if Utils.unversioned_sys_platform() == 'linux':
flags['LINKFLAGS'] += ['-fuse-ld=gold']
elif Utils.unversioned_sys_platform() == 'freebsd':
diff --git a/README.md b/README.md
index 36b6cc7..ed4649e 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# NDNCERT: NDN Certificate Management Protocol
[![CI](https://github.com/named-data/ndncert/actions/workflows/ci.yml/badge.svg)](https://github.com/named-data/ndncert/actions/workflows/ci.yml)
-![Language](https://img.shields.io/badge/C%2B%2B-14-blue)
+![Language](https://img.shields.io/badge/C%2B%2B-17-blue)
The NDN certificate management protocol (**NDNCERT**) enables automatic certificate management
in NDN. In Named Data Networking (NDN), every entity should have a corresponding identity
diff --git a/src/ca-module.cpp b/src/ca-module.cpp
index 8b9ba5c..ef41efc 100644
--- a/src/ca-module.cpp
+++ b/src/ca-module.cpp
@@ -35,8 +35,7 @@
#include <ndn-cxx/util/random.hpp>
#include <ndn-cxx/util/string-helper.hpp>
-namespace ndncert {
-namespace ca {
+namespace ndncert::ca {
const time::seconds DEFAULT_DATA_FRESHNESS_PERIOD = 1_s;
const time::seconds REQUEST_VALIDITY_PERIOD_NOT_BEFORE_GRACE_PERIOD = 120_s;
@@ -282,11 +281,11 @@
if (requestType == RequestType::NEW) {
// check the validity period
- auto expectedPeriod = clientCert->getValidityPeriod().getPeriod();
+ auto [notBefore, notAfter] = clientCert->getValidityPeriod().getPeriod();
auto currentTime = time::system_clock::now();
- if (expectedPeriod.first < currentTime - REQUEST_VALIDITY_PERIOD_NOT_BEFORE_GRACE_PERIOD ||
- expectedPeriod.second > currentTime + m_config.caProfile.maxValidityPeriod ||
- expectedPeriod.second <= expectedPeriod.first) {
+ if (notBefore < currentTime - REQUEST_VALIDITY_PERIOD_NOT_BEFORE_GRACE_PERIOD ||
+ notAfter > currentTime + m_config.caProfile.maxValidityPeriod ||
+ notAfter <= notBefore) {
NDN_LOG_ERROR("An invalid validity period is being requested.");
m_face.put(generateErrorDataPacket(request.getName(), ErrorCode::BAD_VALIDITY_PERIOD,
"An invalid validity period is being requested."));
@@ -472,8 +471,7 @@
Certificate
CaModule::issueCertificate(const RequestState& requestState)
{
- auto expectedPeriod = requestState.cert.getValidityPeriod().getPeriod();
- ndn::security::ValidityPeriod period(expectedPeriod.first, expectedPeriod.second);
+ auto period = requestState.cert.getValidityPeriod();
Certificate newCert;
Name certName = requestState.cert.getKeyName();
@@ -530,5 +528,4 @@
return result;
}
-} // namespace ca
-} // namespace ndncert
+} // namespace ndncert::ca
diff --git a/src/ca-module.hpp b/src/ca-module.hpp
index 88af9f1..719c3f3 100644
--- a/src/ca-module.hpp
+++ b/src/ca-module.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -28,8 +28,7 @@
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/security/key-chain.hpp>
-namespace ndncert {
-namespace ca {
+namespace ndncert::ca {
/**
* @brief The function would be invoked whenever the certificate request status is updated.
@@ -56,7 +55,7 @@
}
const std::unique_ptr<CaStorage>&
- getCaStorage()
+ getCaStorage() const
{
return m_storage;
}
@@ -111,7 +110,6 @@
std::list<ndn::InterestFilterHandle> m_interestFilterHandles;
};
-} // namespace ca
-} // namespace ndncert
+} // namespace ndncert::ca
#endif // NDNCERT_CA_MODULE_HPP
diff --git a/src/challenge/challenge-module.cpp b/src/challenge/challenge-module.cpp
index bf3b966..73594c0 100644
--- a/src/challenge/challenge-module.cpp
+++ b/src/challenge/challenge-module.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -19,6 +19,7 @@
*/
#include "challenge/challenge-module.hpp"
+
#include <ndn-cxx/util/random.hpp>
namespace ndncert {
@@ -35,15 +36,15 @@
bool
ChallengeModule::isChallengeSupported(const std::string& challengeType)
{
- ChallengeFactory& factory = getFactory();
+ auto& factory = getFactory();
auto i = factory.find(challengeType);
- return i == factory.end() ? false : true;
+ return i != factory.end();
}
std::unique_ptr<ChallengeModule>
ChallengeModule::createChallengeModule(const std::string& challengeType)
{
- ChallengeFactory& factory = getFactory();
+ auto& factory = getFactory();
auto i = factory.find(challengeType);
return i == factory.end() ? nullptr : i->second();
}
@@ -51,7 +52,7 @@
ChallengeModule::ChallengeFactory&
ChallengeModule::getFactory()
{
- static ChallengeModule::ChallengeFactory factory;
+ static ChallengeFactory factory;
return factory;
}
@@ -61,10 +62,9 @@
uint32_t securityCode = 0;
do {
securityCode = ndn::random::generateSecureWord32();
- }
- while (securityCode >= 4294000000);
+ } while (securityCode >= 4294000000);
securityCode /= 4294;
- std::string result = ndn::to_string(securityCode);
+ std::string result = std::to_string(securityCode);
while (result.length() < 6) {
result = "0" + result;
}
@@ -76,8 +76,8 @@
{
request.status = Status::FAILURE;
request.challengeType = "";
- request.challengeState = nullopt;
- return std::make_tuple(errorCode, std::move(errorInfo));
+ request.challengeState = std::nullopt;
+ return {errorCode, std::move(errorInfo)};
}
std::tuple<ErrorCode, std::string>
@@ -89,7 +89,7 @@
request.challengeType = CHALLENGE_TYPE;
request.challengeState = ca::ChallengeState(challengeStatus, time::system_clock::now(), remainingTries,
remainingTime, std::move(challengeSecret));
- return std::make_tuple(ErrorCode::NO_ERROR, "");
+ return {ErrorCode::NO_ERROR, ""};
}
std::tuple<ErrorCode, std::string>
@@ -97,8 +97,8 @@
{
request.status = Status::PENDING;
request.challengeType = CHALLENGE_TYPE;
- request.challengeState = nullopt;
- return std::make_tuple(ErrorCode::NO_ERROR, "");
+ request.challengeState = std::nullopt;
+ return {ErrorCode::NO_ERROR, ""};
}
} // namespace ndncert
diff --git a/src/challenge/challenge-module.hpp b/src/challenge/challenge-module.hpp
index 1e33bfc..a0c7b60 100644
--- a/src/challenge/challenge-module.hpp
+++ b/src/challenge/challenge-module.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,32 +23,18 @@
#include "detail/ca-request-state.hpp"
+#include <map>
+
namespace ndncert {
class ChallengeModule : boost::noncopyable
{
public:
- explicit
ChallengeModule(const std::string& challengeType, size_t maxAttemptTimes, time::seconds secretLifetime);
virtual
~ChallengeModule() = default;
- template <class ChallengeType>
- static void
- registerChallengeModule(const std::string& typeName)
- {
- ChallengeFactory& factory = getFactory();
- BOOST_ASSERT(factory.count(typeName) == 0);
- factory[typeName] = [] { return std::make_unique<ChallengeType>(); };
- }
-
- static bool
- isChallengeSupported(const std::string& challengeType);
-
- static std::unique_ptr<ChallengeModule>
- createChallengeModule(const std::string& challengeType);
-
// For CA
virtual std::tuple<ErrorCode, std::string>
handleChallengeRequest(const Block& params, ca::RequestState& request) = 0;
@@ -61,13 +47,27 @@
genChallengeRequestTLV(Status status, const std::string& challengeStatus,
const std::multimap<std::string, std::string>& params) = 0;
- // helpers
+public: // factory
+ template<class ChallengeType>
+ static void
+ registerChallengeModule(const std::string& type)
+ {
+ auto& factory = getFactory();
+ BOOST_ASSERT(factory.count(type) == 0);
+ factory[type] = [] { return std::make_unique<ChallengeType>(); };
+ }
+
+ static bool
+ isChallengeSupported(const std::string& challengeType);
+
+ static std::unique_ptr<ChallengeModule>
+ createChallengeModule(const std::string& challengeType);
+
+protected: // helpers used by concrete challenge modules
static std::string
generateSecretCode();
-protected:
- // used by challenge modules
- std::tuple<ErrorCode, std::string>
+ static std::tuple<ErrorCode, std::string>
returnWithError(ca::RequestState& request, ErrorCode errorCode, std::string errorInfo);
std::tuple<ErrorCode, std::string>
@@ -79,27 +79,29 @@
public:
const std::string CHALLENGE_TYPE;
+
+protected:
const size_t m_maxAttemptTimes;
const time::seconds m_secretLifetime;
private:
- typedef std::function<std::unique_ptr<ChallengeModule>()> ChallengeCreateFunc;
- typedef std::map<std::string, ChallengeCreateFunc> ChallengeFactory;
+ using CreateFunc = std::function<std::unique_ptr<ChallengeModule>()>;
+ using ChallengeFactory = std::map<std::string, CreateFunc>;
static ChallengeFactory&
getFactory();
};
-#define NDNCERT_REGISTER_CHALLENGE(C, T) \
- static class NdnCert##C##ChallengeRegistrationClass \
- { \
- public: \
- NdnCert##C##ChallengeRegistrationClass() \
- { \
- ::ndncert::ChallengeModule::registerChallengeModule<C>(T); \
- } \
- } g_NdnCert##C##ChallengeRegistrationVariable
-
} // namespace ndncert
+#define NDNCERT_REGISTER_CHALLENGE(C, T) \
+static class NdnCert##C##ChallengeRegistrationClass \
+{ \
+public: \
+ NdnCert##C##ChallengeRegistrationClass() \
+ { \
+ ::ndncert::ChallengeModule::registerChallengeModule<C>(T); \
+ } \
+} g_NdnCert##C##ChallengeRegistrationVariable
+
#endif // NDNCERT_CHALLENGE_MODULE_HPP
diff --git a/src/challenge/challenge-possession.cpp b/src/challenge/challenge-possession.cpp
index d4c8185..2299a51 100644
--- a/src/challenge/challenge-possession.cpp
+++ b/src/challenge/challenge-possession.cpp
@@ -57,7 +57,7 @@
}
catch (const boost::property_tree::file_parser_error& error) {
NDN_THROW(std::runtime_error("Failed to parse configuration file " + m_configFile + ": " +
- error.message() + " on line " + ndn::to_string(error.line())));
+ error.message() + " on line " + std::to_string(error.line())));
}
if (config.begin() == config.end()) {
@@ -243,12 +243,12 @@
const auto& issuedCertTlv = issuedCert.wireEncode();
auto signature = keyChain.getTpm().sign({nonce}, keyName, ndn::DigestAlgorithm::SHA256);
- for (auto& item : params) {
- if (item.first == PARAMETER_KEY_CREDENTIAL_CERT) {
- item.second = std::string(reinterpret_cast<const char*>(issuedCertTlv.wire()), issuedCertTlv.size());
+ for (auto& [key, val] : params) {
+ if (key == PARAMETER_KEY_CREDENTIAL_CERT) {
+ val = std::string(reinterpret_cast<const char*>(issuedCertTlv.wire()), issuedCertTlv.size());
}
- else if (item.first == PARAMETER_KEY_PROOF) {
- item.second = std::string(signature->get<char>(), signature->size());
+ else if (key == PARAMETER_KEY_PROOF) {
+ val = std::string(signature->get<char>(), signature->size());
}
}
}
diff --git a/src/detail/ca-configuration.cpp b/src/detail/ca-configuration.cpp
index 55b8a7c..667d98b 100644
--- a/src/detail/ca-configuration.cpp
+++ b/src/detail/ca-configuration.cpp
@@ -25,8 +25,7 @@
#include <boost/filesystem.hpp>
#include <boost/property_tree/json_parser.hpp>
-namespace ndncert {
-namespace ca {
+namespace ndncert::ca {
void
CaConfig::load(const std::string& fileName)
@@ -38,33 +37,35 @@
catch (const std::exception& error) {
NDN_THROW(std::runtime_error("Failed to parse configuration file " + fileName + ", " + error.what()));
}
+
if (configJson.begin() == configJson.end()) {
NDN_THROW(std::runtime_error("No JSON configuration found in file: " + fileName));
}
caProfile = CaProfile::fromJson(configJson);
- if (caProfile.supportedChallenges.size() == 0) {
+ if (caProfile.supportedChallenges.empty()) {
NDN_THROW(std::runtime_error("At least one challenge should be specified."));
}
- // parse redirection section if appears
+
+ // parse redirection section if present
redirection.clear();
auto redirectionItems = configJson.get_child_optional(CONFIG_REDIRECTION);
if (redirectionItems) {
for (const auto& item : *redirectionItems) {
auto caPrefixStr = item.second.get(CONFIG_CA_PREFIX, "");
auto caCertStr = item.second.get(CONFIG_CERTIFICATE, "");
- if (caCertStr == "") {
+ if (caCertStr.empty()) {
NDN_THROW(std::runtime_error("Redirect-to item's certificate cannot be empty."));
}
std::istringstream ss(caCertStr);
auto caCert = ndn::io::load<Certificate>(ss);
- if (caPrefixStr != "" && Name(caPrefixStr) != caCert->getIdentity()) {
+ if (!caPrefixStr.empty() && Name(caPrefixStr) != caCert->getIdentity()) {
NDN_THROW(std::runtime_error("Redirect-to item's prefix and certificate does not match."));
}
auto policyType = item.second.get(CONFIG_REDIRECTION_POLICY_TYPE, "");
auto policyParam = item.second.get(CONFIG_REDIRECTION_POLICY_PARAM, "");
if (policyType.empty()) {
- NDN_THROW(std::runtime_error("Redirect-to policy type expected but not provided."));
+ NDN_THROW(std::runtime_error("Redirect-to policy type expected but not provided."));
}
auto policy = RedirectionPolicy::createPolicyFunc(policyType, policyParam);
if (policy == nullptr) {
@@ -73,12 +74,13 @@
redirection.emplace_back(caCert, std::move(policy));
}
}
- // parse name assignment if appears
+
+ // parse name assignment if present
nameAssignmentFuncs.clear();
auto nameAssignmentItems = configJson.get_child_optional(CONFIG_NAME_ASSIGNMENT);
if (nameAssignmentItems) {
- for (const auto& item : *nameAssignmentItems) {
- auto func = NameAssignmentFunc::createNameAssignmentFunc(item.first, item.second.data());
+ for (const auto& [key, val] : *nameAssignmentItems) {
+ auto func = NameAssignmentFunc::createNameAssignmentFunc(key, val.data());
if (func == nullptr) {
NDN_THROW(std::runtime_error("Error on creating name assignment function"));
}
@@ -87,5 +89,4 @@
}
}
-} // namespace ca
-} // namespace ndncert
+} // namespace ndncert::ca
diff --git a/src/detail/ca-configuration.hpp b/src/detail/ca-configuration.hpp
index 0a02777..5f39887 100644
--- a/src/detail/ca-configuration.hpp
+++ b/src/detail/ca-configuration.hpp
@@ -21,12 +21,11 @@
#ifndef NDNCERT_DETAIL_CA_CONFIGURATION_HPP
#define NDNCERT_DETAIL_CA_CONFIGURATION_HPP
+#include "ca-profile.hpp"
#include "name-assignment/assignment-func.hpp"
#include "redirection/redirection-policy.hpp"
-#include "ca-profile.hpp"
-namespace ndncert {
-namespace ca {
+namespace ndncert::ca {
/**
* @brief CA's configuration on NDNCERT.
@@ -74,7 +73,6 @@
std::vector<std::unique_ptr<NameAssignmentFunc>> nameAssignmentFuncs;
};
-} // namespace ca
-} // namespace ndncert
+} // namespace ndncert::ca
#endif // NDNCERT_DETAIL_CA_CONFIGURATION_HPP
diff --git a/src/detail/ca-memory.cpp b/src/detail/ca-memory.cpp
index b3c5efd..cab365b 100644
--- a/src/detail/ca-memory.cpp
+++ b/src/detail/ca-memory.cpp
@@ -20,13 +20,12 @@
#include "detail/ca-memory.hpp"
-namespace ndncert {
-namespace ca {
+namespace ndncert::ca {
const std::string CaMemory::STORAGE_TYPE = "ca-storage-memory";
NDNCERT_REGISTER_CA_STORAGE(CaMemory);
-CaMemory::CaMemory(const Name& caName, const std::string& path)
+CaMemory::CaMemory(const Name&, const std::string&)
: CaStorage()
{
}
@@ -34,21 +33,18 @@
RequestState
CaMemory::getRequest(const RequestId& requestId)
{
- auto search = m_requests.find(requestId);
- if (search == m_requests.end()) {
- NDN_THROW(std::runtime_error("Request " + ndn::toHex(requestId) + " does not exists"));
+ auto it = m_requests.find(requestId);
+ if (it == m_requests.end()) {
+ NDN_THROW(std::runtime_error("Request " + ndn::toHex(requestId) + " does not exist"));
}
- return search->second;
+ return it->second;
}
void
CaMemory::addRequest(const RequestState& request)
{
- auto search = m_requests.find(request.requestId);
- if (search == m_requests.end()) {
- m_requests.insert(std::make_pair(request.requestId, request));
- }
- else {
+ auto result = m_requests.insert({request.requestId, request});
+ if (!result.second) {
NDN_THROW(std::runtime_error("Request " + ndn::toHex(request.requestId) + " already exists"));
}
}
@@ -56,23 +52,13 @@
void
CaMemory::updateRequest(const RequestState& request)
{
- auto search = m_requests.find(request.requestId);
- if (search == m_requests.end()) {
- m_requests.insert(std::make_pair(request.requestId, request));
- }
- else {
- search->second = request;
- }
+ m_requests.insert_or_assign(request.requestId, request);
}
void
CaMemory::deleteRequest(const RequestId& requestId)
{
- auto search = m_requests.find(requestId);
- auto keyName = search->second.cert.getKeyName();
- if (search != m_requests.end()) {
- m_requests.erase(search);
- }
+ m_requests.erase(requestId);
}
std::list<RequestState>
@@ -97,5 +83,4 @@
return result;
}
-} // namespace ca
-} // namespace ndncert
+} // namespace ndncert::ca
diff --git a/src/detail/ca-memory.hpp b/src/detail/ca-memory.hpp
index 6d8b115..2c78997 100644
--- a/src/detail/ca-memory.hpp
+++ b/src/detail/ca-memory.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,25 +23,20 @@
#include "detail/ca-storage.hpp"
-namespace ndncert {
-namespace ca {
+namespace ndncert::ca {
class CaMemory : public CaStorage
{
public:
- CaMemory(const Name& caName = Name(), const std::string& path = "");
- const static std::string STORAGE_TYPE;
+ static const std::string STORAGE_TYPE;
+
+ explicit
+ CaMemory(const Name& caName = "", const std::string& path = "");
public:
- /**
- * @throw if request cannot be fetched from underlying data storage
- */
RequestState
getRequest(const RequestId& requestId) override;
- /**
- * @throw if there is an existing request with the same request ID
- */
void
addRequest(const RequestState& request) override;
@@ -61,7 +56,6 @@
std::map<RequestId, RequestState> m_requests;
};
-} // namespace ca
-} // namespace ndncert
+} // namespace ndncert::ca
#endif // NDNCERT_DETAIL_CA_MEMORY_HPP
diff --git a/src/detail/ca-profile.cpp b/src/detail/ca-profile.cpp
index 624ec7a..41c5d56 100644
--- a/src/detail/ca-profile.cpp
+++ b/src/detail/ca-profile.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -41,7 +41,7 @@
// CA max validity period
profile.maxValidityPeriod = time::seconds(json.get(CONFIG_MAX_VALIDITY_PERIOD, 86400));
// CA max suffix length
- profile.maxSuffixLength = nullopt;
+ profile.maxSuffixLength = std::nullopt;
auto maxSuffixLength = json.get_optional<size_t>(CONFIG_MAX_SUFFIX_LENGTH);
if (maxSuffixLength) {
profile.maxSuffixLength = *maxSuffixLength;
@@ -78,7 +78,7 @@
// anchor certificate
profile.cert = nullptr;
auto certificateStr = json.get(CONFIG_CERTIFICATE, "");
- if (certificateStr != "") {
+ if (!certificateStr.empty()) {
std::istringstream ss(certificateStr);
profile.cert = ndn::io::load<Certificate>(ss);
}
@@ -100,7 +100,7 @@
for (const auto& key : probeParameterKeys) {
JsonSection keyJson;
keyJson.put(CONFIG_PROBE_PARAMETER, key);
- probeParametersJson.push_back(std::make_pair("", keyJson));
+ probeParametersJson.push_back({"", keyJson});
}
caItem.add_child("", probeParametersJson);
}
@@ -109,7 +109,7 @@
for (const auto& challenge : supportedChallenges) {
JsonSection challengeJson;
challengeJson.put(CONFIG_CHALLENGE, challenge);
- challengeListJson.push_back(std::make_pair("", challengeJson));
+ challengeListJson.push_back({"", challengeJson});
}
caItem.add_child("", challengeListJson);
}
diff --git a/src/detail/ca-profile.hpp b/src/detail/ca-profile.hpp
index 74af5c0..620f49b 100644
--- a/src/detail/ca-profile.hpp
+++ b/src/detail/ca-profile.hpp
@@ -83,7 +83,7 @@
* E.g., When its value is 2, at most 2 name components can be assigned after m_caPrefix.
* Default: none.
*/
- optional<size_t> maxSuffixLength = nullopt;
+ std::optional<size_t> maxSuffixLength;
/**
* @brief A list of supported challenges. Only CA side will have m_supportedChallenges.
*/
diff --git a/src/detail/ca-request-state.hpp b/src/detail/ca-request-state.hpp
index 2c4a1d6..5fbb8f7 100644
--- a/src/detail/ca-request-state.hpp
+++ b/src/detail/ca-request-state.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -27,7 +27,7 @@
namespace ndncert {
-typedef std::array<uint8_t, 8> RequestId;
+using RequestId = std::array<uint8_t, 8>;
enum class Status : uint16_t {
BEFORE_CHALLENGE = 0,
@@ -127,7 +127,7 @@
/**
* @brief The challenge state.
*/
- optional<ChallengeState> challengeState;
+ std::optional<ChallengeState> challengeState;
};
std::ostream&
diff --git a/src/detail/ca-sqlite.cpp b/src/detail/ca-sqlite.cpp
index 0632edc..3794ce0 100644
--- a/src/detail/ca-sqlite.cpp
+++ b/src/detail/ca-sqlite.cpp
@@ -28,8 +28,7 @@
#include <boost/filesystem.hpp>
#include <boost/property_tree/json_parser.hpp>
-namespace ndncert {
-namespace ca {
+namespace ndncert::ca {
using ndn::util::Sqlite3Statement;
@@ -148,7 +147,7 @@
std::memcpy(state.encryptionKey.data(), statement.getBlob(11), statement.getSize(11));
state.encryptionIv = std::vector<uint8_t>(statement.getBlob(12), statement.getBlob(12) + statement.getSize(12));
state.decryptionIv = std::vector<uint8_t>(statement.getBlob(13), statement.getBlob(13) + statement.getSize(13));
- if (state.challengeType != "") {
+ if (!state.challengeType.empty()) {
ChallengeState challengeState(statement.getString(3), time::fromIsoString(statement.getString(7)),
statement.getInt(8), time::seconds(statement.getInt(9)),
convertString2Json(statement.getString(6)));
@@ -279,7 +278,7 @@
std::memcpy(state.encryptionKey.data(), statement.getBlob(12), statement.getSize(12));
state.encryptionIv = std::vector<uint8_t>(statement.getBlob(13), statement.getBlob(13) + statement.getSize(13));
state.decryptionIv = std::vector<uint8_t>(statement.getBlob(14), statement.getBlob(14) + statement.getSize(14));
- if (state.challengeType != "") {
+ if (!state.challengeType.empty()) {
ChallengeState challengeState(statement.getString(4), time::fromIsoString(statement.getString(8)),
statement.getInt(9), time::seconds(statement.getInt(10)),
convertString2Json(statement.getString(7)));
@@ -299,5 +298,4 @@
statement.step();
}
-} // namespace ca
-} // namespace ndncert
+} // namespace ndncert::ca
diff --git a/src/detail/ca-sqlite.hpp b/src/detail/ca-sqlite.hpp
index 969cacf..5ad10d9 100644
--- a/src/detail/ca-sqlite.hpp
+++ b/src/detail/ca-sqlite.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -25,13 +25,12 @@
struct sqlite3;
-namespace ndncert {
-namespace ca {
+namespace ndncert::ca {
class CaSqlite : public CaStorage
{
public:
- const static std::string STORAGE_TYPE;
+ static const std::string STORAGE_TYPE;
explicit
CaSqlite(const Name& caName, const std::string& path = "");
@@ -39,15 +38,9 @@
~CaSqlite() override;
public:
- /**
- * @throw if request cannot be fetched from underlying data storage
- */
RequestState
getRequest(const RequestId& requestId) override;
- /**
- * @throw if there is an existing request with the same request ID
- */
void
addRequest(const RequestState& request) override;
@@ -67,7 +60,6 @@
sqlite3* m_database;
};
-} // namespace ca
-} // namespace ndncert
+} // namespace ndncert::ca
#endif // NDNCERT_DETAIL_CA_SQLITE_HPP
diff --git a/src/detail/ca-storage.cpp b/src/detail/ca-storage.cpp
index 24fe38f..c3c08a7 100644
--- a/src/detail/ca-storage.cpp
+++ b/src/detail/ca-storage.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -20,13 +20,12 @@
#include "detail/ca-storage.hpp"
-namespace ndncert {
-namespace ca {
+namespace ndncert::ca {
std::unique_ptr<CaStorage>
CaStorage::createCaStorage(const std::string& caStorageType, const Name& caName, const std::string& path)
{
- CaStorageFactory& factory = getFactory();
+ auto& factory = getFactory();
auto i = factory.find(caStorageType);
return i == factory.end() ? nullptr : i->second(caName, path);
}
@@ -34,9 +33,8 @@
CaStorage::CaStorageFactory&
CaStorage::getFactory()
{
- static CaStorage::CaStorageFactory factory;
+ static CaStorageFactory factory;
return factory;
}
-} // namespace ca
-} // namespace ndncert
+} // namespace ndncert::ca
diff --git a/src/detail/ca-storage.hpp b/src/detail/ca-storage.hpp
index 0fa7238..6b8f03c 100644
--- a/src/detail/ca-storage.hpp
+++ b/src/detail/ca-storage.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,20 +23,24 @@
#include "detail/ca-request-state.hpp"
-namespace ndncert {
-namespace ca {
+#include <map>
+
+namespace ndncert::ca {
class CaStorage : boost::noncopyable
{
-public: // request related
+public:
+ virtual
+ ~CaStorage() = default;
+
/**
- * @throw if request cannot be fetched from underlying data storage
+ * @throw std::runtime_error The request cannot be fetched from underlying data storage
*/
virtual RequestState
getRequest(const RequestId& requestId) = 0;
/**
- * @throw if there is an existing request with the same request ID
+ * @throw std::runtime_error There is an existing request with the same request ID
*/
virtual void
addRequest(const RequestState& request) = 0;
@@ -56,11 +60,11 @@
public: // factory
template<class CaStorageType>
static void
- registerCaStorage(const std::string& caStorageType = CaStorageType::STORAGE_TYPE)
+ registerCaStorage(const std::string& type = CaStorageType::STORAGE_TYPE)
{
- CaStorageFactory& factory = getFactory();
- BOOST_ASSERT(factory.count(caStorageType) == 0);
- factory[caStorageType] = [] (const Name& caName, const std::string& path) {
+ auto& factory = getFactory();
+ BOOST_ASSERT(factory.count(type) == 0);
+ factory[type] = [] (const Name& caName, const std::string& path) {
return std::make_unique<CaStorageType>(caName, path);
};
}
@@ -68,28 +72,24 @@
static std::unique_ptr<CaStorage>
createCaStorage(const std::string& caStorageType, const Name& caName, const std::string& path);
- virtual
- ~CaStorage() = default;
-
private:
- using CaStorageCreateFunc = std::function<std::unique_ptr<CaStorage> (const Name&, const std::string&)>;
- using CaStorageFactory = std::map<std::string, CaStorageCreateFunc>;
+ using CreateFunc = std::function<std::unique_ptr<CaStorage>(const Name&, const std::string&)>;
+ using CaStorageFactory = std::map<std::string, CreateFunc>;
static CaStorageFactory&
getFactory();
};
-#define NDNCERT_REGISTER_CA_STORAGE(C) \
-static class NdnCert ## C ## CaStorageRegistrationClass \
-{ \
-public: \
- NdnCert ## C ## CaStorageRegistrationClass() \
- { \
- ::ndncert::ca::CaStorage::registerCaStorage<C>(); \
- } \
-} g_NdnCert ## C ## CaStorageRegistrationVariable
+} // namespace ndncert::ca
-} // namespace ca
-} // namespace ndncert
+#define NDNCERT_REGISTER_CA_STORAGE(C) \
+static class NdnCert##C##CaStorageRegistrationClass \
+{ \
+public: \
+ NdnCert##C##CaStorageRegistrationClass() \
+ { \
+ ::ndncert::ca::CaStorage::registerCaStorage<C>(); \
+ } \
+} g_NdnCert##C##CaStorageRegistrationVariable
#endif // NDNCERT_DETAIL_CA_STORAGE_HPP
diff --git a/src/detail/challenge-encoder.cpp b/src/detail/challenge-encoder.cpp
index 1a7a83d..9f36042 100644
--- a/src/detail/challenge-encoder.cpp
+++ b/src/detail/challenge-encoder.cpp
@@ -20,10 +20,10 @@
#include "detail/challenge-encoder.hpp"
-namespace ndncert {
+namespace ndncert::challengetlv {
Block
-challengetlv::encodeDataContent(ca::RequestState& request, const Name& issuedCertName)
+encodeDataContent(ca::RequestState& request, const Name& issuedCertName)
{
Block response(tlv::EncryptedPayload);
response.push_back(ndn::makeNonNegativeIntegerBlock(tlv::Status, static_cast<uint64_t>(request.status)));
@@ -52,7 +52,7 @@
}
void
-challengetlv::decodeDataContent(const Block& contentBlock, requester::Request& state)
+decodeDataContent(const Block& contentBlock, requester::Request& state)
{
auto result = decodeBlockWithAesGcm128(contentBlock, state.m_aesKey.data(),
state.m_requestId.data(), state.m_requestId.size(),
@@ -122,4 +122,4 @@
}
}
-} // namespace ndncert
+} // namespace ndncert::challengetlv
diff --git a/src/detail/challenge-encoder.hpp b/src/detail/challenge-encoder.hpp
index 2013061..5c502d2 100644
--- a/src/detail/challenge-encoder.hpp
+++ b/src/detail/challenge-encoder.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -24,8 +24,7 @@
#include "detail/ca-request-state.hpp"
#include "requester-request.hpp"
-namespace ndncert {
-namespace challengetlv {
+namespace ndncert::challengetlv {
Block
encodeDataContent(ca::RequestState& request, const Name& issuedCertName = Name());
@@ -33,7 +32,6 @@
void
decodeDataContent(const Block& contentBlock, requester::Request& state);
-} // namespace challengetlv
-} // namespace ndncert
+} // namespace ndncert::challengetlv
#endif // NDNCERT_DETAIL_CHALLENGE_ENCODER_HPP
diff --git a/src/detail/error-encoder.cpp b/src/detail/error-encoder.cpp
index 990ce84..3dcb6ca 100644
--- a/src/detail/error-encoder.cpp
+++ b/src/detail/error-encoder.cpp
@@ -22,10 +22,10 @@
NDN_LOG_INIT(ndncert.encode.error);
-namespace ndncert {
+namespace ndncert::errortlv {
Block
-errortlv::encodeDataContent(ErrorCode errorCode, const std::string& description)
+encodeDataContent(ErrorCode errorCode, const std::string& description)
{
Block response(ndn::tlv::Content);
response.push_back(ndn::makeNonNegativeIntegerBlock(tlv::ErrorCode, static_cast<size_t>(errorCode)));
@@ -35,7 +35,7 @@
}
std::tuple<ErrorCode, std::string>
-errortlv::decodefromDataContent(const Block& block)
+decodefromDataContent(const Block& block)
{
try {
block.parse();
@@ -47,34 +47,35 @@
for (const auto& item : block.elements()) {
if (item.type() == tlv::ErrorCode) {
error = static_cast<ErrorCode>(readNonNegativeInteger(block.get(tlv::ErrorCode)));
- codeCount ++;
+ codeCount++;
}
else if (item.type() == tlv::ErrorInfo) {
errorInfo = readString(block.get(tlv::ErrorInfo));
- infoCount ++;
+ infoCount++;
}
else if (ndn::tlv::isCriticalType(item.type())) {
- otherCriticalCount ++;
+ otherCriticalCount++;
}
else {
//ignore
}
}
if (codeCount == 0 && infoCount == 0) {
- return std::make_tuple(ErrorCode::NO_ERROR, "");
+ return {ErrorCode::NO_ERROR, ""};
}
if (codeCount != 1 || infoCount != 1) {
NDN_THROW(std::runtime_error("Error TLV contains " + std::to_string(codeCount) + " error code(s) and " +
- std::to_string(infoCount) + "error info(s), instead of expected 1 times each."));
+ std::to_string(infoCount) + " error info(s), instead of expected 1 time each."));
}
if (otherCriticalCount > 0) {
NDN_THROW(std::runtime_error("Unknown Critical TLV type in error packet"));
}
- return std::make_tuple(error, errorInfo);
- } catch (const std::exception& e) {
- NDN_LOG_ERROR("[errortlv::DecodeFromDataContent] Exception in error message decoding: " << e.what());
- return std::make_tuple(ErrorCode::NO_ERROR, "");
+ return {error, errorInfo};
+ }
+ catch (const std::exception& e) {
+ NDN_LOG_ERROR("Exception in error message decoding: " << e.what());
+ return {ErrorCode::NO_ERROR, ""};
}
}
-} // namespace ndncert
+} // namespace ndncert::errortlv
diff --git a/src/detail/error-encoder.hpp b/src/detail/error-encoder.hpp
index cd136cf..57fdf92 100644
--- a/src/detail/error-encoder.hpp
+++ b/src/detail/error-encoder.hpp
@@ -23,8 +23,7 @@
#include "detail/ca-profile.hpp"
-namespace ndncert {
-namespace errortlv {
+namespace ndncert::errortlv {
/**
* Encode error information into a Data content TLV
@@ -38,7 +37,6 @@
std::tuple<ErrorCode, std::string>
decodefromDataContent(const Block& block);
-} // namespace errortlv
-} // namespace ndncert
+} // namespace ndncert::errortlv
#endif // NDNCERT_DETAIL_ERROR_ENCODER_HPP
diff --git a/src/detail/info-encoder.cpp b/src/detail/info-encoder.cpp
index 9331f1f..2a9df67 100644
--- a/src/detail/info-encoder.cpp
+++ b/src/detail/info-encoder.cpp
@@ -22,15 +22,15 @@
NDN_LOG_INIT(ndncert.encode.info);
-namespace ndncert {
+namespace ndncert::infotlv {
Block
-infotlv::encodeDataContent(const CaProfile& caConfig, const Certificate& certificate)
+encodeDataContent(const CaProfile& caConfig, const Certificate& certificate)
{
Block content(ndn::tlv::Content);
content.push_back(makeNestedBlock(tlv::CaPrefix, caConfig.caPrefix));
- std::string caInfo = "";
- if (caConfig.caInfo == "") {
+ std::string caInfo;
+ if (caConfig.caInfo.empty()) {
caInfo = "Issued by " + certificate.getSignatureInfo().getKeyLocator().getName().toUri();
}
else {
@@ -48,7 +48,8 @@
}
CaProfile
-infotlv::decodeDataContent(const Block& block) {
+decodeDataContent(const Block& block)
+{
CaProfile result;
block.parse();
for (auto const &item : block.elements()) {
@@ -74,13 +75,10 @@
if (ndn::tlv::isCriticalType(item.type())) {
NDN_THROW(std::runtime_error("Unrecognized TLV Type: " + std::to_string(item.type())));
}
- else {
- //ignore
- }
break;
}
}
return result;
}
-} // namespace ndncert
+} // namespace ndncert::infotlv
diff --git a/src/detail/info-encoder.hpp b/src/detail/info-encoder.hpp
index 4eaa967..e4a9cab 100644
--- a/src/detail/info-encoder.hpp
+++ b/src/detail/info-encoder.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,8 +23,7 @@
#include "detail/ca-profile.hpp"
-namespace ndncert {
-namespace infotlv {
+namespace ndncert::infotlv {
/**
* Encode CA configuration and its certificate into a TLV block as INFO Data packet content.
@@ -38,7 +37,6 @@
CaProfile
decodeDataContent(const Block& block);
-} // namespace infotlv
-} // namespace ndncert
+} // namespace ndncert::infotlv
#endif // NDNCERT_DETAIL_INFO_ENCODER_HPP
diff --git a/src/detail/ndncert-common.hpp b/src/detail/ndncert-common.hpp
index d9863a5..5549550 100644
--- a/src/detail/ndncert-common.hpp
+++ b/src/detail/ndncert-common.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -37,8 +37,11 @@
#include <cstddef>
#include <cstdint>
+#include <memory>
+#include <optional>
#include <string>
#include <tuple>
+#include <vector>
#include <ndn-cxx/data.hpp>
#include <ndn-cxx/encoding/block.hpp>
@@ -48,7 +51,6 @@
#include <ndn-cxx/security/certificate.hpp>
#include <ndn-cxx/util/exception.hpp>
#include <ndn-cxx/util/logger.hpp>
-#include <ndn-cxx/util/optional.hpp>
#include <ndn-cxx/util/time.hpp>
#include <boost/algorithm/string.hpp>
@@ -65,9 +67,6 @@
using ndn::SignatureInfo;
using ndn::security::Certificate;
-using ndn::optional;
-using ndn::nullopt;
-
namespace time = ndn::time;
using namespace ndn::time_literals;
using namespace std::string_literals;
diff --git a/src/detail/probe-encoder.cpp b/src/detail/probe-encoder.cpp
index 13b040e..cdace7e 100644
--- a/src/detail/probe-encoder.cpp
+++ b/src/detail/probe-encoder.cpp
@@ -20,10 +20,10 @@
#include "detail/probe-encoder.hpp"
-namespace ndncert {
+namespace ndncert::probetlv {
Block
-probetlv::encodeApplicationParameters(const std::multimap<std::string, std::string>& parameters)
+encodeApplicationParameters(const std::multimap<std::string, std::string>& parameters)
{
Block content(ndn::tlv::ApplicationParameters);
for (const auto& items : parameters) {
@@ -35,7 +35,8 @@
}
std::multimap<std::string, std::string>
-probetlv::decodeApplicationParameters(const Block& block) {
+decodeApplicationParameters(const Block& block)
+{
std::multimap<std::string, std::string> result;
block.parse();
const auto& elements = block.elements();
@@ -56,8 +57,8 @@
}
Block
-probetlv::encodeDataContent(const std::vector<Name>& identifiers, optional<size_t> maxSuffixLength,
- std::vector<ndn::Name> redirectionItems)
+encodeDataContent(const std::vector<Name>& identifiers, std::optional<size_t> maxSuffixLength,
+ const std::vector<Name>& redirectionItems)
{
Block content(ndn::tlv::Content);
for (const auto& name : identifiers) {
@@ -78,9 +79,9 @@
}
void
-probetlv::decodeDataContent(const Block& block,
- std::vector<std::pair<Name, int>>& availableNames,
- std::vector<Name>& availableRedirection) {
+decodeDataContent(const Block& block, std::vector<std::pair<Name, int>>& availableNames,
+ std::vector<Name>& availableRedirection)
+{
block.parse();
for (const auto& item : block.elements()) {
if (item.type() == tlv::ProbeResponse) {
@@ -121,4 +122,4 @@
}
}
-} // namespace ndncert
+} // namespace ndncert::probetlv
diff --git a/src/detail/probe-encoder.hpp b/src/detail/probe-encoder.hpp
index 223c61b..bd15463 100644
--- a/src/detail/probe-encoder.hpp
+++ b/src/detail/probe-encoder.hpp
@@ -23,27 +23,26 @@
#include "detail/ndncert-common.hpp"
-namespace ndncert {
-namespace probetlv {
+namespace ndncert::probetlv {
// For Client use
Block
encodeApplicationParameters(const std::multimap<std::string, std::string>& parameters);
void
-decodeDataContent(const Block& block, std::vector<std::pair<Name, int>>& availableNames,
+decodeDataContent(const Block& block,
+ std::vector<std::pair<Name, int>>& availableNames,
std::vector<Name>& availableRedirection);
// For CA use
Block
encodeDataContent(const std::vector<Name>& identifiers,
- optional<size_t> maxSuffixLength = nullopt,
- std::vector<ndn::Name> redirectionItems = std::vector<ndn::Name>());
+ std::optional<size_t> maxSuffixLength = std::nullopt,
+ const std::vector<Name>& redirectionItems = {});
std::multimap<std::string, std::string>
decodeApplicationParameters(const Block& block);
-} // namespace probetlv
-} // namespace ndncert
+} // namespace ndncert::probetlv
#endif // NDNCERT_DETAIL_PROBE_ENCODER_HPP
diff --git a/src/detail/profile-storage.cpp b/src/detail/profile-storage.cpp
index 8ae2bb6..ebd33ac 100644
--- a/src/detail/profile-storage.cpp
+++ b/src/detail/profile-storage.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -20,11 +20,9 @@
#include "detail/profile-storage.hpp"
-#include <boost/filesystem.hpp>
#include <boost/property_tree/json_parser.hpp>
-namespace ndncert {
-namespace requester {
+namespace ndncert::requester {
void
ProfileStorage::load(const std::string& fileName)
@@ -47,13 +45,12 @@
{
m_caProfiles.clear();
auto caList = json.get_child("ca-list");
- for (auto item : caList) {
- CaProfile caItem;
- caItem = CaProfile::fromJson(item.second);
- if (caItem.cert == nullptr) {
+ for (const auto& item : caList) {
+ auto profile = CaProfile::fromJson(item.second);
+ if (profile.cert == nullptr) {
NDN_THROW(std::runtime_error("No CA certificate is loaded from JSON configuration."));
}
- m_caProfiles.push_back(std::move(caItem));
+ m_caProfiles.push_back(std::move(profile));
}
}
@@ -62,14 +59,12 @@
{
JsonSection configJson;
for (const auto& caItem : m_caProfiles) {
- configJson.push_back(std::make_pair("", caItem.toJson()));
+ configJson.push_back({"", caItem.toJson()});
}
std::stringstream ss;
boost::property_tree::write_json(ss, configJson);
- std::ofstream configFile;
- configFile.open(fileName);
+ std::ofstream configFile(fileName);
configFile << ss.str();
- configFile.close();
}
void
@@ -96,5 +91,4 @@
return m_caProfiles;
}
-} // namespace requester
-} // namespace ndncert
+} // namespace ndncert::requester
diff --git a/src/detail/profile-storage.hpp b/src/detail/profile-storage.hpp
index 3df6407..41791ed 100644
--- a/src/detail/profile-storage.hpp
+++ b/src/detail/profile-storage.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,8 +23,7 @@
#include "detail/ca-profile.hpp"
-namespace ndncert {
-namespace requester {
+namespace ndncert::requester {
/**
* @brief CA profiles kept by a requester.
@@ -53,8 +52,7 @@
/**
* @brief Add a new CA profile
- *
- * Be cautious. This will add a new trust anchor for requesters.
+ * @warning This will add a new trust anchor for requesters.
*/
void
addCaProfile(const CaProfile& profile);
@@ -66,7 +64,6 @@
std::list<CaProfile> m_caProfiles;
};
-} // namespace requester
-} // namespace ndncert
+} // namespace ndncert::requester
#endif // NDNCERT_DETAIL_PROFILE_STORAGE_HPP
diff --git a/src/detail/request-encoder.hpp b/src/detail/request-encoder.hpp
index e94571e..a5b80f6 100644
--- a/src/detail/request-encoder.hpp
+++ b/src/detail/request-encoder.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,8 +23,7 @@
#include "detail/ca-request-state.hpp"
-namespace ndncert {
-namespace requesttlv {
+namespace ndncert::requesttlv {
Block
encodeApplicationParameters(RequestType requestType, const std::vector<uint8_t>& ecdhPub,
@@ -42,7 +41,6 @@
decodeDataContent(const Block& content, std::vector<uint8_t>& ecdhKey,
std::array<uint8_t, 32>& salt, RequestId& requestId);
-} // namespace requesttlv
-} // namespace ndncert
+} // namespace ndncert::requesttlv
#endif // NDNCERT_DETAIL_REQUEST_ENCODER_HPP
diff --git a/src/name-assignment/assignment-email.cpp b/src/name-assignment/assignment-email.cpp
index 685a820..2cb6184 100644
--- a/src/name-assignment/assignment-email.cpp
+++ b/src/name-assignment/assignment-email.cpp
@@ -22,7 +22,7 @@
namespace ndncert {
-NDNCERT_REGISTER_FUNCFACTORY(AssignmentEmail, "email");
+NDNCERT_REGISTER_NAME_ASSIGNMENT_FUNC(AssignmentEmail, "email");
AssignmentEmail::AssignmentEmail(const std::string& format)
: NameAssignmentFunc(format)
diff --git a/src/name-assignment/assignment-email.hpp b/src/name-assignment/assignment-email.hpp
index c0bb330..f4eb5c5 100644
--- a/src/name-assignment/assignment-email.hpp
+++ b/src/name-assignment/assignment-email.hpp
@@ -26,12 +26,13 @@
namespace ndncert {
/**
- * assign names base on client probe parameter
+ * @brief Assign names based on requester's email address
*/
class AssignmentEmail : public NameAssignmentFunc
{
public:
- explicit AssignmentEmail(const std::string& format = "");
+ explicit
+ AssignmentEmail(const std::string& format = "");
std::vector<ndn::PartialName>
assignName(const std::multimap<std::string, std::string>& params) override;
diff --git a/src/name-assignment/assignment-func.cpp b/src/name-assignment/assignment-func.cpp
index f4728d3..1e33986 100644
--- a/src/name-assignment/assignment-func.cpp
+++ b/src/name-assignment/assignment-func.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -40,15 +40,15 @@
std::unique_ptr<NameAssignmentFunc>
NameAssignmentFunc::createNameAssignmentFunc(const std::string& challengeType, const std::string& format)
{
- CurriedFuncFactory& factory = getFactory();
+ auto& factory = getFactory();
auto i = factory.find(challengeType);
return i == factory.end() ? nullptr : i->second(format);
}
-NameAssignmentFunc::CurriedFuncFactory&
+NameAssignmentFunc::FuncFactory&
NameAssignmentFunc::getFactory()
{
- static NameAssignmentFunc::CurriedFuncFactory factory;
+ static FuncFactory factory;
return factory;
}
diff --git a/src/name-assignment/assignment-func.hpp b/src/name-assignment/assignment-func.hpp
index 7f35fcf..f08e50c 100644
--- a/src/name-assignment/assignment-func.hpp
+++ b/src/name-assignment/assignment-func.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -30,10 +30,12 @@
class NameAssignmentFunc : boost::noncopyable
{
protected:
- explicit NameAssignmentFunc(const std::string& format = "");
+ explicit
+ NameAssignmentFunc(const std::string& format = "");
public:
- virtual ~NameAssignmentFunc() = default;
+ virtual
+ ~NameAssignmentFunc() = default;
/**
* @brief The name assignment function provided by the CA operator to generate available
@@ -48,40 +50,40 @@
virtual std::vector<ndn::PartialName>
assignName(const std::multimap<std::string, std::string>& params) = 0;
-public:
- template <class AssignmentType>
+public: // factory
+ template<class AssignmentType>
static void
- registerNameAssignmentFunc(const std::string& typeName)
+ registerNameAssignmentFunc(const std::string& type)
{
- CurriedFuncFactory& factory = getFactory();
- BOOST_ASSERT(factory.count(typeName) == 0);
- factory[typeName] = [](const std::string& format) { return std::make_unique<AssignmentType>(format); };
+ auto& factory = getFactory();
+ BOOST_ASSERT(factory.count(type) == 0);
+ factory[type] = [] (const std::string& format) { return std::make_unique<AssignmentType>(format); };
}
static std::unique_ptr<NameAssignmentFunc>
- createNameAssignmentFunc(const std::string& challengeType, const std::string& format = "");
+ createNameAssignmentFunc(const std::string& type, const std::string& format = "");
NDNCERT_PUBLIC_WITH_TESTS_ELSE_PROTECTED:
std::vector<std::string> m_nameFormat;
private:
- typedef std::function<std::unique_ptr<NameAssignmentFunc>(const std::string&)> FactoryCreateFunc;
- typedef std::map<std::string, FactoryCreateFunc> CurriedFuncFactory;
+ using CreateFunc = std::function<std::unique_ptr<NameAssignmentFunc>(const std::string &)>;
+ using FuncFactory = std::map<std::string, CreateFunc>;
- static CurriedFuncFactory&
+ static FuncFactory&
getFactory();
};
-#define NDNCERT_REGISTER_FUNCFACTORY(C, T) \
- static class NdnCert##C##FuncFactoryRegistrationClass \
- { \
- public: \
- NdnCert##C##FuncFactoryRegistrationClass() \
- { \
- ::ndncert::NameAssignmentFunc::registerNameAssignmentFunc<C>(T); \
- } \
- } g_NdnCert##C##ChallengeRegistrationVariable
-
} // namespace ndncert
+#define NDNCERT_REGISTER_NAME_ASSIGNMENT_FUNC(C, T) \
+static class NdnCert##C##NameAssignmentRegistrationClass \
+{ \
+public: \
+ NdnCert##C##NameAssignmentRegistrationClass() \
+ { \
+ ::ndncert::NameAssignmentFunc::registerNameAssignmentFunc<C>(T); \
+ } \
+} g_NdnCert##C##NameAssignmentRegistrationVariable
+
#endif // NDNCERT_ASSIGNMENT_FUNC_HPP
diff --git a/src/name-assignment/assignment-hash.cpp b/src/name-assignment/assignment-hash.cpp
index f406619..c8c56e5 100644
--- a/src/name-assignment/assignment-hash.cpp
+++ b/src/name-assignment/assignment-hash.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -24,7 +24,7 @@
namespace ndncert {
-NDNCERT_REGISTER_FUNCFACTORY(AssignmentHash, "hash");
+NDNCERT_REGISTER_NAME_ASSIGNMENT_FUNC(AssignmentHash, "hash");
AssignmentHash::AssignmentHash(const std::string& format)
: NameAssignmentFunc(format)
diff --git a/src/name-assignment/assignment-param.cpp b/src/name-assignment/assignment-param.cpp
index e1961e7..6995557 100644
--- a/src/name-assignment/assignment-param.cpp
+++ b/src/name-assignment/assignment-param.cpp
@@ -22,7 +22,7 @@
namespace ndncert {
-NDNCERT_REGISTER_FUNCFACTORY(AssignmentParam, "param");
+NDNCERT_REGISTER_NAME_ASSIGNMENT_FUNC(AssignmentParam, "param");
AssignmentParam::AssignmentParam(const std::string& format)
: NameAssignmentFunc(format)
diff --git a/src/name-assignment/assignment-random.cpp b/src/name-assignment/assignment-random.cpp
index 3305cae..efbe07a 100644
--- a/src/name-assignment/assignment-random.cpp
+++ b/src/name-assignment/assignment-random.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -24,7 +24,7 @@
namespace ndncert {
-NDNCERT_REGISTER_FUNCFACTORY(AssignmentRandom, "random");
+NDNCERT_REGISTER_NAME_ASSIGNMENT_FUNC(AssignmentRandom, "random");
AssignmentRandom::AssignmentRandom(const std::string& format)
: NameAssignmentFunc(format)
@@ -34,7 +34,7 @@
std::vector<ndn::PartialName>
AssignmentRandom::assignName(const std::multimap<std::string, std::string>&)
{
- return {ndn::PartialName(ndn::to_string(ndn::random::generateSecureWord64()))};
+ return {ndn::PartialName(std::to_string(ndn::random::generateSecureWord64()))};
}
} // namespace ndncert
diff --git a/src/redirection/redirection-email.cpp b/src/redirection/redirection-email.cpp
index 863eb91..c13ad91 100644
--- a/src/redirection/redirection-email.cpp
+++ b/src/redirection/redirection-email.cpp
@@ -19,16 +19,16 @@
*/
#include "redirection-email.hpp"
+
#include <boost/algorithm/string.hpp>
namespace ndncert {
-NDNCERT_REGISTER_POLICY_FACTORY(RedirectionEmail, "email");
+NDNCERT_REGISTER_REDIRECTION_POLICY(RedirectionEmail, "email");
RedirectionEmail::RedirectionEmail(const std::string& format)
- : RedirectionPolicy(format)
+ : m_domain(format)
{
- m_domain = format;
}
bool
diff --git a/src/redirection/redirection-email.hpp b/src/redirection/redirection-email.hpp
index 9a338ef..9a8c403 100644
--- a/src/redirection/redirection-email.hpp
+++ b/src/redirection/redirection-email.hpp
@@ -25,13 +25,11 @@
namespace ndncert {
-/**
- * assign names base on client probe parameter
- */
class RedirectionEmail : public RedirectionPolicy
{
public:
- explicit RedirectionEmail(const std::string& format = "");
+ explicit
+ RedirectionEmail(const std::string& format = "");
bool
isRedirecting(const std::multimap<std::string, std::string>& params) override;
diff --git a/src/redirection/redirection-param.cpp b/src/redirection/redirection-param.cpp
index d74d105..1ce9517 100644
--- a/src/redirection/redirection-param.cpp
+++ b/src/redirection/redirection-param.cpp
@@ -19,18 +19,19 @@
*/
#include "redirection-param.hpp"
+
#include <boost/algorithm/string.hpp>
namespace ndncert {
-NDNCERT_REGISTER_POLICY_FACTORY(RedirectionParam, "param");
+NDNCERT_REGISTER_REDIRECTION_POLICY(RedirectionParam, "param");
RedirectionParam::RedirectionParam(const std::string& format)
- : RedirectionPolicy(format)
{
if (format.empty()) {
return;
}
+
std::vector<std::string> strs;
boost::split(strs,format,boost::is_any_of("&"));
for (const auto& s : strs) {
@@ -47,7 +48,7 @@
{
for (const auto& p : m_format) {
bool found = false;
- for (auto it = params.find(p.first); it != params.end() && it->first == p.first; it ++) {
+ for (auto it = params.find(p.first); it != params.end() && it->first == p.first; ++it) {
if (it->second == p.second) {
found = true;
break;
diff --git a/src/redirection/redirection-param.hpp b/src/redirection/redirection-param.hpp
index d067a1f..270fb3d 100644
--- a/src/redirection/redirection-param.hpp
+++ b/src/redirection/redirection-param.hpp
@@ -25,13 +25,11 @@
namespace ndncert {
-/**
- * assign names base on client probe parameter
- */
class RedirectionParam : public RedirectionPolicy
{
public:
- explicit RedirectionParam(const std::string& format = "");
+ explicit
+ RedirectionParam(const std::string& format = "");
bool
isRedirecting(const std::multimap<std::string, std::string>& params) override;
diff --git a/src/redirection/redirection-policy.cpp b/src/redirection/redirection-policy.cpp
index 88aef3e..9ecda9a 100644
--- a/src/redirection/redirection-policy.cpp
+++ b/src/redirection/redirection-policy.cpp
@@ -25,7 +25,7 @@
std::unique_ptr<RedirectionPolicy>
RedirectionPolicy::createPolicyFunc(const std::string& policyType, const std::string& format)
{
- PolicyFactory& factory = getFactory();
+ auto& factory = getFactory();
auto i = factory.find(policyType);
return i == factory.end() ? nullptr : i->second(format);
}
diff --git a/src/redirection/redirection-policy.hpp b/src/redirection/redirection-policy.hpp
index cba0cd8..9e55467 100644
--- a/src/redirection/redirection-policy.hpp
+++ b/src/redirection/redirection-policy.hpp
@@ -29,11 +29,9 @@
class RedirectionPolicy : boost::noncopyable
{
-protected:
- explicit RedirectionPolicy(const std::string& format = "") {}
-
public:
- virtual ~RedirectionPolicy() = default;
+ virtual
+ ~RedirectionPolicy() = default;
/**
* @brief The Redirection Policy provided by the CA operator to decide if redirection is suitable.
@@ -45,37 +43,37 @@
virtual bool
isRedirecting(const std::multimap<std::string, std::string>& params) = 0;
-public:
- template <class PolicyType>
+public: // factory
+ template<class PolicyType>
static void
- registerRedirectionPolicy(const std::string& typeName)
+ registerRedirectionPolicy(const std::string& type)
{
PolicyFactory& factory = getFactory();
- BOOST_ASSERT(factory.count(typeName) == 0);
- factory[typeName] = [](const std::string& format) { return std::make_unique<PolicyType>(format); };
+ BOOST_ASSERT(factory.count(type) == 0);
+ factory[type] = [] (const std::string& format) { return std::make_unique<PolicyType>(format); };
}
static std::unique_ptr<RedirectionPolicy>
createPolicyFunc(const std::string& policyType, const std::string& format = "");
private:
- typedef std::function<std::unique_ptr<RedirectionPolicy>(const std::string&)> FactoryCreateFunc;
- typedef std::map<std::string, FactoryCreateFunc> PolicyFactory;
+ using CreateFunc = std::function<std::unique_ptr<RedirectionPolicy>(const std::string &)>;
+ using PolicyFactory = std::map<std::string, CreateFunc>;
static PolicyFactory&
getFactory();
};
-#define NDNCERT_REGISTER_POLICY_FACTORY(C, T) \
- static class NdnCert##C##PolicyFactoryRegistrationClass \
- { \
- public: \
- NdnCert##C##PolicyFactoryRegistrationClass() \
- { \
- ::ndncert::RedirectionPolicy::registerRedirectionPolicy<C>(T); \
- } \
- } g_NdnCert##C##RedirectionPolicyRegistrationVariable
-
} // namespace ndncert
+#define NDNCERT_REGISTER_REDIRECTION_POLICY(C, T) \
+static class NdnCert##C##RedirectionPolicyRegistrationClass \
+{ \
+public: \
+ NdnCert##C##RedirectionPolicyRegistrationClass() \
+ { \
+ ::ndncert::RedirectionPolicy::registerRedirectionPolicy<C>(T); \
+ } \
+} g_NdnCert##C##RedirectionPolicyRegistrationVariable
+
#endif // NDNCERT_REDIRECTION_POLICY_HPP
diff --git a/src/requester-request.cpp b/src/requester-request.cpp
index 4e6d654..32e29df 100644
--- a/src/requester-request.cpp
+++ b/src/requester-request.cpp
@@ -39,8 +39,7 @@
#include <boost/lexical_cast.hpp>
-namespace ndncert {
-namespace requester {
+namespace ndncert::requester {
NDN_LOG_INIT(ndncert.client);
@@ -63,7 +62,7 @@
return std::make_shared<Interest>(interestName);
}
-optional<CaProfile>
+std::optional<CaProfile>
Request::onCaProfileResponse(const Data& reply)
{
auto caItem = infotlv::decodeDataContent(reply.getContent());
@@ -74,7 +73,7 @@
return caItem;
}
-optional<CaProfile>
+std::optional<CaProfile>
Request::onCaProfileResponseAfterRedirection(const Data& reply, const Name& caCertFullName)
{
auto caItem = infotlv::decodeDataContent(reply.getContent());
@@ -94,7 +93,7 @@
interestName.append("CA").append("PROBE");
auto interest = std::make_shared<Interest>(interestName);
interest->setMustBeFresh(true);
- interest->setApplicationParameters(probetlv::encodeApplicationParameters(std::move(probeInfo)));
+ interest->setApplicationParameters(probetlv::encodeApplicationParameters(probeInfo));
return interest;
}
@@ -220,7 +219,7 @@
if (challenge == nullptr) {
NDN_THROW(std::runtime_error("The challenge selected is not supported by your current version of NDNCERT."));
}
- auto challengeParams = challenge->genChallengeRequestTLV(m_status, m_challengeStatus, std::move(parameters));
+ auto challengeParams = challenge->genChallengeRequestTLV(m_status, m_challengeStatus, parameters);
Name interestName = m_caProfile.caPrefix;
interestName.append("CA").append("CHALLENGE").append(Name::Component(m_requestId));
@@ -284,5 +283,4 @@
" and Error Info: " + std::get<1>(errorInfo)));
}
-} // namespace requester
-} // namespace ndncert
+} // namespace ndncert::requester
diff --git a/src/requester-request.hpp b/src/requester-request.hpp
index 0f8447a..729d106 100644
--- a/src/requester-request.hpp
+++ b/src/requester-request.hpp
@@ -27,8 +27,7 @@
#include <ndn-cxx/security/key-chain.hpp>
-namespace ndncert {
-namespace requester {
+namespace ndncert::requester {
class Request : boost::noncopyable
{
@@ -61,7 +60,7 @@
* @return the CaProfile if decoding is successful
* @throw std::runtime_error if the decoding fails or receiving an error packet.
*/
- static optional<CaProfile>
+ static std::optional<CaProfile>
onCaProfileResponse(const Data& reply);
/**
@@ -76,7 +75,7 @@
* @return the CaProfile if decoding is successful
* @throw std::runtime_error if the decoding fails or receiving an error packet.
*/
- static optional<CaProfile>
+ static std::optional<CaProfile>
onCaProfileResponseAfterRedirection(const Data& reply, const Name& caCertFullName);
/**
@@ -276,7 +275,6 @@
ndn::security::Key m_keyPair;
};
-} // namespace requester
-} // namespace ndncert
+} // namespace ndncert::requester
#endif // NDNCERT_REQUESTER_REQUEST_HPP
diff --git a/tests/database-fixture.hpp b/tests/database-fixture.hpp
index 53f813e..283ae2b 100644
--- a/tests/database-fixture.hpp
+++ b/tests/database-fixture.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -27,8 +27,7 @@
#include <boost/filesystem.hpp>
-namespace ndncert {
-namespace tests {
+namespace ndncert::tests {
class IdentityManagementTimeFixture : public UnitTestTimeFixture
, public IdentityManagementFixture
@@ -56,7 +55,6 @@
boost::filesystem::path dbDir;
};
-} // namespace tests
-} // namespace ndncert
+} // namespace ndncert::tests
#endif // NDNCERT_TESTS_DATABASE_FIXTURE_HPP
diff --git a/tests/global-configuration.cpp b/tests/global-configuration.cpp
index e526936..bad7caf 100644
--- a/tests/global-configuration.cpp
+++ b/tests/global-configuration.cpp
@@ -26,8 +26,7 @@
#include <fstream>
#include <stdlib.h>
-namespace ndncert {
-namespace tests {
+namespace ndncert::tests {
class GlobalConfiguration
{
@@ -63,5 +62,4 @@
BOOST_TEST_GLOBAL_CONFIGURATION(GlobalConfiguration);
-} // namespace tests
-} // namespace ndncert
+} // namespace ndncert::tests
diff --git a/tests/identity-management-fixture.cpp b/tests/identity-management-fixture.cpp
index 254da23..86655c4 100644
--- a/tests/identity-management-fixture.cpp
+++ b/tests/identity-management-fixture.cpp
@@ -26,8 +26,7 @@
#include <boost/filesystem.hpp>
-namespace ndncert {
-namespace tests {
+namespace ndncert::tests {
using namespace ndn::security;
@@ -126,5 +125,4 @@
return certificate;
}
-} // namespace tests
-} // namespace ndncert
+} // namespace ndncert::tests
diff --git a/tests/identity-management-fixture.hpp b/tests/identity-management-fixture.hpp
index 7856bf9..8c435a4 100644
--- a/tests/identity-management-fixture.hpp
+++ b/tests/identity-management-fixture.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -27,8 +27,7 @@
#include <ndn-cxx/security/key-chain.hpp>
#include <ndn-cxx/security/signing-helpers.hpp>
-namespace ndncert {
-namespace tests {
+namespace ndncert::tests {
class IdentityManagementBaseFixture
{
@@ -98,7 +97,6 @@
ndn::KeyChain m_keyChain;
};
-} // namespace tests
-} // namespace ndncert
+} // namespace ndncert::tests
#endif // NDN_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP
diff --git a/tests/unit-test-time-fixture.hpp b/tests/unit-test-time-fixture.hpp
index c497940..0ea3635 100644
--- a/tests/unit-test-time-fixture.hpp
+++ b/tests/unit-test-time-fixture.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2022 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -28,8 +28,7 @@
#include <boost/asio/io_service.hpp>
-namespace ndncert {
-namespace tests {
+namespace ndncert::tests {
/** \brief a test fixture that overrides steady clock and system clock
*/
@@ -102,7 +101,6 @@
boost::asio::io_service io;
};
-} // namespace tests
-} // namespace ndncert
+} // namespace ndncert::tests
#endif // NDN_TESTS_UNIT_UNIT_TEST_TIME_FIXTURE_HPP
diff --git a/tests/unit-tests/bench.t.cpp b/tests/unit-tests/bench.t.cpp
index a8098e4..335f448 100644
--- a/tests/unit-tests/bench.t.cpp
+++ b/tests/unit-tests/bench.t.cpp
@@ -22,10 +22,10 @@
#include "challenge/challenge-pin.hpp"
#include "detail/info-encoder.hpp"
#include "requester-request.hpp"
+
#include "test-common.hpp"
-namespace ndncert {
-namespace tests {
+namespace ndncert::tests {
BOOST_FIXTURE_TEST_SUITE(Benchmark, IdentityManagementTimeFixture)
@@ -167,5 +167,4 @@
BOOST_AUTO_TEST_SUITE_END() // Benchmark
-} // namespace tests
-} // namespace ndncert
+} // namespace ndncert::tests
diff --git a/tests/unit-tests/ca-memory.t.cpp b/tests/unit-tests/ca-memory.t.cpp
index fd6f9a5..fa1ddd8 100644
--- a/tests/unit-tests/ca-memory.t.cpp
+++ b/tests/unit-tests/ca-memory.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -19,11 +19,10 @@
*/
#include "detail/ca-memory.hpp"
-#include "detail/ca-sqlite.hpp"
+
#include "test-common.hpp"
-namespace ndncert {
-namespace tests {
+namespace ndncert::tests {
using namespace ca;
@@ -94,5 +93,4 @@
BOOST_AUTO_TEST_SUITE_END() // TestCaMemory
-} // namespace tests
-} // namespace ndncert
+} // namespace ndncert::tests
diff --git a/tests/unit-tests/ca-module.t.cpp b/tests/unit-tests/ca-module.t.cpp
index 3d76678..19f369d 100644
--- a/tests/unit-tests/ca-module.t.cpp
+++ b/tests/unit-tests/ca-module.t.cpp
@@ -24,10 +24,10 @@
#include "challenge/challenge-pin.hpp"
#include "detail/info-encoder.hpp"
#include "requester-request.hpp"
+
#include "test-common.hpp"
-namespace ndncert {
-namespace tests {
+namespace ndncert::tests {
using namespace ca;
using ndn::util::DummyClientFace;
@@ -596,5 +596,4 @@
BOOST_AUTO_TEST_SUITE_END() // TestCaModule
-} // namespace tests
-} // namespace ndncert
+} // namespace ndncert::tests
diff --git a/tests/unit-tests/ca-sqlite.t.cpp b/tests/unit-tests/ca-sqlite.t.cpp
index c592d47..fcd1348 100644
--- a/tests/unit-tests/ca-sqlite.t.cpp
+++ b/tests/unit-tests/ca-sqlite.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -19,10 +19,10 @@
*/
#include "detail/ca-sqlite.hpp"
+
#include "test-common.hpp"
-namespace ndncert {
-namespace tests {
+namespace ndncert::tests {
using namespace ca;
@@ -131,5 +131,4 @@
BOOST_AUTO_TEST_SUITE_END() // TestCaSqlite
-} // namespace tests
-} // namespace ndncert
+} // namespace ndncert::tests
diff --git a/tests/unit-tests/challenge-email.t.cpp b/tests/unit-tests/challenge-email.t.cpp
index 1044660..d996d4a 100644
--- a/tests/unit-tests/challenge-email.t.cpp
+++ b/tests/unit-tests/challenge-email.t.cpp
@@ -19,10 +19,10 @@
*/
#include "challenge/challenge-email.hpp"
+
#include "test-common.hpp"
-namespace ndncert {
-namespace tests {
+namespace ndncert::tests {
BOOST_FIXTURE_TEST_SUITE(TestChallengeEmail, IdentityManagementFixture)
@@ -154,5 +154,4 @@
BOOST_AUTO_TEST_SUITE_END() // TestChallengeEmail
-} // namespace tests
-} // namespace ndncert
+} // namespace ndncert::tests
diff --git a/tests/unit-tests/challenge-pin.t.cpp b/tests/unit-tests/challenge-pin.t.cpp
index b835089..49e3e29 100644
--- a/tests/unit-tests/challenge-pin.t.cpp
+++ b/tests/unit-tests/challenge-pin.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -19,10 +19,10 @@
*/
#include "challenge/challenge-pin.hpp"
+
#include "test-common.hpp"
-namespace ndncert {
-namespace tests {
+namespace ndncert::tests {
BOOST_FIXTURE_TEST_SUITE(TestChallengePin, IdentityManagementFixture)
@@ -113,5 +113,4 @@
BOOST_AUTO_TEST_SUITE_END() // TestChallengePin
-} // namespace tests
-} // namespace ndncert
+} // namespace ndncert::tests
diff --git a/tests/unit-tests/challenge-possession.t.cpp b/tests/unit-tests/challenge-possession.t.cpp
index 0a25577..bfc48a6 100644
--- a/tests/unit-tests/challenge-possession.t.cpp
+++ b/tests/unit-tests/challenge-possession.t.cpp
@@ -20,10 +20,10 @@
#include "challenge/challenge-possession.hpp"
#include "detail/challenge-encoder.hpp"
+
#include "test-common.hpp"
-namespace ndncert {
-namespace tests {
+namespace ndncert::tests {
BOOST_FIXTURE_TEST_SUITE(TestChallengePossession, IdentityManagementFixture)
@@ -145,5 +145,4 @@
BOOST_AUTO_TEST_SUITE_END() // TestChallengePossession
-} // namespace tests
-} // namespace ndncert
+} // namespace ndncert::tests
diff --git a/tests/unit-tests/configuration.t.cpp b/tests/unit-tests/configuration.t.cpp
index bb380f9..7d38adc 100644
--- a/tests/unit-tests/configuration.t.cpp
+++ b/tests/unit-tests/configuration.t.cpp
@@ -21,10 +21,10 @@
#include "detail/ca-configuration.hpp"
#include "detail/profile-storage.hpp"
#include "detail/info-encoder.hpp"
+
#include "test-common.hpp"
-namespace ndncert {
-namespace tests {
+namespace ndncert::tests {
BOOST_FIXTURE_TEST_SUITE(TestConfig, IdentityManagementFixture)
@@ -144,5 +144,4 @@
BOOST_AUTO_TEST_SUITE_END() // TestConfig
-} // namespace tests
-} // namespace ndncert
+} // namespace ndncert::tests
diff --git a/tests/unit-tests/crypto-helpers.t.cpp b/tests/unit-tests/crypto-helpers.t.cpp
index 008a2f6..e67828f 100644
--- a/tests/unit-tests/crypto-helpers.t.cpp
+++ b/tests/unit-tests/crypto-helpers.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -19,10 +19,10 @@
*/
#include "detail/crypto-helpers.hpp"
+
#include "test-common.hpp"
-namespace ndncert {
-namespace tests {
+namespace ndncert::tests {
BOOST_AUTO_TEST_SUITE(TestCryptoHelpers)
@@ -339,5 +339,4 @@
BOOST_AUTO_TEST_SUITE_END() // TestCryptoHelpers
-} // namespace tests
-} // namespace ndncert
+} // namespace ndncert::tests
diff --git a/tests/unit-tests/name-assignment.t.cpp b/tests/unit-tests/name-assignment.t.cpp
index cecbc59..da8396a 100644
--- a/tests/unit-tests/name-assignment.t.cpp
+++ b/tests/unit-tests/name-assignment.t.cpp
@@ -22,10 +22,10 @@
#include "name-assignment/assignment-random.hpp"
#include "name-assignment/assignment-param.hpp"
#include "name-assignment/assignment-hash.hpp"
+
#include "test-common.hpp"
-namespace ndncert {
-namespace tests {
+namespace ndncert::tests {
BOOST_AUTO_TEST_SUITE(TestNameAssignment)
@@ -93,5 +93,4 @@
BOOST_AUTO_TEST_SUITE_END() // TestNameAssignment
-} // namespace tests
-} // namespace ndncert
+} // namespace ndncert::tests
diff --git a/tests/unit-tests/protocol-encoders.t.cpp b/tests/unit-tests/protocol-encoders.t.cpp
index 720c10e..a569f0e 100644
--- a/tests/unit-tests/protocol-encoders.t.cpp
+++ b/tests/unit-tests/protocol-encoders.t.cpp
@@ -21,13 +21,13 @@
#include "detail/challenge-encoder.hpp"
#include "detail/error-encoder.hpp"
#include "detail/info-encoder.hpp"
-#include "detail/request-encoder.hpp"
#include "detail/probe-encoder.hpp"
+#include "detail/request-encoder.hpp"
#include "detail/ca-configuration.hpp"
+
#include "test-common.hpp"
-namespace ndncert {
-namespace tests {
+namespace ndncert::tests {
BOOST_FIXTURE_TEST_SUITE(TestProtocolEncoding, IdentityManagementTimeFixture)
@@ -172,5 +172,4 @@
BOOST_AUTO_TEST_SUITE_END() // TestProtocolEncoding
-} // namespace tests
-} // namespace ndncert
+} // namespace ndncert::tests
diff --git a/tests/unit-tests/redirection-policy.t.cpp b/tests/unit-tests/redirection-policy.t.cpp
index d8d5203..bcc0d9f 100644
--- a/tests/unit-tests/redirection-policy.t.cpp
+++ b/tests/unit-tests/redirection-policy.t.cpp
@@ -21,10 +21,10 @@
#include "redirection/redirection-policy.hpp"
#include "redirection/redirection-param.hpp"
#include "redirection/redirection-email.hpp"
+
#include "test-common.hpp"
-namespace ndncert {
-namespace tests {
+namespace ndncert::tests {
BOOST_AUTO_TEST_SUITE(TestRedirectionPolicy)
@@ -76,5 +76,4 @@
BOOST_AUTO_TEST_SUITE_END() // TestNameAssignment
-} // namespace tests
-} // namespace ndncert
+} // namespace ndncert::tests
diff --git a/tests/unit-tests/requester.t.cpp b/tests/unit-tests/requester.t.cpp
index 73da390..858a127 100644
--- a/tests/unit-tests/requester.t.cpp
+++ b/tests/unit-tests/requester.t.cpp
@@ -19,14 +19,14 @@
*/
#include "requester-request.hpp"
+#include "ca-module.hpp"
+#include "challenge/challenge-module.hpp"
#include "detail/error-encoder.hpp"
#include "detail/probe-encoder.hpp"
-#include "challenge/challenge-module.hpp"
-#include "ca-module.hpp"
+
#include "test-common.hpp"
-namespace ndncert {
-namespace tests {
+namespace ndncert::tests {
using namespace requester;
@@ -128,5 +128,4 @@
BOOST_AUTO_TEST_SUITE_END() // TestRequester
-} // namespace tests
-} // namespace ndncert
+} // namespace ndncert::tests
diff --git a/tools/ndncert-ca-server.cpp b/tools/ndncert-ca-server.cpp
index 8260502..a8af693 100644
--- a/tools/ndncert-ca-server.cpp
+++ b/tools/ndncert-ca-server.cpp
@@ -25,15 +25,15 @@
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/program_options/variables_map.hpp>
-#include <iostream>
+
#include <chrono>
#include <deque>
+#include <iostream>
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/security/key-chain.hpp>
-namespace ndncert {
-namespace ca {
+namespace ndncert::ca {
static ndn::Face face;
static ndn::KeyChain keyChain;
@@ -42,7 +42,8 @@
const size_t MAX_CACHED_CERT_NUM = 100;
static bool
-writeDataToRepo(const Data& data) {
+writeDataToRepo(const Data& data)
+{
boost::asio::ip::tcp::iostream requestStream;
#if BOOST_VERSION >= 106600
requestStream.expires_after(std::chrono::seconds(3));
@@ -162,8 +163,7 @@
return 0;
}
-} // namespace ca
-} // namespace ndncert
+} // namespace ndncert::ca
int
main(int argc, char* argv[])
diff --git a/tools/ndncert-ca-status.cpp b/tools/ndncert-ca-status.cpp
index 2d0c0f9..c4f14c1 100644
--- a/tools/ndncert-ca-status.cpp
+++ b/tools/ndncert-ca-status.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -27,8 +27,7 @@
#include <iostream>
-namespace ndncert {
-namespace ca {
+namespace ndncert::ca {
static int
main(int argc, char* argv[])
@@ -74,8 +73,7 @@
return 0;
}
-} // namespace ca
-} // namespace ndncert
+} // namespace ndncert::ca
int
main(int argc, char* argv[])
diff --git a/tools/ndncert-client.cpp b/tools/ndncert-client.cpp
index c99104a..b2e3593 100644
--- a/tools/ndncert-client.cpp
+++ b/tools/ndncert-client.cpp
@@ -31,11 +31,10 @@
#include <iostream>
-namespace ndncert {
-namespace requester {
+namespace ndncert::requester {
static void
-selectCaProfile(std::string configFilePath);
+selectCaProfile(const std::string& configFilePath);
static void
runProbe(CaProfile profile);
@@ -92,7 +91,7 @@
<< " The CA may reject your application if your expected period is too long."
<< " The maximum validity period allowed by this CA is " << maxValidityPeriod << "."<< std::endl;
size_t count = 0;
- while (true && count < 3) {
+ while (count < 3) {
std::string periodStr = "";
getline(std::cin, periodStr);
try {
@@ -161,7 +160,7 @@
}
}
-static void
+[[noreturn]] static void
onNackCb()
{
std::cerr << "Got NACK\n";
@@ -171,7 +170,7 @@
static void
timeoutCb()
{
- std::cerr << "Interest sent time out\n";
+ std::cerr << "Interest timeout\n";
}
static void
@@ -223,62 +222,61 @@
}
size_t challengeIndex = 0;
- if (challengeList.size() < 1) {
+ if (challengeList.empty()) {
std::cerr << "There is no available challenge provided by the CA. Exit" << std::endl;
exit(1);
}
- else if (challengeList.size() >= 1) {
- auto item = std::find(challengeList.begin(), challengeList.end(), defaultChallenge);
- if (item != challengeList.end()) {
- runChallenge(defaultChallenge);
- }
- else {
- // default challenge not available
- std::cerr << "\n***************************************\n"
- << "Step " << nStep++
- << ": CHALLENGE SELECTION" << std::endl;
- size_t count = 0;
- std::string choice = "";
- for (auto item : challengeList) {
- std::cerr << "> Index: " << count++ << std::endl
- << ">> Challenge: " << item << std::endl;
- }
- std::cerr << "Please type in the index of the challenge that you want to perform:" << std::endl;
- size_t inputCount = 0;
- while (inputCount < 3) {
- getline(std::cin, choice);
- try {
- challengeIndex = std::stoul(choice);
- }
- catch (const std::exception&) {
- std::cerr << "Your input is not valid. Try again:" << std::endl;
- inputCount++;
- continue;
- }
- if (challengeIndex >= count) {
- std::cerr << "Your input index is out of range. Try again:" << std::endl;
- inputCount++;
- continue;
- }
- break;
- }
- if (inputCount == 3) {
- std::cerr << "Invalid input for too many times, exit. " << std::endl;
- exit(1);
- }
- auto it = challengeList.begin();
- std::advance(it, challengeIndex);
- std::cerr << "The challenge has been selected: " << *it << std::endl;
- runChallenge(*it);
+ auto item = std::find(challengeList.begin(), challengeList.end(), defaultChallenge);
+ if (item != challengeList.end()) {
+ runChallenge(defaultChallenge);
+ }
+ else {
+ // default challenge not available
+ std::cerr << "\n***************************************\n"
+ << "Step " << nStep++
+ << ": CHALLENGE SELECTION" << std::endl;
+ size_t count = 0;
+ std::string choice = "";
+ for (const auto& item : challengeList) {
+ std::cerr << "> Index: " << count++ << std::endl
+ << ">> Challenge: " << item << std::endl;
}
+ std::cerr << "Please type in the index of the challenge that you want to perform:" << std::endl;
+ size_t inputCount = 0;
+ while (inputCount < 3) {
+ getline(std::cin, choice);
+ try {
+ challengeIndex = std::stoul(choice);
+ }
+ catch (const std::exception&) {
+ std::cerr << "Your input is not valid. Try again:" << std::endl;
+ inputCount++;
+ continue;
+ }
+ if (challengeIndex >= count) {
+ std::cerr << "Your input index is out of range. Try again:" << std::endl;
+ inputCount++;
+ continue;
+ }
+ break;
+ }
+ if (inputCount == 3) {
+ std::cerr << "Invalid input for too many times, exit. " << std::endl;
+ exit(1);
+ }
+
+ auto it = challengeList.begin();
+ std::advance(it, challengeIndex);
+ std::cerr << "The challenge has been selected: " << *it << std::endl;
+ runChallenge(*it);
}
}
static void
infoCb(const Data& reply, const Name& certFullName)
{
- optional<CaProfile> profile;
+ std::optional<CaProfile> profile;
try {
if (certFullName.empty()) {
profile = Request::onCaProfileResponse(reply);
@@ -329,7 +327,7 @@
Name selectedName;
Name redirectedCaFullName;
// always prefer redirection over direct assignment
- if (redirects.size() > 0) {
+ if (!redirects.empty()) {
if (redirects.size() < 2) {
redirectedCaFullName = redirects.front();
}
@@ -373,7 +371,7 @@
[] (auto&&...) { onNackCb(); },
[] (auto&&...) { timeoutCb(); });
}
- else if (names.size() > 0) {
+ else if (!names.empty()) {
if (names.size() < 2) {
selectedName = names.front().first;
}
@@ -413,7 +411,7 @@
}
static void
-selectCaProfile(std::string configFilePath)
+selectCaProfile(const std::string& configFilePath)
{
ProfileStorage profileStorage;
try {
@@ -426,7 +424,7 @@
size_t count = 0;
std::cerr << "***************************************\n"
<< "Step " << nStep++ << ": CA SELECTION" << std::endl;
- for (auto item : profileStorage.getKnownProfiles()) {
+ for (const auto& item : profileStorage.getKnownProfiles()) {
std::cerr << "> Index: " << count++ << std::endl
<< ">> CA prefix:" << item.caPrefix << std::endl
<< ">> Introduction: " << item.caInfo << std::endl;
@@ -547,7 +545,7 @@
<< "\nExit." << std::endl;
exit(1);
}
- if (requirement.size() > 0) {
+ if (!requirement.empty()) {
if (requesterState->m_status == Status::BEFORE_CHALLENGE && challengeType == defaultChallenge) {
requirement.find(challengeType)->second = capturedProbeParams->find(defaultChallenge)->second;
}
@@ -630,8 +628,7 @@
return 0;
}
-} // namespace requester
-} // namespace ndncert
+} // namespace ndncert::requester
int
main(int argc, char* argv[])