Skip to content

Commit

Permalink
src: convert more Maybe<bool> to Maybe<void>
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Sep 7, 2024
1 parent 6bbb18f commit 70dcde2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
12 changes: 8 additions & 4 deletions src/crypto/crypto_keygen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ using v8::Just;
using v8::JustVoid;
using v8::Local;
using v8::Maybe;
using v8::MaybeLocal;
using v8::Object;
using v8::Uint32;
using v8::Value;
Expand Down Expand Up @@ -79,12 +80,15 @@ KeyGenJobStatus SecretKeyGenTraits::DoKeyGen(Environment* env,
return KeyGenJobStatus::OK;
}

Maybe<bool> SecretKeyGenTraits::EncodeKey(Environment* env,
SecretKeyGenConfig* params,
Local<Value>* result) {
MaybeLocal<Value> SecretKeyGenTraits::EncodeKey(Environment* env,
SecretKeyGenConfig* params) {
std::shared_ptr<KeyObjectData> data =
KeyObjectData::CreateSecret(std::move(params->out));
return Just(KeyObjectHandle::Create(env, data).ToLocal(result));
Local<Value> ret;
if (!KeyObjectHandle::Create(env, data).ToLocal(&ret)) {
return MaybeLocal<Value>();
}
return ret;
}

namespace Keygen {
Expand Down
26 changes: 14 additions & 12 deletions src/crypto/crypto_keygen.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,16 @@ class KeyGenJob final : public CryptoJob<KeyGenTraits> {
AdditionalParams* params = CryptoJob<KeyGenTraits>::params();

if (status_ == KeyGenJobStatus::OK) {
v8::Maybe<bool> ret = KeyGenTraits::EncodeKey(env, params, result);
if (ret.IsJust() && ret.FromJust()) {
v8::TryCatch try_catch(env->isolate());
if (KeyGenTraits::EncodeKey(env, params).ToLocal(result)) {
*err = Undefined(env->isolate());
} else {
CHECK(try_catch.HasCaught());
CHECK(try_catch.CanContinue());
*result = Undefined(env->isolate());
*err = try_catch.Exception();
}
return ret;
return v8::Just(true);
}

if (errors->Empty())
Expand Down Expand Up @@ -178,21 +183,19 @@ struct KeyPairGenTraits final {
return KeyGenJobStatus::OK;
}

static v8::Maybe<bool> EncodeKey(
static v8::MaybeLocal<v8::Value> EncodeKey(
Environment* env,
AdditionalParameters* params,
v8::Local<v8::Value>* result) {
AdditionalParameters* params) {
v8::Local<v8::Value> keys[2];
if (params->key
.ToEncodedPublicKey(env, params->public_key_encoding, &keys[0])
.IsNothing() ||
params->key
.ToEncodedPrivateKey(env, params->private_key_encoding, &keys[1])
.IsNothing()) {
return v8::Nothing<bool>();
return v8::MaybeLocal<v8::Value>();
}
*result = v8::Array::New(env->isolate(), keys, arraysize(keys));
return v8::Just(true);
return v8::Array::New(env->isolate(), keys, arraysize(keys));
}
};

Expand Down Expand Up @@ -221,10 +224,9 @@ struct SecretKeyGenTraits final {
Environment* env,
SecretKeyGenConfig* params);

static v8::Maybe<bool> EncodeKey(
static v8::MaybeLocal<v8::Value> EncodeKey(
Environment* env,
SecretKeyGenConfig* params,
v8::Local<v8::Value>* result);
SecretKeyGenConfig* params);
};

template <typename AlgorithmParams>
Expand Down

0 comments on commit 70dcde2

Please sign in to comment.