Reduce namespace nesting (ndn::ndncert -> ndncert)
Change-Id: I5b69a2c3673cccdf07ea0ba3a0e7181894328f47
diff --git a/src/detail/ca-configuration.cpp b/src/detail/ca-configuration.cpp
index 813c428..a6d26a0 100644
--- a/src/detail/ca-configuration.cpp
+++ b/src/detail/ca-configuration.cpp
@@ -25,7 +25,6 @@
#include <boost/filesystem.hpp>
#include <boost/property_tree/json_parser.hpp>
-namespace ndn {
namespace ndncert {
namespace ca {
@@ -57,7 +56,7 @@
NDN_THROW(std::runtime_error("Redirect-to item's ca-prefix or certificate cannot be empty."));
}
std::istringstream ss(caCertStr);
- auto caCert = io::load<security::Certificate>(ss);
+ auto caCert = ndn::io::load<Certificate>(ss);
redirection.push_back(caCert);
}
}
@@ -77,4 +76,3 @@
} // namespace ca
} // namespace ndncert
-} // namespace ndn
diff --git a/src/detail/ca-configuration.hpp b/src/detail/ca-configuration.hpp
index ba3de47..2a2a9ff 100644
--- a/src/detail/ca-configuration.hpp
+++ b/src/detail/ca-configuration.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -24,7 +24,6 @@
#include "detail/ca-profile.hpp"
#include "name-assignment/assignment-func.hpp"
-namespace ndn {
namespace ndncert {
namespace ca {
@@ -67,7 +66,7 @@
/**
* @brief Used for CA redirection
*/
- std::vector<std::shared_ptr<security::Certificate>> redirection;
+ std::vector<std::shared_ptr<Certificate>> redirection;
/**
* @brief Name Assignment Functions
*/
@@ -76,6 +75,5 @@
} // namespace ca
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_DETAIL_CA_CONFIGURATION_HPP
diff --git a/src/detail/ca-memory.cpp b/src/detail/ca-memory.cpp
index 48a0903..eae67cc 100644
--- a/src/detail/ca-memory.cpp
+++ b/src/detail/ca-memory.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2020, Regents of the University of California.
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -19,15 +19,11 @@
*/
#include "detail/ca-memory.hpp"
-#include <ndn-cxx/security/validation-policy.hpp>
-namespace ndn {
namespace ndncert {
namespace ca {
-const std::string
-CaMemory::STORAGE_TYPE = "ca-storage-memory";
-
+const std::string CaMemory::STORAGE_TYPE = "ca-storage-memory";
NDNCERT_REGISTER_CA_STORAGE(CaMemory);
CaMemory::CaMemory(const Name& caName, const std::string& path)
@@ -40,7 +36,8 @@
{
auto search = m_requests.find(requestId);
if (search == m_requests.end()) {
- NDN_THROW(std::runtime_error("Request " + toHex(requestId.data(), requestId.size()) + " doest not exists"));
+ NDN_THROW(std::runtime_error("Request " + ndn::toHex(requestId.data(), requestId.size()) +
+ " does not exists"));
}
return search->second;
}
@@ -53,7 +50,8 @@
m_requests.insert(std::make_pair(request.requestId, request));
}
else {
- NDN_THROW(std::runtime_error("Request " + toHex(request.requestId.data(), request.requestId.size()) + " already exists"));
+ NDN_THROW(std::runtime_error("Request " + ndn::toHex(request.requestId.data(), request.requestId.size()) +
+ " already exists"));
}
}
@@ -103,4 +101,3 @@
} // namespace ca
} // namespace ndncert
-} // namespace ndn
diff --git a/src/detail/ca-memory.hpp b/src/detail/ca-memory.hpp
index d61fc10..6d8b115 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-2020, Regents of the University of California.
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,7 +23,6 @@
#include "detail/ca-storage.hpp"
-namespace ndn {
namespace ndncert {
namespace ca {
@@ -64,6 +63,5 @@
} // namespace ca
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_DETAIL_CA_MEMORY_HPP
diff --git a/src/detail/ca-profile.cpp b/src/detail/ca-profile.cpp
index 0f1ad01..624ec7a 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-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -20,10 +20,11 @@
#include "detail/ca-profile.hpp"
#include "challenge/challenge-module.hpp"
+
#include <ndn-cxx/util/io.hpp>
+
#include <boost/filesystem.hpp>
-namespace ndn {
namespace ndncert {
CaProfile
@@ -79,7 +80,7 @@
auto certificateStr = json.get(CONFIG_CERTIFICATE, "");
if (certificateStr != "") {
std::istringstream ss(certificateStr);
- profile.cert = io::load<security::Certificate>(ss);
+ profile.cert = ndn::io::load<Certificate>(ss);
}
return profile;
}
@@ -114,11 +115,10 @@
}
if (cert != nullptr) {
std::stringstream ss;
- io::save(*cert, ss);
+ ndn::io::save(*cert, ss);
caItem.put("certificate", ss.str());
}
return caItem;
}
} // namespace ndncert
-} // namespace ndn
diff --git a/src/detail/ca-profile.hpp b/src/detail/ca-profile.hpp
index 69adf43..0592be5 100644
--- a/src/detail/ca-profile.hpp
+++ b/src/detail/ca-profile.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,7 +23,6 @@
#include "detail/ndncert-common.hpp"
-namespace ndn {
namespace ndncert {
// used in parsing CA configuration file and Client CA profile storage file
@@ -90,10 +89,9 @@
/**
* @brief CA's certificate. Only Client side will have m_cert.
*/
- std::shared_ptr<security::Certificate> cert;
+ std::shared_ptr<Certificate> cert;
};
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_DETAIL_CA_PROFILE_HPP
diff --git a/src/detail/ca-request-state.cpp b/src/detail/ca-request-state.cpp
index b8a6b27..68d189a 100644
--- a/src/detail/ca-request-state.cpp
+++ b/src/detail/ca-request-state.cpp
@@ -24,7 +24,6 @@
#include <boost/property_tree/json_parser.hpp>
-namespace ndn {
namespace ndncert {
std::string statusToString(Status status)
@@ -72,7 +71,7 @@
operator<<(std::ostream& os, const RequestState& request)
{
os << "Request's CA name: " << request.caPrefix << "\n";
- os << "Request's request ID: " << toHex(request.requestId.data(), request.requestId.size()) << "\n";
+ os << "Request's request ID: " << ndn::toHex(request.requestId.data(), request.requestId.size()) << "\n";
os << "Request's status: " << statusToString(request.status) << "\n";
os << "Request's challenge type: " << request.challengeType << "\n";
if (request.challengeState) {
@@ -85,11 +84,10 @@
os << "Challenge secret: " << ss.str() << "\n";
}
os << "Certificate:\n";
- util::IndentedStream os2(os, " ");
+ ndn::util::IndentedStream os2(os, " ");
os2 << request.cert;
return os;
}
} // namespace ca
} // namespace ndncert
-} // namespace ndn
diff --git a/src/detail/ca-request-state.hpp b/src/detail/ca-request-state.hpp
index fe4db23..2c4a1d6 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-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -22,9 +22,9 @@
#define NDNCERT_DETAIL_CA_REQUEST_STATE_HPP
#include "detail/ndncert-common.hpp"
+
#include <array>
-namespace ndn {
namespace ndncert {
typedef std::array<uint8_t, 8> RequestId;
@@ -107,7 +107,7 @@
/**
* @brief The self-signed certificate in the request.
*/
- security::Certificate cert;
+ Certificate cert;
/**
* @brief The encryption key for the requester.
*/
@@ -135,6 +135,5 @@
} // namespace ca
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_DETAIL_CA_REQUEST_STATE_HPP
diff --git a/src/detail/ca-sqlite.cpp b/src/detail/ca-sqlite.cpp
index c247501..45cd84d 100644
--- a/src/detail/ca-sqlite.cpp
+++ b/src/detail/ca-sqlite.cpp
@@ -28,16 +28,15 @@
#include <boost/filesystem.hpp>
#include <boost/property_tree/json_parser.hpp>
-namespace ndn {
namespace ndncert {
namespace ca {
-using namespace ndn::util;
-const std::string CaSqlite::STORAGE_TYPE = "ca-storage-sqlite3";
+using ndn::util::Sqlite3Statement;
+const std::string CaSqlite::STORAGE_TYPE = "ca-storage-sqlite3";
NDNCERT_REGISTER_CA_STORAGE(CaSqlite);
-std::string
+static std::string
convertJson2String(const JsonSection& json)
{
std::stringstream ss;
@@ -45,7 +44,7 @@
return ss.str();
}
-JsonSection
+static JsonSection
convertString2Json(const std::string& jsonContent)
{
std::istringstream ss(jsonContent);
@@ -54,7 +53,7 @@
return json;
}
-static const std::string INITIALIZATION = R"_DBTEXT_(
+const std::string INITIALIZATION = R"SQL(
CREATE TABLE IF NOT EXISTS
RequestStates(
id INTEGER PRIMARY KEY,
@@ -75,10 +74,10 @@
);
CREATE UNIQUE INDEX IF NOT EXISTS
RequestStateIdIndex ON RequestStates(request_id);
-)_DBTEXT_";
+)SQL";
CaSqlite::CaSqlite(const Name& caName, const std::string& path)
- : CaStorage()
+ : CaStorage()
{
// Determine the path of sqlite db
boost::filesystem::path dbDir;
@@ -143,7 +142,7 @@
state.requestId = requestId;
state.caPrefix = Name(statement.getBlock(1));
state.status = static_cast<Status>(statement.getInt(2));
- state.cert = security::Certificate(statement.getBlock(4));
+ state.cert = Certificate(statement.getBlock(4));
state.challengeType = statement.getString(5);
state.requestType = static_cast<RequestType>(statement.getInt(10));
std::memcpy(state.encryptionKey.data(), statement.getBlob(11), statement.getSize(11));
@@ -158,7 +157,7 @@
return state;
}
else {
- NDN_THROW(std::runtime_error("Request " + toHex(requestId.data(), requestId.size()) +
+ NDN_THROW(std::runtime_error("Request " + ndn::toHex(requestId.data(), requestId.size()) +
" cannot be fetched from database"));
}
}
@@ -189,7 +188,7 @@
statement.bind(11, request.challengeState->remainingTime.count());
}
if (statement.step() != SQLITE_DONE) {
- NDN_THROW(std::runtime_error("Request " + toHex(request.requestId.data(), request.requestId.size()) +
+ NDN_THROW(std::runtime_error("Request " + ndn::toHex(request.requestId.data(), request.requestId.size()) +
" cannot be added to database"));
}
}
@@ -242,7 +241,7 @@
state.caPrefix = Name(statement.getBlock(2));
state.status = static_cast<Status>(statement.getInt(3));
state.challengeType = statement.getString(6);
- state.cert = security::Certificate(statement.getBlock(5));
+ state.cert = Certificate(statement.getBlock(5));
state.requestType = static_cast<RequestType>(statement.getInt(11));
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));
@@ -276,7 +275,7 @@
state.caPrefix = Name(statement.getBlock(2));
state.status = static_cast<Status>(statement.getInt(3));
state.challengeType = statement.getString(6);
- state.cert = security::Certificate(statement.getBlock(5));
+ state.cert = Certificate(statement.getBlock(5));
state.requestType = static_cast<RequestType>(statement.getInt(11));
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));
@@ -303,4 +302,3 @@
} // namespace ca
} // namespace ndncert
-} // namespace ndn
diff --git a/src/detail/ca-sqlite.hpp b/src/detail/ca-sqlite.hpp
index 2577a80..969cacf 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-2020, Regents of the University of California.
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -25,7 +25,6 @@
struct sqlite3;
-namespace ndn {
namespace ndncert {
namespace ca {
@@ -37,7 +36,7 @@
explicit
CaSqlite(const Name& caName, const std::string& path = "");
- ~CaSqlite();
+ ~CaSqlite() override;
public:
/**
@@ -70,6 +69,5 @@
} // namespace ca
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_DETAIL_CA_SQLITE_HPP
diff --git a/src/detail/ca-storage.cpp b/src/detail/ca-storage.cpp
index a377c6c..24fe38f 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-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -20,11 +20,10 @@
#include "detail/ca-storage.hpp"
-namespace ndn {
namespace ndncert {
namespace ca {
-unique_ptr<CaStorage>
+std::unique_ptr<CaStorage>
CaStorage::createCaStorage(const std::string& caStorageType, const Name& caName, const std::string& path)
{
CaStorageFactory& factory = getFactory();
@@ -41,4 +40,3 @@
} // namespace ca
} // namespace ndncert
-} // namespace ndn
diff --git a/src/detail/ca-storage.hpp b/src/detail/ca-storage.hpp
index 40166cf..0fa7238 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-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,11 +23,10 @@
#include "detail/ca-request-state.hpp"
-namespace ndn {
namespace ndncert {
namespace ca {
-class CaStorage : noncopyable
+class CaStorage : boost::noncopyable
{
public: // request related
/**
@@ -66,14 +65,14 @@
};
}
- static unique_ptr<CaStorage>
+ static std::unique_ptr<CaStorage>
createCaStorage(const std::string& caStorageType, const Name& caName, const std::string& path);
virtual
~CaStorage() = default;
private:
- using CaStorageCreateFunc = function<unique_ptr<CaStorage> (const Name&, const std::string&)>;
+ using CaStorageCreateFunc = std::function<std::unique_ptr<CaStorage> (const Name&, const std::string&)>;
using CaStorageFactory = std::map<std::string, CaStorageCreateFunc>;
static CaStorageFactory&
@@ -86,12 +85,11 @@
public: \
NdnCert ## C ## CaStorageRegistrationClass() \
{ \
- ::ndn::ndncert::ca::CaStorage::registerCaStorage<C>(); \
+ ::ndncert::ca::CaStorage::registerCaStorage<C>(); \
} \
} g_NdnCert ## C ## CaStorageRegistrationVariable
} // namespace ca
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_DETAIL_CA_STORAGE_HPP
diff --git a/src/detail/challenge-encoder.cpp b/src/detail/challenge-encoder.cpp
index 11a0168..5d9d46b 100644
--- a/src/detail/challenge-encoder.cpp
+++ b/src/detail/challenge-encoder.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -20,30 +20,30 @@
#include "detail/challenge-encoder.hpp"
-namespace ndn {
namespace ndncert {
Block
challengetlv::encodeDataContent(ca::RequestState& request, const Name& issuedCertName)
{
Block response(tlv::EncryptedPayload);
- response.push_back(makeNonNegativeIntegerBlock(tlv::Status, static_cast<uint64_t>(request.status)));
+ response.push_back(ndn::makeNonNegativeIntegerBlock(tlv::Status, static_cast<uint64_t>(request.status)));
if (request.challengeState) {
- response.push_back(makeStringBlock(tlv::ChallengeStatus, request.challengeState->challengeStatus));
- response.push_back(makeNonNegativeIntegerBlock(tlv::RemainingTries,
- request.challengeState->remainingTries));
- response.push_back(makeNonNegativeIntegerBlock(tlv::RemainingTime,
- request.challengeState->remainingTime.count()));
+ response.push_back(ndn::makeStringBlock(tlv::ChallengeStatus, request.challengeState->challengeStatus));
+ response.push_back(ndn::makeNonNegativeIntegerBlock(tlv::RemainingTries,
+ request.challengeState->remainingTries));
+ response.push_back(ndn::makeNonNegativeIntegerBlock(tlv::RemainingTime,
+ request.challengeState->remainingTime.count()));
if (request.challengeState->challengeStatus == "need-proof") {
- response.push_back(makeStringBlock(tlv::ParameterKey, "nonce"));
- auto nonce = fromHex(request.challengeState->secrets.get("nonce", ""));
- response.push_back(makeBinaryBlock(tlv::ParameterValue, nonce->data(), 16));
+ response.push_back(ndn::makeStringBlock(tlv::ParameterKey, "nonce"));
+ auto nonce = ndn::fromHex(request.challengeState->secrets.get("nonce", ""));
+ response.push_back(ndn::makeBinaryBlock(tlv::ParameterValue, nonce->data(), 16));
}
}
if (!issuedCertName.empty()) {
response.push_back(makeNestedBlock(tlv::IssuedCertName, issuedCertName));
}
response.encode();
+
return encodeBlockWithAesGcm128(ndn::tlv::Content, request.encryptionKey.data(),
response.value(), response.value_size(),
request.requestId.data(), request.requestId.size(),
@@ -56,8 +56,9 @@
auto result = decodeBlockWithAesGcm128(contentBlock, state.m_aesKey.data(),
state.m_requestId.data(), state.m_requestId.size(),
state.m_decryptionIv, state.m_encryptionIv);
- auto data = makeBinaryBlock(tlv::EncryptedPayload, result.data(), result.size());
+ auto data = ndn::makeBinaryBlock(tlv::EncryptedPayload, result.data(), result.size());
data.parse();
+
state.m_status = statusFromBlock(data.get(tlv::Status));
if (data.find(tlv::ChallengeStatus) != data.elements_end()) {
state.m_challengeStatus = readString(data.get(tlv::ChallengeStatus));
@@ -87,4 +88,3 @@
}
} // namespace ndncert
-} // namespace ndn
diff --git a/src/detail/challenge-encoder.hpp b/src/detail/challenge-encoder.hpp
index a8baa57..2013061 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-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -24,7 +24,6 @@
#include "detail/ca-request-state.hpp"
#include "requester-request.hpp"
-namespace ndn {
namespace ndncert {
namespace challengetlv {
@@ -36,6 +35,5 @@
} // namespace challengetlv
} // namespace ndncert
-} // namespace ndn
-#endif // NDNCERT_DETAIL_CHALLENGE_ENCODER_HPP
\ No newline at end of file
+#endif // NDNCERT_DETAIL_CHALLENGE_ENCODER_HPP
diff --git a/src/detail/crypto-helpers.cpp b/src/detail/crypto-helpers.cpp
index a2a0af5..d0c2e55 100644
--- a/src/detail/crypto-helpers.cpp
+++ b/src/detail/crypto-helpers.cpp
@@ -37,7 +37,6 @@
#include <cstring>
-namespace ndn {
namespace ndncert {
ECDHState::ECDHState()
@@ -416,25 +415,25 @@
{
// The spec of AES encrypted payload TLV used in NDNCERT:
// https://github.com/named-data/ndncert/wiki/NDNCERT-Protocol-0.3#242-aes-gcm-encryption
- Buffer encryptedPayload(payloadSize);
+ ndn::Buffer encryptedPayload(payloadSize);
uint8_t tag[16];
if (encryptionIv.empty()) {
encryptionIv.resize(12, 0);
- random::generateSecureBytes(encryptionIv.data(), 8);
+ ndn::random::generateSecureBytes(encryptionIv.data(), 8);
}
size_t encryptedPayloadLen = aesGcm128Encrypt(payload, payloadSize, associatedData, associatedDataSize,
key, encryptionIv.data(), encryptedPayload.data(), tag);
Block content(tlvType);
- content.push_back(makeBinaryBlock(tlv::InitializationVector, encryptionIv.data(), encryptionIv.size()));
- content.push_back(makeBinaryBlock(tlv::AuthenticationTag, tag, 16));
- content.push_back(makeBinaryBlock(tlv::EncryptedPayload, encryptedPayload.data(), encryptedPayloadLen));
+ content.push_back(ndn::makeBinaryBlock(tlv::InitializationVector, encryptionIv.data(), encryptionIv.size()));
+ content.push_back(ndn::makeBinaryBlock(tlv::AuthenticationTag, tag, 16));
+ content.push_back(ndn::makeBinaryBlock(tlv::EncryptedPayload, encryptedPayload.data(), encryptedPayloadLen));
content.encode();
// update IV's counter
updateIv(encryptionIv, payloadSize);
return content;
}
-Buffer
+ndn::Buffer
decodeBlockWithAesGcm128(const Block& block, const uint8_t* key,
const uint8_t* associatedData, size_t associatedDataSize,
std::vector<uint8_t>& decryptionIv, const std::vector<uint8_t>& encryptionIv)
@@ -443,7 +442,7 @@
// https://github.com/named-data/ndncert/wiki/NDNCERT-Protocol-0.3#242-aes-gcm-encryption
block.parse();
const auto& encryptedPayloadBlock = block.get(tlv::EncryptedPayload);
- Buffer result(encryptedPayloadBlock.value_size());
+ ndn::Buffer result(encryptedPayloadBlock.value_size());
if (block.get(tlv::InitializationVector).value_size() != 12 ||
block.get(tlv::AuthenticationTag).value_size() != 16) {
NDN_THROW(std::runtime_error("Error when decrypting the AES Encrypted Block: "
@@ -478,4 +477,3 @@
}
} // namespace ndncert
-} // namespace ndn
diff --git a/src/detail/crypto-helpers.hpp b/src/detail/crypto-helpers.hpp
index 9701786..235c6b5 100644
--- a/src/detail/crypto-helpers.hpp
+++ b/src/detail/crypto-helpers.hpp
@@ -25,7 +25,6 @@
#include <openssl/evp.h>
-namespace ndn {
namespace ndncert {
/**
@@ -33,7 +32,7 @@
*
* The ECDH is based on prime256v1.
*/
-class ECDHState : noncopyable
+class ECDHState : boost::noncopyable
{
public:
ECDHState();
@@ -169,7 +168,7 @@
* invocations of this function with the same @p key.
* @return Buffer The plaintext buffer.
*/
-Buffer
+ndn::Buffer
decodeBlockWithAesGcm128(const Block& block, const uint8_t* key,
const uint8_t* associatedData, size_t associatedDataSize,
std::vector<uint8_t>& decryptionIv, const std::vector<uint8_t>& encryptionIv);
@@ -183,6 +182,5 @@
#endif
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_DETAIL_CRYPTO_HELPERS_HPP
diff --git a/src/detail/error-encoder.cpp b/src/detail/error-encoder.cpp
index 3fbbdc2..e1e4357 100644
--- a/src/detail/error-encoder.cpp
+++ b/src/detail/error-encoder.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -20,15 +20,14 @@
#include "detail/error-encoder.hpp"
-namespace ndn {
namespace ndncert {
Block
errortlv::encodeDataContent(ErrorCode errorCode, const std::string& description)
{
Block response(ndn::tlv::Content);
- response.push_back(makeNonNegativeIntegerBlock(tlv::ErrorCode, static_cast<size_t>(errorCode)));
- response.push_back(makeStringBlock(tlv::ErrorInfo, description));
+ response.push_back(ndn::makeNonNegativeIntegerBlock(tlv::ErrorCode, static_cast<size_t>(errorCode)));
+ response.push_back(ndn::makeStringBlock(tlv::ErrorInfo, description));
response.encode();
return response;
}
@@ -45,4 +44,3 @@
}
} // namespace ndncert
-} // namespace ndn
diff --git a/src/detail/error-encoder.hpp b/src/detail/error-encoder.hpp
index 67fe80f..3b17353 100644
--- a/src/detail/error-encoder.hpp
+++ b/src/detail/error-encoder.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,7 +23,6 @@
#include "detail/ca-profile.hpp"
-namespace ndn {
namespace ndncert {
namespace errortlv {
@@ -41,6 +40,5 @@
} // namespace errortlv
} // namespace ndncert
-} // namespace ndn
-#endif // NDNCERT_DETAIL_ERROR_ENCODER_HPP
\ No newline at end of file
+#endif // NDNCERT_DETAIL_ERROR_ENCODER_HPP
diff --git a/src/detail/info-encoder.cpp b/src/detail/info-encoder.cpp
index 79f617f..e6e6581 100644
--- a/src/detail/info-encoder.cpp
+++ b/src/detail/info-encoder.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -20,11 +20,10 @@
#include "detail/info-encoder.hpp"
-namespace ndn {
namespace ndncert {
Block
-infotlv::encodeDataContent(const CaProfile& caConfig, const security::Certificate& certificate)
+infotlv::encodeDataContent(const CaProfile& caConfig, const Certificate& certificate)
{
Block content(ndn::tlv::Content);
content.push_back(makeNestedBlock(tlv::CaPrefix, caConfig.caPrefix));
@@ -35,11 +34,11 @@
else {
caInfo = caConfig.caInfo;
}
- content.push_back(makeStringBlock(tlv::CaInfo, caInfo));
+ content.push_back(ndn::makeStringBlock(tlv::CaInfo, caInfo));
for (const auto& key : caConfig.probeParameterKeys) {
- content.push_back(makeStringBlock(tlv::ParameterKey, key));
+ content.push_back(ndn::makeStringBlock(tlv::ParameterKey, key));
}
- content.push_back(makeNonNegativeIntegerBlock(tlv::MaxValidityPeriod, caConfig.maxValidityPeriod.count()));
+ content.push_back(ndn::makeNonNegativeIntegerBlock(tlv::MaxValidityPeriod, caConfig.maxValidityPeriod.count()));
content.push_back(makeNestedBlock(tlv::CaCertificate, certificate));
content.encode();
return content;
@@ -67,7 +66,7 @@
break;
case tlv::CaCertificate:
item.parse();
- result.cert = std::make_shared<security::Certificate>(item.get(ndn::tlv::Data));
+ result.cert = std::make_shared<Certificate>(item.get(ndn::tlv::Data));
break;
default:
continue;
@@ -78,4 +77,3 @@
}
} // namespace ndncert
-} // namespace ndn
\ No newline at end of file
diff --git a/src/detail/info-encoder.hpp b/src/detail/info-encoder.hpp
index 7f9180e..4eaa967 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-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,7 +23,6 @@
#include "detail/ca-profile.hpp"
-namespace ndn {
namespace ndncert {
namespace infotlv {
@@ -31,7 +30,7 @@
* Encode CA configuration and its certificate into a TLV block as INFO Data packet content.
*/
Block
-encodeDataContent(const CaProfile& caConfig, const security::Certificate& certificate);
+encodeDataContent(const CaProfile& caConfig, const Certificate& certificate);
/**
* Decode CA configuration from the TLV block of INFO Data packet content.
@@ -41,6 +40,5 @@
} // namespace infotlv
} // namespace ndncert
-} // namespace ndn
-#endif // NDNCERT_DETAIL_INFO_ENCODER_HPP
\ No newline at end of file
+#endif // NDNCERT_DETAIL_INFO_ENCODER_HPP
diff --git a/src/detail/ndncert-common.cpp b/src/detail/ndncert-common.cpp
index 7c210b7..5e22afb 100644
--- a/src/detail/ndncert-common.cpp
+++ b/src/detail/ndncert-common.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -20,7 +20,6 @@
#include "detail/ndncert-common.hpp"
-namespace ndn {
namespace ndncert {
std::ostream&
@@ -56,4 +55,3 @@
}
} // namespace ndncert
-} // namespace ndn
diff --git a/src/detail/ndncert-common.hpp b/src/detail/ndncert-common.hpp
index 01fa883..d9863a5 100644
--- a/src/detail/ndncert-common.hpp
+++ b/src/detail/ndncert-common.hpp
@@ -41,26 +41,37 @@
#include <tuple>
#include <ndn-cxx/data.hpp>
-#include <ndn-cxx/encoding/block-helpers.hpp>
#include <ndn-cxx/encoding/block.hpp>
-#include <ndn-cxx/encoding/tlv.hpp>
-#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/encoding/block-helpers.hpp>
#include <ndn-cxx/interest.hpp>
-#include <ndn-cxx/lp/nack.hpp>
#include <ndn-cxx/name.hpp>
#include <ndn-cxx/security/certificate.hpp>
-#include <ndn-cxx/security/key-chain.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>
#include <boost/assert.hpp>
#include <boost/noncopyable.hpp>
#include <boost/property_tree/ptree.hpp>
-namespace ndn {
namespace ndncert {
+using ndn::Block;
+using ndn::Data;
+using ndn::Interest;
+using ndn::Name;
+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;
+
namespace tlv {
enum : uint32_t {
@@ -127,6 +138,5 @@
operator<<(std::ostream& out, RequestType type);
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_DETAIL_NDNCERT_COMMON_HPP
diff --git a/src/detail/probe-encoder.cpp b/src/detail/probe-encoder.cpp
index 24471a7..bf51438 100644
--- a/src/detail/probe-encoder.cpp
+++ b/src/detail/probe-encoder.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -20,7 +20,6 @@
#include "detail/probe-encoder.hpp"
-namespace ndn {
namespace ndncert {
Block
@@ -28,8 +27,8 @@
{
Block content(ndn::tlv::ApplicationParameters);
for (const auto& items : parameters) {
- content.push_back(makeStringBlock(tlv::ParameterKey, items.first));
- content.push_back(makeStringBlock(tlv::ParameterValue, items.second));
+ content.push_back(ndn::makeStringBlock(tlv::ParameterKey, items.first));
+ content.push_back(ndn::makeStringBlock(tlv::ParameterValue, items.second));
}
content.encode();
return content;
@@ -51,14 +50,14 @@
Block
probetlv::encodeDataContent(const std::vector<Name>& identifiers, optional<size_t> maxSuffixLength,
- std::vector<std::shared_ptr<security::Certificate>> redirectionItems)
+ std::vector<std::shared_ptr<Certificate>> redirectionItems)
{
Block content(ndn::tlv::Content);
for (const auto& name : identifiers) {
Block item(tlv::ProbeResponse);
item.push_back(name.wireEncode());
if (maxSuffixLength) {
- item.push_back(makeNonNegativeIntegerBlock(tlv::MaxSuffixLength, *maxSuffixLength));
+ item.push_back(ndn::makeNonNegativeIntegerBlock(tlv::MaxSuffixLength, *maxSuffixLength));
}
content.push_back(item);
}
@@ -71,8 +70,8 @@
void
probetlv::decodeDataContent(const Block& block,
- std::vector<std::pair<Name, int>>& availableNames,
- std::vector<Name>& availableRedirection)
+ std::vector<std::pair<Name, int>>& availableNames,
+ std::vector<Name>& availableRedirection)
{
block.parse();
for (const auto& item : block.elements()) {
@@ -103,4 +102,3 @@
}
} // namespace ndncert
-} // namespace ndn
\ No newline at end of file
diff --git a/src/detail/probe-encoder.hpp b/src/detail/probe-encoder.hpp
index 58bcb44..6afe083 100644
--- a/src/detail/probe-encoder.hpp
+++ b/src/detail/probe-encoder.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,7 +23,6 @@
#include "detail/ndncert-common.hpp"
-namespace ndn {
namespace ndncert {
namespace probetlv {
@@ -39,14 +38,13 @@
Block
encodeDataContent(const std::vector<Name>& identifiers,
optional<size_t> maxSuffixLength = nullopt,
- std::vector<std::shared_ptr<security::Certificate>> redirectionItems =
- std::vector<std::shared_ptr<security::Certificate>>());
+ std::vector<std::shared_ptr<Certificate>> redirectionItems =
+ std::vector<std::shared_ptr<Certificate>>());
std::multimap<std::string, std::string>
decodeApplicationParameters(const Block& block);
} // namespace probetlv
} // namespace ndncert
-} // namespace ndn
-#endif // NDNCERT_DETAIL_PROBE_ENCODER_HPP
\ No newline at end of file
+#endif // NDNCERT_DETAIL_PROBE_ENCODER_HPP
diff --git a/src/detail/profile-storage.cpp b/src/detail/profile-storage.cpp
index 949309a..8ae2bb6 100644
--- a/src/detail/profile-storage.cpp
+++ b/src/detail/profile-storage.cpp
@@ -23,7 +23,6 @@
#include <boost/filesystem.hpp>
#include <boost/property_tree/json_parser.hpp>
-namespace ndn {
namespace ndncert {
namespace requester {
@@ -99,4 +98,3 @@
} // namespace requester
} // namespace ndncert
-} // namespace ndn
diff --git a/src/detail/profile-storage.hpp b/src/detail/profile-storage.hpp
index 5955f15..3df6407 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-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,7 +23,6 @@
#include "detail/ca-profile.hpp"
-namespace ndn {
namespace ndncert {
namespace requester {
@@ -69,6 +68,5 @@
} // namespace requester
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_DETAIL_PROFILE_STORAGE_HPP
diff --git a/src/detail/request-encoder.cpp b/src/detail/request-encoder.cpp
index 1801b63..30e2523 100644
--- a/src/detail/request-encoder.cpp
+++ b/src/detail/request-encoder.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -19,20 +19,21 @@
*/
#include "detail/request-encoder.hpp"
+
#include <ndn-cxx/security/transform/base64-encode.hpp>
#include <ndn-cxx/security/transform/buffer-source.hpp>
#include <ndn-cxx/security/transform/stream-sink.hpp>
-namespace ndn {
namespace ndncert {
Block
-requesttlv::encodeApplicationParameters(RequestType requestType, const std::vector <uint8_t>& ecdhPub,
- const security::Certificate& certRequest)
+requesttlv::encodeApplicationParameters(RequestType requestType,
+ const std::vector<uint8_t>& ecdhPub,
+ const Certificate& certRequest)
{
Block
request(ndn::tlv::ApplicationParameters);
- request.push_back(makeBinaryBlock(tlv::EcdhPub, ecdhPub.data(), ecdhPub.size()));
+ request.push_back(ndn::makeBinaryBlock(tlv::EcdhPub, ecdhPub.data(), ecdhPub.size()));
if (requestType == RequestType::NEW || requestType == RequestType::RENEW) {
request.push_back(makeNestedBlock(tlv::CertRequest, certRequest));
}
@@ -45,8 +46,8 @@
void
requesttlv::decodeApplicationParameters(const Block& payload, RequestType requestType,
- std::vector <uint8_t>& ecdhPub,
- shared_ptr <security::Certificate>& clientCert)
+ std::vector<uint8_t>& ecdhPub,
+ std::shared_ptr<Certificate>& clientCert)
{
payload.parse();
@@ -63,8 +64,7 @@
}
requestPayload.parse();
- security::Certificate cert = security::Certificate(requestPayload.get(ndn::tlv::Data));
- clientCert = std::make_shared<security::Certificate>(cert);
+ clientCert = std::make_shared<Certificate>(requestPayload.get(ndn::tlv::Data));
}
Block
@@ -73,11 +73,11 @@
const std::vector <std::string>& challenges)
{
Block response(ndn::tlv::Content);
- response.push_back(makeBinaryBlock(tlv::EcdhPub, ecdhKey.data(), ecdhKey.size()));
- response.push_back(makeBinaryBlock(tlv::Salt, salt.data(), salt.size()));
- response.push_back(makeBinaryBlock(tlv::RequestId, requestId.data(), requestId.size()));
+ response.push_back(ndn::makeBinaryBlock(tlv::EcdhPub, ecdhKey.data(), ecdhKey.size()));
+ response.push_back(ndn::makeBinaryBlock(tlv::Salt, salt.data(), salt.size()));
+ response.push_back(ndn::makeBinaryBlock(tlv::RequestId, requestId.data(), requestId.size()));
for (const auto& entry: challenges) {
- response.push_back(makeStringBlock(tlv::Challenge, entry));
+ response.push_back(ndn::makeStringBlock(tlv::Challenge, entry));
}
response.encode();
return response;
@@ -109,4 +109,3 @@
}
} // namespace ndncert
-} // namespace ndn
\ No newline at end of file
diff --git a/src/detail/request-encoder.hpp b/src/detail/request-encoder.hpp
index aff7c62..e94571e 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-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,17 +23,16 @@
#include "detail/ca-request-state.hpp"
-namespace ndn {
namespace ndncert {
namespace requesttlv {
Block
encodeApplicationParameters(RequestType requestType, const std::vector<uint8_t>& ecdhPub,
- const security::Certificate& certRequest);
+ const Certificate& certRequest);
void
decodeApplicationParameters(const Block& block, RequestType requestType, std::vector<uint8_t>& ecdhPub,
- shared_ptr<security::Certificate>& certRequest);
+ std::shared_ptr<Certificate>& certRequest);
Block
encodeDataContent(const std::vector<uint8_t>& ecdhKey, const std::array<uint8_t, 32>& salt,
@@ -45,6 +44,5 @@
} // namespace requesttlv
} // namespace ndncert
-} // namespace ndn
-#endif // NDNCERT_DETAIL_NEW_RENEW_REVOKE_ENCODER_HPP
\ No newline at end of file
+#endif // NDNCERT_DETAIL_REQUEST_ENCODER_HPP