Skip to content

Commit 8a05fbc

Browse files
committed
fixup! crypto: add FIPS indicator diagnostics channel
1 parent e3ba181 commit 8a05fbc

2 files changed

Lines changed: 29 additions & 26 deletions

File tree

src/crypto/crypto_util.cc

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ using v8::BackingStoreInitializationMode;
5050
using v8::BackingStoreOnFailureMode;
5151
using v8::BigInt;
5252
using v8::Context;
53+
using v8::DictionaryTemplate;
5354
using v8::EscapableHandleScope;
5455
using v8::Exception;
5556
using v8::Function;
@@ -229,6 +230,22 @@ struct FipsIndicatorEvent {
229230
uint32_t dropped = 0;
230231
};
231232

233+
Local<DictionaryTemplate> GetFipsIndicatorEventTemplate(Environment* env) {
234+
auto tmpl = env->fips_indicator_event_template();
235+
if (tmpl.IsEmpty()) {
236+
static constexpr std::string_view names[] = {
237+
"operation",
238+
"reason",
239+
"blocked",
240+
"count",
241+
"dropped",
242+
};
243+
tmpl = DictionaryTemplate::New(env->isolate(), names);
244+
env->set_fips_indicator_event_template(tmpl);
245+
}
246+
return tmpl;
247+
}
248+
232249
class FipsIndicatorState final {
233250
public:
234251
static FipsIndicatorState& Get() {
@@ -361,32 +378,17 @@ class FipsIndicatorState final {
361378
const uint64_t subscription_generation = subscription_generation_;
362379
for (const auto& event : events) {
363380
if (subscription_generation_ != subscription_generation) return;
364-
Local<Object> value = Object::New(isolate);
365-
if (value
366-
->Set(context,
367-
OneByteString(isolate, "operation"),
368-
OneByteString(isolate, event.operation))
369-
.IsNothing() ||
370-
value
371-
->Set(context,
372-
OneByteString(isolate, "reason"),
373-
OneByteString(isolate, event.reason))
374-
.IsNothing() ||
375-
value
376-
->Set(context,
377-
OneByteString(isolate, "blocked"),
378-
v8::Boolean::New(isolate, event.blocked))
379-
.IsNothing() ||
380-
value
381-
->Set(context,
382-
OneByteString(isolate, "count"),
383-
Uint32::New(isolate, event.count))
384-
.IsNothing() ||
385-
value
386-
->Set(context,
387-
OneByteString(isolate, "dropped"),
388-
Uint32::New(isolate, event.dropped))
389-
.IsNothing()) {
381+
MaybeLocal<Value> values[] = {
382+
OneByteString(isolate, event.operation),
383+
OneByteString(isolate, event.reason),
384+
v8::Boolean::New(isolate, event.blocked),
385+
Uint32::New(isolate, event.count),
386+
Uint32::New(isolate, event.dropped),
387+
};
388+
Local<Object> value;
389+
if (!NewDictionaryInstance(
390+
context, GetFipsIndicatorEventTemplate(env), values)
391+
.ToLocal(&value)) {
390392
return;
391393
}
392394
channel_->Publish(env, value);

src/env_properties.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@
441441
V(ffi_dynamic_library_constructor_template, v8::FunctionTemplate) \
442442
V(ffi_function_constructor_template, v8::FunctionTemplate) \
443443
V(filehandlereadwrap_template, v8::ObjectTemplate) \
444+
V(fips_indicator_event_template, v8::DictionaryTemplate) \
444445
V(free_list_statistics_template, v8::DictionaryTemplate) \
445446
V(fsreqpromise_constructor_template, v8::ObjectTemplate) \
446447
V(handle_wrap_ctor_template, v8::FunctionTemplate) \

0 commit comments

Comments
 (0)