Use nested namespace
Nested namespace is introduced in C++ 17. This saves nearly 50 lines.
This change also puts tests into a nested namespace, which saves
unnecessary using directives.
Signed-off-by: Nan Zhou <nanzhoumails@gmail.com>
Change-Id: I7c3e38588fd5c2cbd83ac13ee24327318e8c06a4
diff --git a/argument.cpp b/argument.cpp
index 35f33e3..389fa54 100644
--- a/argument.cpp
+++ b/argument.cpp
@@ -19,11 +19,7 @@
#include <iostream>
#include <iterator>
-namespace phosphor
-{
-namespace certs
-{
-namespace util
+namespace phosphor::certs::util
{
ArgumentParser::ArgumentParser(int argc, char** argv)
@@ -91,6 +87,4 @@
const std::string ArgumentParser::true_string = "true";
const std::string ArgumentParser::empty_string = "";
-} // namespace util
-} // namespace certs
-} // namespace phosphor
+} // namespace phosphor::certs::util
diff --git a/argument.hpp b/argument.hpp
index af5ac46..e67a877 100644
--- a/argument.hpp
+++ b/argument.hpp
@@ -5,11 +5,7 @@
#include <map>
#include <string>
-namespace phosphor
-{
-namespace certs
-{
-namespace util
+namespace phosphor::certs::util
{
/**
@@ -40,6 +36,4 @@
static const char* optionstr;
};
-} // namespace util
-} // namespace certs
-} // namespace phosphor
+} // namespace phosphor::certs::util
diff --git a/bmc-vmi-ca/ca_cert_entry.cpp b/bmc-vmi-ca/ca_cert_entry.cpp
index 94c0a25..f4d7b2e 100644
--- a/bmc-vmi-ca/ca_cert_entry.cpp
+++ b/bmc-vmi-ca/ca_cert_entry.cpp
@@ -4,9 +4,7 @@
#include "ca_certs_manager.hpp"
-namespace ca
-{
-namespace cert
+namespace ca::cert
{
void Entry::delete_()
@@ -14,5 +12,4 @@
// Remove entry D-bus object
manager.erase(id);
}
-} // namespace cert
-} // namespace ca
+} // namespace ca::cert
diff --git a/bmc-vmi-ca/ca_certs_manager.cpp b/bmc-vmi-ca/ca_certs_manager.cpp
index 3b11a53..0f4e908 100644
--- a/bmc-vmi-ca/ca_certs_manager.cpp
+++ b/bmc-vmi-ca/ca_certs_manager.cpp
@@ -9,9 +9,7 @@
#include <phosphor-logging/log.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
-namespace ca
-{
-namespace cert
+namespace ca::cert
{
static constexpr auto maxCertSize = 4096;
namespace fs = std::filesystem;
@@ -66,5 +64,4 @@
}
}
-} // namespace cert
-} // namespace ca
+} // namespace ca::cert
diff --git a/bmc-vmi-ca/ca_certs_manager.hpp b/bmc-vmi-ca/ca_certs_manager.hpp
index a1db918..21088b6 100644
--- a/bmc-vmi-ca/ca_certs_manager.hpp
+++ b/bmc-vmi-ca/ca_certs_manager.hpp
@@ -8,9 +8,7 @@
#include <sdbusplus/server/object.hpp>
#include <sdeventplus/source/event.hpp>
-namespace ca
-{
-namespace cert
+namespace ca::cert
{
class CACertMgr;
@@ -74,5 +72,4 @@
uint32_t lastEntryId;
};
-} // namespace cert
-} // namespace ca
+} // namespace ca::cert
diff --git a/certificate.cpp b/certificate.cpp
index 88ff65e..de7a455 100644
--- a/certificate.cpp
+++ b/certificate.cpp
@@ -17,9 +17,7 @@
#include <xyz/openbmc_project/Certs/error.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
-namespace phosphor
-{
-namespace certs
+namespace phosphor::certs
{
// RAII support for openSSL functions.
using BIO_MEM_Ptr = std::unique_ptr<BIO, decltype(&::BIO_free)>;
@@ -727,5 +725,4 @@
{
manager.deleteCertificate(this);
}
-} // namespace certs
-} // namespace phosphor
+} // namespace phosphor::certs
diff --git a/certificate.hpp b/certificate.hpp
index 3ea78a5..ce2a737 100644
--- a/certificate.hpp
+++ b/certificate.hpp
@@ -10,9 +10,7 @@
#include <xyz/openbmc_project/Certs/Replace/server.hpp>
#include <xyz/openbmc_project/Object/Delete/server.hpp>
-namespace phosphor
-{
-namespace certs
+namespace phosphor::certs
{
using DeleteIface = sdbusplus::xyz::openbmc_project::Object::server::Delete;
using CertificateIface =
@@ -254,5 +252,4 @@
Manager& manager;
};
-} // namespace certs
-} // namespace phosphor
+} // namespace phosphor::certs
diff --git a/certs_manager.cpp b/certs_manager.cpp
index 6aca6af..ed6e375 100644
--- a/certs_manager.cpp
+++ b/certs_manager.cpp
@@ -9,9 +9,7 @@
#include <xyz/openbmc_project/Certs/error.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
-namespace phosphor
-{
-namespace certs
+namespace phosphor::certs
{
using InternalFailure =
sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
@@ -908,5 +906,4 @@
}
}
-} // namespace certs
-} // namespace phosphor
+} // namespace phosphor::certs
diff --git a/certs_manager.hpp b/certs_manager.hpp
index 122ce44..2be0759 100644
--- a/certs_manager.hpp
+++ b/certs_manager.hpp
@@ -11,9 +11,7 @@
#include <xyz/openbmc_project/Certs/Install/server.hpp>
#include <xyz/openbmc_project/Collection/DeleteAll/server.hpp>
-namespace phosphor
-{
-namespace certs
+namespace phosphor::certs
{
using Install = sdbusplus::xyz::openbmc_project::Certs::server::Install;
using DeleteAll =
@@ -306,5 +304,4 @@
/** @brief Certificate ID pool */
uint64_t certIdCounter = 1;
};
-} // namespace certs
-} // namespace phosphor
+} // namespace phosphor::certs
diff --git a/csr.cpp b/csr.cpp
index cf74f53..1ea3991 100644
--- a/csr.cpp
+++ b/csr.cpp
@@ -10,11 +10,8 @@
#include <xyz/openbmc_project/Certs/error.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
-namespace phosphor
+namespace phosphor::certs
{
-namespace certs
-{
-
using X509_REQ_Ptr = std::unique_ptr<X509_REQ, decltype(&::X509_REQ_free)>;
using BIO_Ptr = std::unique_ptr<BIO, decltype(&::BIO_free_all)>;
using InternalFailure =
@@ -77,5 +74,4 @@
return pem;
}
-} // namespace certs
-} // namespace phosphor
+} // namespace phosphor::certs
diff --git a/csr.hpp b/csr.hpp
index c6b4221..2d82739 100644
--- a/csr.hpp
+++ b/csr.hpp
@@ -1,9 +1,7 @@
#pragma once
#include <xyz/openbmc_project/Certs/CSR/server.hpp>
-namespace phosphor
-{
-namespace certs
+namespace phosphor::certs
{
using CSRRead = sdbusplus::xyz::openbmc_project::Certs::server::CSR;
using CSRIface = sdbusplus::server::object::object<CSRRead>;
@@ -54,5 +52,4 @@
/** @brief Status of GenerateCSR request */
Status csrStatus;
};
-} // namespace certs
-} // namespace phosphor
+} // namespace phosphor::certs
diff --git a/test/ca_certs_manager_test.cpp b/test/ca_certs_manager_test.cpp
index 17c8589..5bdad56 100644
--- a/test/ca_certs_manager_test.cpp
+++ b/test/ca_certs_manager_test.cpp
@@ -10,9 +10,12 @@
#include <gtest/gtest.h>
+namespace ca::cert
+{
+namespace
+{
using InvalidArgument =
sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument;
-using namespace ca::cert;
class MockCACertMgr : public CACertMgr
{
@@ -123,3 +126,5 @@
manager.erase(std::stoi(id));
EXPECT_TRUE(manager.getNumOfEntries() == 0);
}
+} // namespace
+} // namespace ca::cert
diff --git a/test/certs_manager_test.cpp b/test/certs_manager_test.cpp
index 38c563a..1131df1 100644
--- a/test/certs_manager_test.cpp
+++ b/test/certs_manager_test.cpp
@@ -20,12 +20,16 @@
#include <xyz/openbmc_project/Common/error.hpp>
#include <gtest/gtest.h>
+
+namespace phosphor::certs
+{
+namespace
+{
namespace fs = std::filesystem;
using InternalFailure =
sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
using InvalidCertificate =
sdbusplus::xyz::openbmc_project::Certs::Error::InvalidCertificate;
-using namespace phosphor::certs;
/**
* Class to generate certificate file and test verification of certificate file
@@ -1380,3 +1384,5 @@
std::move(installPath));
EXPECT_TRUE(fs::exists(rsaPrivateKeyFilePath));
}
+} // namespace
+} // namespace phosphor::certs
diff --git a/watch.cpp b/watch.cpp
index 32853fa..71acb15 100644
--- a/watch.cpp
+++ b/watch.cpp
@@ -8,9 +8,8 @@
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
-namespace phosphor
-{
-namespace certs
+
+namespace phosphor::certs
{
using namespace phosphor::logging;
namespace fs = std::filesystem;
@@ -107,5 +106,4 @@
}
}
-} // namespace certs
-} // namespace phosphor
+} // namespace phosphor::certs
diff --git a/watch.hpp b/watch.hpp
index d98c322..2cf34aa 100644
--- a/watch.hpp
+++ b/watch.hpp
@@ -5,9 +5,7 @@
#include <sdeventplus/source/io.hpp>
#include <string>
-namespace phosphor
-{
-namespace certs
+namespace phosphor::certs
{
/** @class Watch
*
@@ -69,5 +67,4 @@
/** @brief Certificate file with path */
std::string certFile;
};
-} // namespace certs
-} // namespace phosphor
+} // namespace phosphor::certs