cryptsetupInterface.hpp (59dffa63af63ac1021f372e4505fb8c1b9084906) cryptsetupInterface.hpp (82897c35761f505c2b881f72c61f726f7d562692)
1#pragma once
2
3#include <libcryptsetup.h>
4
5#include <stdplus/handle/managed.hpp>
6
7namespace estoraged
8{
9
10/** @class CryptsetupInterface
11 * @brief Interface to the cryptsetup functions used to manage a LUKS device.
12 * @details This class is used to mock out the cryptsetup functions.
13 */
14class CryptsetupInterface
15{
16 public:
17 virtual ~CryptsetupInterface() = default;
1#pragma once
2
3#include <libcryptsetup.h>
4
5#include <stdplus/handle/managed.hpp>
6
7namespace estoraged
8{
9
10/** @class CryptsetupInterface
11 * @brief Interface to the cryptsetup functions used to manage a LUKS device.
12 * @details This class is used to mock out the cryptsetup functions.
13 */
14class CryptsetupInterface
15{
16 public:
17 virtual ~CryptsetupInterface() = default;
18 CryptsetupInterface() = default;
19 CryptsetupInterface(const CryptsetupInterface&) = delete;
20 CryptsetupInterface& operator=(const CryptsetupInterface&) = delete;
18
21
22 CryptsetupInterface(CryptsetupInterface&&) = delete;
23 CryptsetupInterface& operator=(CryptsetupInterface&&) = delete;
19 /** @brief Wrapper around crypt_format.
20 * @details Used for mocking purposes.
21 *
22 * @param[in] cd - crypt device handle.
23 * @param[in] type - type of device (optional params struct must be of
24 * this type).
25 * @param[in] cipher - (e.g. "aes").
26 * @params[in cipher_mode - including IV specification (e.g. "xts-plain").

--- 73 unchanged lines hidden (view full) ---

100 /** @brief Wrapper around crypt_keyslot_destory.
101 * @details Used for mocking purposes.
102 *
103 * @param[in] cd - crypt device handle, can not be NULL.
104 * @param[in] keyslot requested key slot to destroy
105 *
106 * @returns 0 on success or negative errno value otherwise.
107 */
24 /** @brief Wrapper around crypt_format.
25 * @details Used for mocking purposes.
26 *
27 * @param[in] cd - crypt device handle.
28 * @param[in] type - type of device (optional params struct must be of
29 * this type).
30 * @param[in] cipher - (e.g. "aes").
31 * @params[in cipher_mode - including IV specification (e.g. "xts-plain").

--- 73 unchanged lines hidden (view full) ---

105 /** @brief Wrapper around crypt_keyslot_destory.
106 * @details Used for mocking purposes.
107 *
108 * @param[in] cd - crypt device handle, can not be NULL.
109 * @param[in] keyslot requested key slot to destroy
110 *
111 * @returns 0 on success or negative errno value otherwise.
112 */
108 virtual int cryptKeyslotDestroy(struct crypt_device* cd,
109 const int keyslot) = 0;
113 virtual int cryptKeyslotDestroy(struct crypt_device* cd, int keyslot) = 0;
110
111 /** @breif Wapper around crypt_keyslot_max
112 * @details Used for mocking purposes.
113 *
114 * @param type crypt device type
115 *
116 * @return slot count or negative errno otherwise if device
117 * does not support keyslots.

--- 15 unchanged lines hidden (view full) ---

133};
134
135/** @class Cryptsetup
136 * @brief Implements CryptsetupInterface.
137 */
138class Cryptsetup : public CryptsetupInterface
139{
140 public:
114
115 /** @breif Wapper around crypt_keyslot_max
116 * @details Used for mocking purposes.
117 *
118 * @param type crypt device type
119 *
120 * @return slot count or negative errno otherwise if device
121 * does not support keyslots.

--- 15 unchanged lines hidden (view full) ---

137};
138
139/** @class Cryptsetup
140 * @brief Implements CryptsetupInterface.
141 */
142class Cryptsetup : public CryptsetupInterface
143{
144 public:
141 ~Cryptsetup() = default;
145 ~Cryptsetup() override = default;
142
146
147 Cryptsetup() = default;
148 Cryptsetup(const Cryptsetup&) = delete;
149 Cryptsetup& operator=(const Cryptsetup&) = delete;
150
151 Cryptsetup(Cryptsetup&&) = delete;
152 Cryptsetup& operator=(Cryptsetup&&) = delete;
143 int cryptFormat(struct crypt_device* cd, const char* type,
144 const char* cipher, const char* cipherMode,
145 const char* uuid, const char* volumeKey,
146 size_t volumeKeySize, void* params) override
147 {
148 return crypt_format(cd, type, cipher, cipherMode, uuid, volumeKey,
149 volumeKeySize, params);
150 }

--- 66 unchanged lines hidden (view full) ---

217
218 private:
219 /** @brief Allocate and initialize the crypt_device struct
220 *
221 * @param[in] device - path to device file
222 */
223 struct crypt_device* init(const char* device)
224 {
153 int cryptFormat(struct crypt_device* cd, const char* type,
154 const char* cipher, const char* cipherMode,
155 const char* uuid, const char* volumeKey,
156 size_t volumeKeySize, void* params) override
157 {
158 return crypt_format(cd, type, cipher, cipherMode, uuid, volumeKey,
159 volumeKeySize, params);
160 }

--- 66 unchanged lines hidden (view full) ---

227
228 private:
229 /** @brief Allocate and initialize the crypt_device struct
230 *
231 * @param[in] device - path to device file
232 */
233 struct crypt_device* init(const char* device)
234 {
225 struct crypt_device* cryptDev;
235 struct crypt_device* cryptDev = nullptr;
226 int retval = crypt_init(&cryptDev, device);
227 if (retval < 0)
228 {
229 return nullptr;
230 }
231
232 return cryptDev;
233 }

--- 15 unchanged lines hidden ---
236 int retval = crypt_init(&cryptDev, device);
237 if (retval < 0)
238 {
239 return nullptr;
240 }
241
242 return cryptDev;
243 }

--- 15 unchanged lines hidden ---