Replace std::bind with lambda expressions
This will help to reduce runtime overhead.
Change-Id: Iccdf249e78535423d9e5b360d081d2c4b2e42ffc
Signed-off-by: Jayanth Othayoth <ojayanth@in.ibm.com>
diff --git a/certs_manager.cpp b/certs_manager.cpp
index 8f36782..7ff4ca3 100644
--- a/certs_manager.cpp
+++ b/certs_manager.cpp
@@ -8,11 +8,7 @@
#include <openssl/x509v3.h>
#include <experimental/filesystem>
-#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/log.hpp>
#include <sdbusplus/bus.hpp>
-#include <xyz/openbmc_project/Certs/Install/error.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
namespace phosphor
@@ -28,12 +24,8 @@
using EVP_PKEY_Ptr = std::unique_ptr<EVP_PKEY, decltype(&::EVP_PKEY_free)>;
namespace fs = std::experimental::filesystem;
-using namespace phosphor::logging;
using InternalFailure =
sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
-using InvalidCertificate =
- sdbusplus::xyz::openbmc_project::Certs::Install::Error::InvalidCertificate;
-using Reason = xyz::openbmc_project::Certs::Install::InvalidCertificate::REASON;
// Trust chain related errors.`
#define TRUST_CHAIN_ERR(errnum) \
((errnum == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT) || \
@@ -77,29 +69,6 @@
}
}
-void Manager::serverInstallHelper(const std::string& filePath)
-{
- if (!compareKeys(filePath))
- {
- elog<InvalidCertificate>(
- Reason("Private key does not match the Certificate"));
- }
-}
-
-void Manager::clientInstallHelper(const std::string& filePath)
-{
- if (!compareKeys(filePath))
- {
- elog<InvalidCertificate>(
- Reason("Private key does not match the Certificate"));
- }
-}
-
-void Manager::authorityInstallHelper(const std::string& filePath)
-{
- // No additional steps required now.
-}
-
void Manager::reloadOrReset(const std::string& unit)
{
constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1";
diff --git a/certs_manager.hpp b/certs_manager.hpp
index 1ca4f1a..252864f 100644
--- a/certs_manager.hpp
+++ b/certs_manager.hpp
@@ -2,9 +2,12 @@
#include <openssl/x509.h>
#include <cstring>
+#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/elog.hpp>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/server/object.hpp>
#include <unordered_map>
+#include <xyz/openbmc_project/Certs/Install/error.hpp>
#include <xyz/openbmc_project/Certs/Install/server.hpp>
#include <xyz/openbmc_project/Object/Delete/server.hpp>
@@ -26,6 +29,11 @@
using InstallFunc = std::function<void(const std::string&)>;
using InputType = std::string;
+using namespace phosphor::logging;
+using InvalidCertificate =
+ sdbusplus::xyz::openbmc_project::Certs::Install::Error::InvalidCertificate;
+using Reason = xyz::openbmc_project::Certs::Install::InvalidCertificate::REASON;
+
// for placeholders
using namespace std::placeholders;
@@ -62,12 +70,17 @@
bus(bus), path(path), type(type), unit(std::move(unit)),
certPath(std::move(certPath))
{
- typeFuncMap[SERVER] =
- std::bind(&phosphor::certs::Manager::serverInstallHelper, this, _1);
- typeFuncMap[CLIENT] =
- std::bind(&phosphor::certs::Manager::clientInstallHelper, this, _1);
- typeFuncMap[AUTHORITY] = std::bind(
- &phosphor::certs::Manager::authorityInstallHelper, this, _1);
+ auto installHelper = [this](const auto& filePath) {
+ if (!compareKeys(filePath))
+ {
+ elog<InvalidCertificate>(
+ Reason("Private key does not match the Certificate"));
+ };
+ };
+
+ typeFuncMap[SERVER] = installHelper;
+ typeFuncMap[CLIENT] = installHelper;
+ typeFuncMap[AUTHORITY] = [](auto filePath) {};
}
/** @brief Implementation for Install
@@ -84,21 +97,6 @@
void delete_() override;
private:
- /** @brief Client certificate Installation helper function
- * @param[in] path - Certificate key file path.
- */
- virtual void clientInstallHelper(const std::string& filePath);
-
- /** @brief Server certificate Installation helper function
- * @param[in] path - Certificate key file path.
- */
- virtual void serverInstallHelper(const std::string& filePath);
-
- /** @brief Authority certificate Installation helper function
- * @param[in] path - Certificate key file path.
- */
- virtual void authorityInstallHelper(const std::string& filePath);
-
/** @brief systemd unit reload or reset helper function
* Reload if the unit supports it and use a restart otherwise.
* @param[in] unit - service need to reload.