cryptsetupInterface.hpp (28cc834cecbd3d93e21089862a9288474b5f88cc) | cryptsetupInterface.hpp (b2c86be3b1c6bf26dbfbcf3e3a3f3322472023e9) |
---|---|
1#pragma once 2 3#include <libcryptsetup.h> 4 5#include <phosphor-logging/lg2.hpp> 6#include <stdplus/handle/managed.hpp> 7#include <xyz/openbmc_project/Common/error.hpp> 8 9#include <string> | 1#pragma once 2 3#include <libcryptsetup.h> 4 5#include <phosphor-logging/lg2.hpp> 6#include <stdplus/handle/managed.hpp> 7#include <xyz/openbmc_project/Common/error.hpp> 8 9#include <string> |
10#include <string_view> |
|
10 11namespace estoraged 12{ 13 14using sdbusplus::xyz::openbmc_project::Common::Error::ResourceNotFound; 15 16/** @class CryptsetupInterface 17 * @brief Interface to the cryptsetup functions used to manage a LUKS device. --- 199 unchanged lines hidden (view full) --- 217 */ 218class CryptHandle 219{ 220 public: 221 /** @brief Constructor for CryptHandle 222 * 223 * @param[in] device - path to device file 224 */ | 11 12namespace estoraged 13{ 14 15using sdbusplus::xyz::openbmc_project::Common::Error::ResourceNotFound; 16 17/** @class CryptsetupInterface 18 * @brief Interface to the cryptsetup functions used to manage a LUKS device. --- 199 unchanged lines hidden (view full) --- 218 */ 219class CryptHandle 220{ 221 public: 222 /** @brief Constructor for CryptHandle 223 * 224 * @param[in] device - path to device file 225 */ |
225 explicit CryptHandle(const char* device) : handle(init(device)) | 226 explicit CryptHandle(const std::string_view& device) : handle(init(device)) |
226 {} 227 228 /** @brief Get a pointer to the crypt_device struct. */ 229 struct crypt_device* get() 230 { 231 if (*handle == nullptr) 232 { 233 lg2::error("Failed to get crypt device handle", --- 5 unchanged lines hidden (view full) --- 239 return *handle; 240 } 241 242 private: 243 /** @brief Allocate and initialize the crypt_device struct 244 * 245 * @param[in] device - path to device file 246 */ | 227 {} 228 229 /** @brief Get a pointer to the crypt_device struct. */ 230 struct crypt_device* get() 231 { 232 if (*handle == nullptr) 233 { 234 lg2::error("Failed to get crypt device handle", --- 5 unchanged lines hidden (view full) --- 240 return *handle; 241 } 242 243 private: 244 /** @brief Allocate and initialize the crypt_device struct 245 * 246 * @param[in] device - path to device file 247 */ |
247 struct crypt_device* init(const char* device) | 248 struct crypt_device* init(const std::string_view& device) |
248 { 249 struct crypt_device* cryptDev = nullptr; | 249 { 250 struct crypt_device* cryptDev = nullptr; |
250 int retval = crypt_init(&cryptDev, device); | 251 int retval = crypt_init(&cryptDev, device.data()); |
251 if (retval < 0) 252 { 253 lg2::error("Failed to crypt_init", "REDFISH_MESSAGE_ID", 254 std::string("OpenBMC.0.1.InitFail")); 255 throw ResourceNotFound(); 256 } 257 258 return cryptDev; --- 16 unchanged lines hidden --- | 252 if (retval < 0) 253 { 254 lg2::error("Failed to crypt_init", "REDFISH_MESSAGE_ID", 255 std::string("OpenBMC.0.1.InitFail")); 256 throw ResourceNotFound(); 257 } 258 259 return cryptDev; --- 16 unchanged lines hidden --- |