@@ -17,7 +17,7 @@ namespace {
1717 return constants::key_name_prefix + key;
1818 }
1919
20- key_serial_t get_id_from_name (key_serial_t keyring_id, const std::string& key) {
20+ i64 get_id_from_name (key_serial_t keyring_id, const std::string& key) {
2121
2222 const std::string full_key = get_key_name (key);
2323
@@ -41,12 +41,14 @@ secret::SecretStorage::SecretStorage(KeyringType type) : m_type{ type } {
4141 break ;
4242 case secret::KeyringType::Persistent: {
4343 // -1 stands for current uid, 0 stands for: do not create a link to another keyring
44- this -> m_ring_id = keyctl_get_persistent (-1 , 0 );
45- if (this -> m_ring_id < 0 ) {
44+ auto result = keyctl_get_persistent (-1 , 0 );
45+ if (result < 0 ) {
4646 throw std::runtime_error (fmt::format (" Error while getting the persistent keyring: {}" , strerror (errno))
4747 );
4848 }
4949
50+ this ->m_ring_id = static_cast <key_serial_t >(result);
51+
5052 return ;
5153 }
5254 default :
@@ -63,6 +65,10 @@ secret::SecretStorage::SecretStorage(KeyringType type) : m_type{ type } {
6365
6466secret::SecretStorage::~SecretStorage () = default ;
6567
68+ secret::SecretStorage::SecretStorage (SecretStorage&& other) noexcept
69+ : m_type{ other.m_type },
70+ m_ring_id{ other.m_ring_id } { }
71+
6672[[nodiscard]] helper::expected<std::string, std::string> secret::SecretStorage::load (const std::string& key) const {
6773
6874 auto key_id = get_id_from_name (m_ring_id, key);
@@ -76,7 +82,7 @@ secret::SecretStorage::~SecretStorage() = default;
7682
7783 void * buffer = nullptr ;
7884
79- auto result = keyctl_read_alloc (key_id, &buffer);
85+ auto result = keyctl_read_alloc (static_cast < key_serial_t >( key_id) , &buffer);
8086
8187 if (result < 0 ) {
8288 return helper::unexpected<std::string>{
@@ -92,8 +98,11 @@ secret::SecretStorage::~SecretStorage() = default;
9298 return result_string;
9399}
94100
95- [[nodiscard]] std::optional<std::string>
96- secret::SecretStorage::store (const std::string& key, const std::string& value, bool update) const {
101+ [[nodiscard]] std::optional<std::string> secret::SecretStorage::store (
102+ const std::string& key, // NOLINT(bugprone-easily-swappable-parameters)
103+ const std::string& value,
104+ bool update
105+ ) const {
97106
98107 auto key_id = get_id_from_name (m_ring_id, key);
99108
@@ -129,7 +138,7 @@ secret::SecretStorage::store(const std::string& key, const std::string& value, b
129138 return fmt::format (" Error while removing a key, can't find key by name: {}" , strerror (errno));
130139 }
131140
132- auto result = keyctl_unlink (key_id, m_ring_id);
141+ auto result = keyctl_unlink (static_cast < key_serial_t >( key_id) , m_ring_id);
133142
134143 if (result < 0 ) {
135144 return fmt::format (" Error while removing a key, can't unlink key: {}" , strerror (errno));
@@ -213,8 +222,16 @@ secret::SecretStorage::SecretStorage(KeyringType type) : m_type{ type }, m_phPro
213222}
214223
215224secret::SecretStorage::~SecretStorage () {
216- // ignore return code, as it only indicates, if we passed a valid or invalid handle
217- NCryptFreeObject (m_phProvider);
225+ if (m_phProvider) {
226+ // ignore return code, as it only indicates, if we passed a valid or invalid handle
227+ NCryptFreeObject (m_phProvider);
228+ }
229+ }
230+
231+ secret::SecretStorage::SecretStorage (SecretStorage&& other) noexcept
232+ : m_type{ other.m_type },
233+ m_phProvider{ other.m_phProvider } {
234+ other.m_phProvider = nullptr ;
218235}
219236
220237
@@ -381,6 +398,10 @@ secret::SecretStorage::SecretStorage(KeyringType type) : m_type{ type } {
381398
382399secret::SecretStorage::~SecretStorage () = default ;
383400
401+ secret::SecretStorage::SecretStorage (SecretStorage&& other) noexcept
402+ : m_type{ other.m_type },
403+ m_file_path{ other.m_file_path } { }
404+
384405
385406[[nodiscard]] helper::expected<std::string, std::string> secret::SecretStorage::load (const std::string& key) const {
386407
0 commit comments