Skip to content

Commit 6f2645e

Browse files
committed
fix: fix more complex clang-tidy warnings
1 parent c5ff067 commit 6f2645e

File tree

2 files changed

+44
-14
lines changed

2 files changed

+44
-14
lines changed

src/lobby/credentials/secret.cpp

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

6466
secret::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

215224
secret::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

382399
secret::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

src/lobby/credentials/secret.hpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <core/helper/expected.hpp>
88
#include <core/helper/types.hpp>
99

10+
#include "helper/windows.hpp"
11+
1012
#if defined(__linux__)
1113

1214
#include <keyutils.h>
@@ -37,16 +39,23 @@ namespace secret {
3739

3840

3941
public:
40-
explicit SecretStorage(KeyringType type);
42+
OOPETRIS_GRAPHICS_EXPORTED explicit SecretStorage(KeyringType type);
43+
44+
OOPETRIS_GRAPHICS_EXPORTED ~SecretStorage(); //NOLINT(performance-trivially-destructible)
45+
46+
OOPETRIS_GRAPHICS_EXPORTED SecretStorage(const SecretStorage& other) = delete;
47+
OOPETRIS_GRAPHICS_EXPORTED SecretStorage& operator=(const SecretStorage& other) = delete;
4148

42-
~SecretStorage();
49+
OOPETRIS_GRAPHICS_EXPORTED SecretStorage(SecretStorage&& other) noexcept;
50+
OOPETRIS_GRAPHICS_EXPORTED SecretStorage& operator=(SecretStorage&& other) noexcept = delete;
4351

44-
[[nodiscard]] helper::expected<std::string, std::string> load(const std::string& key) const;
52+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] helper::expected<std::string, std::string> load(const std::string& key
53+
) const;
4554

46-
[[nodiscard]] std::optional<std::string>
55+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] std::optional<std::string>
4756
store(const std::string& key, const std::string& value, bool update = true) const;
4857

49-
[[nodiscard]] std::optional<std::string> remove(const std::string& key) const;
58+
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] std::optional<std::string> remove(const std::string& key) const;
5059
};
5160

5261
} // namespace secret

0 commit comments

Comments
 (0)