clang-format: re-format for clang-18
clang-format-18 isn't compatible with the clang-format-17 output, so we
need to reformat the code with the latest version. The way clang-18
handles lambda formatting also changed, so we have made changes to the
organization default style format to better handle lambda formatting.
See I5e08687e696dd240402a2780158664b7113def0e for updated style.
See Iea0776aaa7edd483fa395e23de25ebf5a6288f71 for clang-18 enablement.
Change-Id: Ic1ad64722b2368169dfb0e62c37f7f3c1ff20fe8
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
diff --git a/.clang-format b/.clang-format
index d43e884..28e3328 100644
--- a/.clang-format
+++ b/.clang-format
@@ -87,7 +87,7 @@
IndentWrappedFunctionNames: true
InsertNewlineAtEOF: true
KeepEmptyLinesAtTheStartOfBlocks: false
-LambdaBodyIndentation: OuterScope
+LambdaBodyIndentation: Signature
LineEnding: LF
MacroBlockBegin: ''
MacroBlockEnd: ''
@@ -98,13 +98,14 @@
ObjCSpaceBeforeProtocolList: true
PackConstructorInitializers: BinPack
PenaltyBreakAssignment: 25
-PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakBeforeFirstCallParameter: 50
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
+PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
-PenaltyIndentedWhitespace: 0
+PenaltyIndentedWhitespace: 1
PointerAlignment: Left
QualifierAlignment: Left
ReferenceAlignment: Left
diff --git a/bmc-vmi-ca/ca_certs_manager.hpp b/bmc-vmi-ca/ca_certs_manager.hpp
index 72e1ba4..c49cab3 100644
--- a/bmc-vmi-ca/ca_certs_manager.hpp
+++ b/bmc-vmi-ca/ca_certs_manager.hpp
@@ -39,7 +39,7 @@
*/
CACertMgr(sdbusplus::bus_t& bus, const char* path) :
internal::ManagerInterface(bus, path), bus(bus), objectPath(path),
- lastEntryId(0){};
+ lastEntryId(0) {};
/** @brief This method provides signing authority functionality.
It signs the certificate and creates the CSR request entry Dbus
diff --git a/certificate.cpp b/certificate.cpp
index 047482d..428b252 100644
--- a/certificate.cpp
+++ b/certificate.cpp
@@ -122,12 +122,12 @@
{
std::ifstream inputCertFileStream;
std::ofstream outputCertFileStream;
- inputCertFileStream.exceptions(std::ifstream::failbit |
- std::ifstream::badbit |
- std::ifstream::eofbit);
- outputCertFileStream.exceptions(std::ofstream::failbit |
- std::ofstream::badbit |
- std::ofstream::eofbit);
+ inputCertFileStream.exceptions(
+ std::ifstream::failbit | std::ifstream::badbit |
+ std::ifstream::eofbit);
+ outputCertFileStream.exceptions(
+ std::ofstream::failbit | std::ofstream::badbit |
+ std::ofstream::eofbit);
try
{
inputCertFileStream.open(certSrcFilePath);
@@ -590,12 +590,12 @@
std::ifstream privKeyFileStream;
std::ofstream certFileStream;
- privKeyFileStream.exceptions(std::ifstream::failbit |
- std::ifstream::badbit |
- std::ifstream::eofbit);
- certFileStream.exceptions(std::ofstream::failbit |
- std::ofstream::badbit |
- std::ofstream::eofbit);
+ privKeyFileStream.exceptions(
+ std::ifstream::failbit | std::ifstream::badbit |
+ std::ifstream::eofbit);
+ certFileStream.exceptions(
+ std::ofstream::failbit | std::ofstream::badbit |
+ std::ofstream::eofbit);
try
{
privKeyFileStream.open(privateKeyFile);
diff --git a/certs_manager.cpp b/certs_manager.cpp
index b4e396f..9d828c1 100644
--- a/certs_manager.cpp
+++ b/certs_manager.cpp
@@ -131,9 +131,9 @@
Manager::Manager(sdbusplus::bus_t& bus, sdeventplus::Event& event,
const char* path, CertificateType type,
const std::string& unit, const std::string& installPath) :
- internal::ManagerInterface(bus, path),
- bus(bus), event(event), objectPath(path), certType(type),
- unitToRestart(std::move(unit)), certInstallPath(std::move(installPath)),
+ internal::ManagerInterface(bus, path), bus(bus), event(event),
+ objectPath(path), certType(type), unitToRestart(std::move(unit)),
+ certInstallPath(std::move(installPath)),
certParentInstallPath(fs::path(certInstallPath).parent_path())
{
try
@@ -184,8 +184,8 @@
if (certType != CertificateType::authority)
{
// watch for certificate file create/replace
- certWatchPtr = std::make_unique<Watch>(event, certInstallPath,
- [this]() {
+ certWatchPtr = std::make_unique<
+ Watch>(event, certInstallPath, [this]() {
try
{
// if certificate file existing update it
@@ -284,9 +284,9 @@
{
if (certType != CertificateType::authority)
{
- elog<NotAllowed>(
- NotAllowedReason("The InstallAll interface is only allowed for "
- "Authority certificates"));
+ elog<NotAllowed>(NotAllowedReason(
+ "The InstallAll interface is only allowed for "
+ "Authority certificates"));
}
if (!installedCerts.empty())
@@ -311,8 +311,8 @@
lg2::info("Starts authority list install");
fs::path authorityStore(certInstallPath);
- fs::path authoritiesListFile = authorityStore /
- defaultAuthoritiesListFileName;
+ fs::path authoritiesListFile =
+ authorityStore / defaultAuthoritiesListFileName;
// Atomically install all the certificates
fs::path tempPath = Certificate::generateUniqueFilePath(authorityStore);
@@ -325,8 +325,8 @@
X509StorePtr x509Store = getX509Store(sourceFile);
for (const auto& authority : authorities)
{
- std::string certObjectPath = objectPath + '/' +
- std::to_string(tempCertIdCounter);
+ std::string certObjectPath =
+ objectPath + '/' + std::to_string(tempCertIdCounter);
tempCertificates.emplace_back(std::make_unique<Certificate>(
bus, certObjectPath, certType, tempPath, *x509Store, authority,
certWatchPtr.get(), *this, /*restore=*/false));
@@ -349,8 +349,8 @@
for (const auto& cert : installedCerts)
{
cert->setCertInstallPath(certInstallPath);
- cert->setCertFilePath(certInstallPath /
- fs::path(cert->getCertFilePath()).filename());
+ cert->setCertFilePath(
+ certInstallPath / fs::path(cert->getCertFilePath()).filename());
cert->storageUpdate();
}
// Remove the temporary folder
@@ -387,8 +387,8 @@
// If the authorities list exists, delete it as well
if (certType == CertificateType::authority)
{
- if (fs::path authoritiesList = fs::path(certInstallPath) /
- defaultAuthoritiesListFileName;
+ if (fs::path authoritiesList =
+ fs::path(certInstallPath) / defaultAuthoritiesListFileName;
fs::exists(authoritiesList))
{
fs::remove(authoritiesList);
@@ -404,8 +404,8 @@
const std::vector<std::unique_ptr<Certificate>>::iterator& certIt =
std::find_if(installedCerts.begin(), installedCerts.end(),
[certificate](const std::unique_ptr<Certificate>& cert) {
- return (cert.get() == certificate);
- });
+ return (cert.get() == certificate);
+ });
if (certIt != installedCerts.end())
{
installedCerts.erase(certIt);
@@ -456,12 +456,12 @@
{
try
{
- generateCSRHelper(alternativeNames, challengePassword, city,
- commonName, contactPerson, country, email,
- givenName, initials, keyBitLength, keyCurveId,
- keyPairAlgorithm, keyUsage, organization,
- organizationalUnit, state, surname,
- unstructuredName);
+ generateCSRHelper(
+ alternativeNames, challengePassword, city, commonName,
+ contactPerson, country, email, givenName, initials,
+ keyBitLength, keyCurveId, keyPairAlgorithm, keyUsage,
+ organization, organizationalUnit, state, surname,
+ unstructuredName);
exit(EXIT_SUCCESS);
}
catch (const InternalFailure& e)
@@ -482,18 +482,18 @@
else
{
using namespace sdeventplus::source;
- Child::Callback callback = [this](Child& eventSource,
- const siginfo_t* si) {
- eventSource.set_enabled(Enabled::On);
- if (si->si_status != 0)
- {
- this->createCSRObject(Status::failure);
- }
- else
- {
- this->createCSRObject(Status::success);
- }
- };
+ Child::Callback callback =
+ [this](Child& eventSource, const siginfo_t* si) {
+ eventSource.set_enabled(Enabled::On);
+ if (si->si_status != 0)
+ {
+ this->createCSRObject(Status::failure);
+ }
+ else
+ {
+ this->createCSRObject(Status::success);
+ }
+ };
try
{
sigset_t ss;
@@ -850,8 +850,8 @@
lg2::error("Error occurred creating private key file");
elog<InternalFailure>();
}
- int ret = PEM_write_PrivateKey(fp, pKey.get(), nullptr, nullptr, 0, 0,
- nullptr);
+ int ret =
+ PEM_write_PrivateKey(fp, pKey.get(), nullptr, nullptr, 0, 0, nullptr);
std::fclose(fp);
if (ret == 0)
{
@@ -940,8 +940,8 @@
}
// If the authorities list exists, recover from it and return
- if (fs::path authoritiesListFilePath = fs::path(certInstallPath) /
- defaultAuthoritiesListFileName;
+ if (fs::path authoritiesListFilePath =
+ fs::path(certInstallPath) / defaultAuthoritiesListFileName;
fs::exists(authoritiesListFilePath))
{
// remove all other files and directories
@@ -1004,8 +1004,8 @@
void Manager::createRSAPrivateKeyFile()
{
- fs::path rsaPrivateKeyFileName = certParentInstallPath /
- defaultRSAPrivateKeyFileName;
+ fs::path rsaPrivateKeyFileName =
+ certParentInstallPath / defaultRSAPrivateKeyFileName;
try
{
@@ -1034,8 +1034,8 @@
Argument::ARGUMENT_NAME("KEYBITLENGTH"),
Argument::ARGUMENT_VALUE(std::to_string(keyBitLength).c_str()));
}
- fs::path rsaPrivateKeyFileName = certParentInstallPath /
- defaultRSAPrivateKeyFileName;
+ fs::path rsaPrivateKeyFileName =
+ certParentInstallPath / defaultRSAPrivateKeyFileName;
FILE* privateKeyFile = std::fopen(rsaPrivateKeyFileName.c_str(), "r");
if (!privateKeyFile)
@@ -1124,8 +1124,8 @@
if (std::any_of(
installedCerts.begin(), installedCerts.end(),
[&filePath, certToDrop](const std::unique_ptr<Certificate>& cert) {
- return cert.get() != certToDrop && cert->isSame(filePath);
- }))
+ return cert.get() != certToDrop && cert->isSame(filePath);
+ }))
{
return false;
}
diff --git a/certs_manager.hpp b/certs_manager.hpp
index 2c35fa7..4ce49d2 100644
--- a/certs_manager.hpp
+++ b/certs_manager.hpp
@@ -208,17 +208,15 @@
virtual void reloadOrReset(const std::string& unit);
private:
- void generateCSRHelper(std::vector<std::string> alternativeNames,
- std::string challengePassword, std::string city,
- std::string commonName, std::string contactPerson,
- std::string country, std::string email,
- std::string givenName, std::string initials,
- int64_t keyBitLength, std::string keyCurveId,
- std::string keyPairAlgorithm,
- std::vector<std::string> keyUsage,
- std::string organization,
- std::string organizationalUnit, std::string state,
- std::string surname, std::string unstructuredName);
+ void generateCSRHelper(
+ std::vector<std::string> alternativeNames,
+ std::string challengePassword, std::string city, std::string commonName,
+ std::string contactPerson, std::string country, std::string email,
+ std::string givenName, std::string initials, int64_t keyBitLength,
+ std::string keyCurveId, std::string keyPairAlgorithm,
+ std::vector<std::string> keyUsage, std::string organization,
+ std::string organizationalUnit, std::string state, std::string surname,
+ std::string unstructuredName);
/** @brief Generate RSA Key pair and get private key from key pair
* @param[in] keyBitLength - KeyBit length.
diff --git a/test/certs_manager_test.cpp b/test/certs_manager_test.cpp
index c44f7ec..08a7bb5 100644
--- a/test/certs_manager_test.cpp
+++ b/test/certs_manager_test.cpp
@@ -214,26 +214,22 @@
{
public:
MainApp(phosphor::certs::Manager* manager,
- phosphor::certs::CSR* csr = nullptr) :
- manager(manager),
- csr_(csr)
+ phosphor::certs::CSR* csr = nullptr) : manager(manager), csr_(csr)
{}
void install(std::string& path)
{
manager->install(path);
}
- std::string generateCSR(std::vector<std::string> alternativeNames,
- std::string challengePassword, std::string city,
- std::string commonName, std::string contactPerson,
- std::string country, std::string email,
- std::string givenName, std::string initials,
- int64_t keyBitLength, std::string keyCurveId,
- std::string keyPairAlgorithm,
- std::vector<std::string> keyUsage,
- std::string organization,
- std::string organizationalUnit, std::string state,
- std::string surname, std::string unstructuredName)
+ std::string generateCSR(
+ std::vector<std::string> alternativeNames,
+ std::string challengePassword, std::string city, std::string commonName,
+ std::string contactPerson, std::string country, std::string email,
+ std::string givenName, std::string initials, int64_t keyBitLength,
+ std::string keyCurveId, std::string keyPairAlgorithm,
+ std::vector<std::string> keyUsage, std::string organization,
+ std::string organizationalUnit, std::string state, std::string surname,
+ std::string unstructuredName)
{
return (manager->generateCSR(
alternativeNames, challengePassword, city, commonName,
@@ -341,8 +337,8 @@
EXPECT_EQ(certs.front()->subject(), "O=openbmc-project.xyz,CN=localhost");
EXPECT_EQ(certs.front()->issuer(), "O=openbmc-project.xyz,CN=localhost");
- std::string verifyPath = verifyDir + "/" +
- getCertSubjectNameHash(certificateFile) + ".0";
+ std::string verifyPath =
+ verifyDir + "/" + getCertSubjectNameHash(certificateFile) + ".0";
// Check that certificate has been created at installation directory
EXPECT_FALSE(fs::is_empty(verifyDir));
@@ -381,8 +377,8 @@
EXPECT_EQ(certs.front()->validNotBefore(), 0);
EXPECT_EQ(certs.front()->validNotAfter(), 253402300799ULL);
- std::string verifyPath = verifyDir + "/" +
- getCertSubjectNameHash(certificateFile) + ".0";
+ std::string verifyPath =
+ verifyDir + "/" + getCertSubjectNameHash(certificateFile) + ".0";
// Check that certificate has been created at installation directory
EXPECT_FALSE(fs::is_empty(verifyDir));
@@ -419,8 +415,8 @@
EXPECT_FALSE(certs.empty());
// Check that certificate has been created at installation directory
- std::string verifyPath = verifyDir + "/" +
- getCertSubjectNameHash(certificateFile) + ".0";
+ std::string verifyPath =
+ verifyDir + "/" + getCertSubjectNameHash(certificateFile) + ".0";
EXPECT_FALSE(fs::is_empty(verifyDir));
EXPECT_TRUE(fs::exists(verifyPath));
@@ -476,8 +472,8 @@
EXPECT_FALSE(certs.empty());
// Check that certificate has been created at installation directory
- std::string verifyPath0 = verifyDir + "/" +
- getCertSubjectNameHash(certificateFile) + ".0";
+ std::string verifyPath0 =
+ verifyDir + "/" + getCertSubjectNameHash(certificateFile) + ".0";
EXPECT_FALSE(fs::is_empty(verifyDir));
EXPECT_TRUE(fs::exists(verifyPath0));
@@ -494,8 +490,8 @@
EXPECT_EQ(certs.size(), 2);
// Check that certificate has been created at installation directory
- std::string verifyPath1 = verifyDir + "/" +
- getCertSubjectNameHash(certificateFile) + ".1";
+ std::string verifyPath1 =
+ verifyDir + "/" + getCertSubjectNameHash(certificateFile) + ".1";
EXPECT_TRUE(fs::exists(verifyPath1));
// Check that installed cert is identical to input one
@@ -544,8 +540,8 @@
EXPECT_EQ(certs.size(), i + 1);
// Check that certificate has been created at installation directory
- std::string verifyPath = verifyDir + "/" +
- getCertSubjectNameHash(certificateFile) + ".0";
+ std::string verifyPath =
+ verifyDir + "/" + getCertSubjectNameHash(certificateFile) + ".0";
EXPECT_FALSE(fs::is_empty(verifyDir));
EXPECT_TRUE(fs::exists(verifyPath));
@@ -700,8 +696,8 @@
// Certificate successfully installed
EXPECT_FALSE(certs.empty());
- std::string verifyPath = verifyDir + "/" +
- getCertSubjectNameHash(certificateFile) + ".0";
+ std::string verifyPath =
+ verifyDir + "/" + getCertSubjectNameHash(certificateFile) + ".0";
// Check that certificate has been created at installation directory
EXPECT_FALSE(fs::is_empty(verifyDir));
@@ -1520,12 +1516,12 @@
ASSERT_NO_THROW({
std::ifstream inputCertFileStream;
std::ofstream outputCertFileStream;
- inputCertFileStream.exceptions(std::ifstream::failbit |
- std::ifstream::badbit |
- std::ifstream::eofbit);
- outputCertFileStream.exceptions(std::ofstream::failbit |
- std::ofstream::badbit |
- std::ofstream::eofbit);
+ inputCertFileStream.exceptions(
+ std::ifstream::failbit | std::ifstream::badbit |
+ std::ifstream::eofbit);
+ outputCertFileStream.exceptions(
+ std::ofstream::failbit | std::ofstream::badbit |
+ std::ofstream::eofbit);
inputCertFileStream.open(from);
outputCertFileStream.open(to, std::ios::app);
outputCertFileStream << inputCertFileStream.rdbuf() << std::flush;
@@ -1540,9 +1536,9 @@
{
ASSERT_NO_THROW({
std::ofstream outputCertFileStream;
- outputCertFileStream.exceptions(std::ofstream::failbit |
- std::ofstream::badbit |
- std::ofstream::eofbit);
+ outputCertFileStream.exceptions(
+ std::ofstream::failbit | std::ofstream::badbit |
+ std::ofstream::eofbit);
outputCertFileStream.open(to, std::ios::out);
outputCertFileStream << from << std::flush;
outputCertFileStream.close();
@@ -1579,9 +1575,9 @@
{
ASSERT_NO_THROW({
std::ifstream inputCertFileStream;
- inputCertFileStream.exceptions(std::ifstream::failbit |
- std::ifstream::badbit |
- std::ifstream::eofbit);
+ inputCertFileStream.exceptions(
+ std::ifstream::failbit | std::ifstream::badbit |
+ std::ifstream::eofbit);
inputCertFileStream.open(path);
std::stringstream read;
read << inputCertFileStream.rdbuf();
@@ -1651,8 +1647,8 @@
ASSERT_EQ(manager.getCertificates().size(), maxNumAuthorityCertificates);
// Check attributes and alias
- std::unordered_set<std::string> expectedFiles = {authoritiesListFolder /
- "trust_bundle"};
+ std::unordered_set<std::string> expectedFiles = {
+ authoritiesListFolder / "trust_bundle"};
std::vector<std::unique_ptr<Certificate>>& certs =
manager.getCertificates();
for (size_t i = 0; i < certs.size(); ++i)
@@ -1660,8 +1656,8 @@
std::string name = "root_" + std::to_string(i);
EXPECT_EQ(certs[i]->subject(), "O=openbmc-project.xyz,CN=" + name);
EXPECT_EQ(certs[i]->issuer(), "O=openbmc-project.xyz,CN=" + name);
- std::string symbolLink = authoritiesListFolder /
- (certs[i]->getCertId().substr(0, 8) + ".0");
+ std::string symbolLink =
+ authoritiesListFolder / (certs[i]->getCertId().substr(0, 8) + ".0");
expectedFiles.insert(symbolLink);
expectedFiles.insert(certs[i]->getCertFilePath());
ASSERT_TRUE(fs::exists(symbolLink));
diff --git a/watch.cpp b/watch.cpp
index e785265..933e5ab 100644
--- a/watch.cpp
+++ b/watch.cpp
@@ -75,26 +75,26 @@
ioPtr = std::make_unique<sdeventplus::source::IO>(
event, fd, EPOLLIN, [this](sdeventplus::source::IO&, int fd, uint32_t) {
- constexpr int size = sizeof(struct inotify_event) + NAME_MAX + 1;
- std::array<char, size> buffer{};
- int length = read(fd, buffer.data(), buffer.size());
- if (length >= static_cast<int>(sizeof(struct inotify_event)))
- {
- struct inotify_event* notifyEvent =
- reinterpret_cast<struct inotify_event*>(&buffer[0]);
- if (notifyEvent->len)
+ constexpr int size = sizeof(struct inotify_event) + NAME_MAX + 1;
+ std::array<char, size> buffer{};
+ int length = read(fd, buffer.data(), buffer.size());
+ if (length >= static_cast<int>(sizeof(struct inotify_event)))
{
- if (watchFile == notifyEvent->name)
+ struct inotify_event* notifyEvent =
+ reinterpret_cast<struct inotify_event*>(&buffer[0]);
+ if (notifyEvent->len)
{
- callback();
+ if (watchFile == notifyEvent->name)
+ {
+ callback();
+ }
}
}
- }
- else
- {
- lg2::error("Failed to read inotify event");
- }
- });
+ else
+ {
+ lg2::error("Failed to read inotify event");
+ }
+ });
}
void Watch::stopWatch()