Skip to content

Commit 49cec19

Browse files
authored
Final tidy (#7515)
1 parent 1d929c0 commit 49cec19

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1383
-1314
lines changed

.clang-tidy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@ Checks: >
5959
-readability-magic-numbers,
6060
6161
WarningsAsErrors: '*'
62-
HeaderFilterRegex: '(include\/ccf\/|src\/(udp|tcp|tls|tasks|snapshots|service|quic|pal|apps|clients|common|consensus|ds|enclave|endpoints|host|indexing|http)\/).*'
62+
HeaderFilterRegex: '(include\/ccf|src)\/.*'
6363
FormatStyle: 'file'

doc/build_apps/crypto.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Hashing
1111
.. doxygenfunction:: ccf::crypto::sha256(const std::vector<uint8_t> &data)
1212
:project: CCF
1313

14-
.. doxygenfunction:: ccf::crypto::hmac(MDType, const std::vector<uint8_t>&, const std::vector<uint8_t>&)
14+
.. doxygenfunction:: ccf::crypto::hmac(MDType, const std::span<const uint8_t>&, const std::span<const uint8_t>&)
1515
:project: CCF
1616

1717
.. doxygenClass:: ccf::crypto::HashProvider

include/ccf/crypto/hmac.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ namespace ccf::crypto
1111
*/
1212
HashBytes hmac(
1313
MDType type,
14-
const std::vector<uint8_t>& key,
15-
const std::vector<uint8_t>& data);
14+
const std::span<const uint8_t>& key,
15+
const std::span<const uint8_t>& data);
1616
}

src/crypto/hmac.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ namespace ccf::crypto
1313
{
1414
HashBytes hmac(
1515
MDType type,
16-
const std::vector<uint8_t>& key,
17-
const std::vector<uint8_t>& data)
16+
const std::span<const uint8_t>& key,
17+
const std::span<const uint8_t>& data)
1818
{
1919
const auto* o_md_type = OpenSSL::get_md_type(type);
2020
HashBytes r(EVP_MD_size(o_md_type));
@@ -42,8 +42,8 @@ namespace ccf::crypto
4242

4343
HashBytes hmac(
4444
MDType type,
45-
const std::vector<uint8_t>& key,
46-
const std::vector<uint8_t>& data)
45+
const std::span<const uint8_t>& key,
46+
const std::span<const uint8_t>& data)
4747
{
4848
return OpenSSL::hmac(type, key, data);
4949
}

src/js/extensions/ccf/kv_helpers.h

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ namespace ccf::js::extensions::kvhelpers
1919
static JSValue C_FUNC_NAME( \
2020
JSContext* ctx, JSValueConst this_val, int, JSValueConst*) \
2121
{ \
22-
js::core::Context& jsctx = *(js::core::Context*)JS_GetContextOpaque(ctx); \
22+
js::core::Context& jsctx = \
23+
*static_cast<js::core::Context*>(JS_GetContextOpaque(ctx)); \
2324
const auto table_name = \
2425
jsctx.to_str(JS_GetPropertyStr(jsctx, this_val, "_map_name")) \
2526
.value_or(""); \
@@ -66,23 +67,24 @@ namespace ccf::js::extensions::kvhelpers
6667
static JSValue js_kv_map_has(
6768
JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv)
6869
{
69-
js::core::Context& jsctx = *(js::core::Context*)JS_GetContextOpaque(ctx);
70+
js::core::Context& jsctx =
71+
*static_cast<js::core::Context*>(JS_GetContextOpaque(ctx));
7072

7173
if (argc != 1)
7274
{
7375
return JS_ThrowTypeError(
7476
ctx, "Passed %d arguments, but expected 1", argc);
7577
}
7678

77-
size_t key_size;
79+
size_t key_size = 0;
7880
uint8_t* key = JS_GetArrayBuffer(ctx, &key_size, argv[0]);
7981

8082
if (!key)
8183
{
8284
return JS_ThrowTypeError(ctx, "Argument must be an ArrayBuffer");
8385
}
8486

85-
auto handle = GetReadOnlyHandle(jsctx, this_val);
87+
auto* handle = GetReadOnlyHandle(jsctx, this_val);
8688
JS_CHECK_HANDLE(handle);
8789

8890
auto has = handle->has({key, key + key_size});
@@ -94,23 +96,24 @@ namespace ccf::js::extensions::kvhelpers
9496
static JSValue js_kv_map_get(
9597
JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv)
9698
{
97-
js::core::Context& jsctx = *(js::core::Context*)JS_GetContextOpaque(ctx);
99+
js::core::Context& jsctx =
100+
*static_cast<js::core::Context*>(JS_GetContextOpaque(ctx));
98101

99102
if (argc != 1)
100103
{
101104
return JS_ThrowTypeError(
102105
ctx, "Passed %d arguments, but expected 1", argc);
103106
}
104107

105-
size_t key_size;
108+
size_t key_size = 0;
106109
uint8_t* key = JS_GetArrayBuffer(ctx, &key_size, argv[0]);
107110

108111
if (!key)
109112
{
110113
return JS_ThrowTypeError(ctx, "Argument must be an ArrayBuffer");
111114
}
112115

113-
auto handle = GetReadOnlyHandle(jsctx, this_val);
116+
auto* handle = GetReadOnlyHandle(jsctx, this_val);
114117
JS_CHECK_HANDLE(handle);
115118

116119
auto val = handle->get({key, key + key_size});
@@ -131,23 +134,24 @@ namespace ccf::js::extensions::kvhelpers
131134
static JSValue js_kv_get_version_of_previous_write(
132135
JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv)
133136
{
134-
js::core::Context& jsctx = *(js::core::Context*)JS_GetContextOpaque(ctx);
137+
js::core::Context& jsctx =
138+
*static_cast<js::core::Context*>(JS_GetContextOpaque(ctx));
135139

136140
if (argc != 1)
137141
{
138142
return JS_ThrowTypeError(
139143
ctx, "Passed %d arguments, but expected 1", argc);
140144
}
141145

142-
size_t key_size;
146+
size_t key_size = 0;
143147
uint8_t* key = JS_GetArrayBuffer(ctx, &key_size, argv[0]);
144148

145149
if (!key)
146150
{
147151
return JS_ThrowTypeError(ctx, "Argument must be an ArrayBuffer");
148152
}
149153

150-
auto handle = GetReadOnlyHandle(jsctx, this_val);
154+
auto* handle = GetReadOnlyHandle(jsctx, this_val);
151155
JS_CHECK_HANDLE(handle);
152156

153157
auto val = handle->get_version_of_previous_write({key, key + key_size});
@@ -162,11 +166,12 @@ namespace ccf::js::extensions::kvhelpers
162166

163167
template <ROHandleGetter GetReadOnlyHandle>
164168
static JSValue js_kv_map_size_getter(
165-
JSContext* ctx, JSValueConst this_val, int argc, JSValueConst*)
169+
JSContext* ctx, JSValueConst this_val, int /*argc*/, JSValueConst*)
166170
{
167-
js::core::Context& jsctx = *(js::core::Context*)JS_GetContextOpaque(ctx);
171+
js::core::Context& jsctx =
172+
*static_cast<js::core::Context*>(JS_GetContextOpaque(ctx));
168173

169-
auto handle = GetReadOnlyHandle(jsctx, this_val);
174+
auto* handle = GetReadOnlyHandle(jsctx, this_val);
170175
JS_CHECK_HANDLE(handle);
171176

172177
const uint64_t size = handle->size();
@@ -183,23 +188,24 @@ namespace ccf::js::extensions::kvhelpers
183188
static JSValue js_kv_map_delete(
184189
JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv)
185190
{
186-
js::core::Context& jsctx = *(js::core::Context*)JS_GetContextOpaque(ctx);
191+
js::core::Context& jsctx =
192+
*static_cast<js::core::Context*>(JS_GetContextOpaque(ctx));
187193

188194
if (argc != 1)
189195
{
190196
return JS_ThrowTypeError(
191197
ctx, "Passed %d arguments, but expected 1", argc);
192198
}
193199

194-
size_t key_size;
200+
size_t key_size = 0;
195201
uint8_t* key = JS_GetArrayBuffer(ctx, &key_size, argv[0]);
196202

197203
if (!key)
198204
{
199205
return JS_ThrowTypeError(ctx, "Argument must be an ArrayBuffer");
200206
}
201207

202-
auto handle = GetWriteHandle(jsctx, this_val);
208+
auto* handle = GetWriteHandle(jsctx, this_val);
203209
JS_CHECK_HANDLE(handle);
204210

205211
handle->remove({key, key + key_size});
@@ -211,26 +217,27 @@ namespace ccf::js::extensions::kvhelpers
211217
static JSValue js_kv_map_set(
212218
JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv)
213219
{
214-
js::core::Context& jsctx = *(js::core::Context*)JS_GetContextOpaque(ctx);
220+
js::core::Context& jsctx =
221+
*static_cast<js::core::Context*>(JS_GetContextOpaque(ctx));
215222

216223
if (argc != 2)
217224
{
218225
return JS_ThrowTypeError(
219226
ctx, "Passed %d arguments, but expected 2", argc);
220227
}
221228

222-
size_t key_size;
229+
size_t key_size = 0;
223230
uint8_t* key = JS_GetArrayBuffer(ctx, &key_size, argv[0]);
224231

225-
size_t val_size;
232+
size_t val_size = 0;
226233
uint8_t* val = JS_GetArrayBuffer(ctx, &val_size, argv[1]);
227234

228235
if (!key || !val)
229236
{
230237
return JS_ThrowTypeError(ctx, "Arguments must be ArrayBuffers");
231238
}
232239

233-
auto handle = GetWriteHandle(jsctx, this_val);
240+
auto* handle = GetWriteHandle(jsctx, this_val);
234241
JS_CHECK_HANDLE(handle);
235242

236243
handle->put({key, key + key_size}, {val, val + val_size});
@@ -240,17 +247,18 @@ namespace ccf::js::extensions::kvhelpers
240247

241248
template <RWHandleGetter GetWriteHandle>
242249
static JSValue js_kv_map_clear(
243-
JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv)
250+
JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* /*argv*/)
244251
{
245-
js::core::Context& jsctx = *(js::core::Context*)JS_GetContextOpaque(ctx);
252+
js::core::Context& jsctx =
253+
*static_cast<js::core::Context*>(JS_GetContextOpaque(ctx));
246254

247255
if (argc != 0)
248256
{
249257
return JS_ThrowTypeError(
250258
ctx, "Passed %d arguments, but expected 0", argc);
251259
}
252260

253-
auto handle = GetWriteHandle(jsctx, this_val);
261+
auto* handle = GetWriteHandle(jsctx, this_val);
254262
JS_CHECK_HANDLE(handle);
255263

256264
handle->clear();
@@ -262,11 +270,14 @@ namespace ccf::js::extensions::kvhelpers
262270
static JSValue js_kv_map_foreach(
263271
JSContext* ctx, JSValueConst this_val, int argc, JSValueConst* argv)
264272
{
265-
js::core::Context& jsctx = *(js::core::Context*)JS_GetContextOpaque(ctx);
273+
js::core::Context& jsctx =
274+
*static_cast<js::core::Context*>(JS_GetContextOpaque(ctx));
266275

267276
if (argc != 1)
277+
{
268278
return JS_ThrowTypeError(
269279
ctx, "Passed %d arguments, but expected 1", argc);
280+
}
270281

271282
js::core::JSWrappedValue func(ctx, argv[0]);
272283
js::core::JSWrappedValue obj(ctx, this_val);
@@ -276,7 +287,7 @@ namespace ccf::js::extensions::kvhelpers
276287
return JS_ThrowTypeError(ctx, "Argument must be a function");
277288
}
278289

279-
auto handle = GetReadOnlyHandle(jsctx, this_val);
290+
auto* handle = GetReadOnlyHandle(jsctx, this_val);
280291
JS_CHECK_HANDLE(handle);
281292

282293
bool failed = false;

src/js/modules/chained_module_loader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace ccf::js::modules
1414
public:
1515
ChainedModuleLoader(ModuleLoaders&& ml) : sub_loaders(std::move(ml)) {}
1616

17-
virtual std::optional<js::core::JSWrappedValue> get_module(
17+
std::optional<js::core::JSWrappedValue> get_module(
1818
std::string_view module_name, js::core::Context& ctx) override
1919
{
2020
for (auto& sub_loader : sub_loaders)

src/js/modules/kv_bytecode_module_loader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace ccf::js::modules
4242
}
4343
}
4444

45-
virtual std::optional<js::core::JSWrappedValue> get_module(
45+
std::optional<js::core::JSWrappedValue> get_module(
4646
std::string_view module_name, js::core::Context& ctx) override
4747
{
4848
if (!version_ok)

src/js/modules/kv_module_loader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace ccf::js::modules
2020
public:
2121
KvModuleLoader(ccf::Modules::ReadOnlyHandle* mh) : modules_handle(mh) {}
2222

23-
virtual std::optional<js::core::JSWrappedValue> get_module(
23+
std::optional<js::core::JSWrappedValue> get_module(
2424
std::string_view module_name, js::core::Context& ctx) override
2525
{
2626
std::string module_name_kv(module_name);
@@ -38,7 +38,7 @@ namespace ccf::js::modules
3838
return std::nullopt;
3939
}
4040

41-
auto module_name_quickjs = module_name_kv.c_str() + 1;
41+
const auto* module_name_quickjs = module_name_kv.c_str() + 1;
4242
const char* buf = module_str->c_str();
4343
size_t buf_len = module_str->size();
4444
auto parsed_module = ctx.eval(

src/js/permissions_checks.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,15 @@ namespace ccf::js
3333
{
3434
return KVAccessPermissions::READ_WRITE;
3535
}
36-
else if (
36+
37+
if (
3738
execution_context == TxAccess::APP_RO &&
3839
namespace_of_table == ccf::kv::AccessCategory::APPLICATION)
3940
{
4041
return KVAccessPermissions::READ_ONLY;
4142
}
42-
else
43-
{
44-
return KVAccessPermissions::ILLEGAL;
45-
}
43+
44+
return KVAccessPermissions::ILLEGAL;
4645
}
4746

4847
case (ccf::kv::SecurityDomain::PUBLIC):
@@ -60,10 +59,8 @@ namespace ccf::js
6059
{
6160
return KVAccessPermissions::READ_WRITE;
6261
}
63-
else
64-
{
65-
return KVAccessPermissions::READ_ONLY;
66-
}
62+
63+
return KVAccessPermissions::READ_ONLY;
6764
}
6865

6966
case ccf::kv::AccessCategory::APPLICATION:
@@ -106,7 +103,7 @@ namespace ccf::js
106103
(permission == KVAccessPermissions::WRITE_ONLY ? "write-only" :
107104
"inaccessible");
108105

109-
char const* exec_context = "unknown";
106+
char const* exec_context = nullptr;
110107
switch (access)
111108
{
112109
case (TxAccess::APP_RW):
@@ -129,6 +126,11 @@ namespace ccf::js
129126
exec_context = "read-write governance";
130127
break;
131128
}
129+
default:
130+
{
131+
exec_context = "unknown";
132+
break;
133+
}
132134
}
133135

134136
static constexpr char const* access_permissions_explanation_url =

0 commit comments

Comments
 (0)