Add get() function to CryptHandle class
This commit modifies the CryptHandle class so that the crypt_device
struct is managed internally. This way, the caller does not need to
provide it's own crypt_device pointer. The caller can use the new get()
function when it needs access to the crypt_device struct.
Signed-off-by: John Wedig <johnwedig@google.com>
Change-Id: I82c2f96d74cc2714de5a656432cbaa2f6ee1244a
diff --git a/src/estoraged.cpp b/src/estoraged.cpp
index 4e64ca6..18e4248 100644
--- a/src/estoraged.cpp
+++ b/src/estoraged.cpp
@@ -29,17 +29,16 @@
std::string msg = "OpenBMC.0.1.DriveFormat";
lg2::info("Starting format", "REDFISH_MESSAGE_ID", msg);
- struct crypt_device* cryptDev;
- CryptHandle cryptHandle(&cryptDev, devPath.c_str());
- if (*cryptHandle.handle == nullptr)
+ CryptHandle cryptHandle(devPath.c_str());
+ if (cryptHandle.get() == nullptr)
{
lg2::error("Failed to initialize crypt device", "REDFISH_MESSAGE_ID",
std::string("OpenBMC.0.1.FormatFail"));
throw EncryptionError();
}
- formatLuksDev(cryptDev, password);
- activateLuksDev(cryptDev, password);
+ formatLuksDev(cryptHandle.get(), password);
+ activateLuksDev(cryptHandle.get(), password);
createFilesystem();
mountFilesystem();
@@ -104,16 +103,15 @@
std::string msg = "OpenBMC.0.1.DriveUnlock";
lg2::info("Starting unlock", "REDFISH_MESSAGE_ID", msg);
- struct crypt_device* cryptDev;
- CryptHandle cryptHandle(&cryptDev, devPath.c_str());
- if (*cryptHandle.handle == nullptr)
+ CryptHandle cryptHandle(devPath.c_str());
+ if (cryptHandle.get() == nullptr)
{
lg2::error("Failed to initialize crypt device", "REDFISH_MESSAGE_ID",
std::string("OpenBMC.0.1.UnlockFail"));
throw EncryptionError();
}
- activateLuksDev(cryptDev, password);
+ activateLuksDev(cryptHandle.get(), password);
mountFilesystem();
}