diff options
author | Darshan Sen <raisinten@gmail.com> | 2022-03-09 01:40:28 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-09 01:40:28 +0300 |
commit | 6b004f1bb14a1f06066a087f1e1c12c577dc7568 (patch) | |
tree | 89be9adc798fc087fd6325f224a468fd5ec5c320 /src/crypto/crypto_ec.cc | |
parent | 4d70dc7dc26ef365602452c9a6be3f63dfec5eba (diff) |
src,crypto: avoid tristate Maybe<bool> in ExportJWKEcKey()
The function currently uses the return value to convey whether an
exception was thrown while it was running by using either Just(true) or
Nothing<bool>(). Unfortunately, Maybe<bool> also has a third state -
Just(false), which doesn't make any sense here. So this change avoids
the possibility of a tristate return value by making use of Maybe<void>
which only has two valid states - JustVoid() / Nothing<void>(), which
fits right in.
Signed-off-by: Darshan Sen <raisinten@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/42223
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/crypto/crypto_ec.cc')
-rw-r--r-- | src/crypto/crypto_ec.cc | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/crypto/crypto_ec.cc b/src/crypto/crypto_ec.cc index 868c3465ad3..7f1ba4dbff6 100644 --- a/src/crypto/crypto_ec.cc +++ b/src/crypto/crypto_ec.cc @@ -24,6 +24,7 @@ using v8::FunctionCallbackInfo; using v8::FunctionTemplate; using v8::Int32; using v8::Just; +using v8::JustVoid; using v8::Local; using v8::Maybe; using v8::Nothing; @@ -711,7 +712,7 @@ WebCryptoKeyExportStatus ECKeyExportTraits::DoExport( } } -Maybe<bool> ExportJWKEcKey( +Maybe<void> ExportJWKEcKey( Environment* env, std::shared_ptr<KeyObjectData> key, Local<Object> target) { @@ -738,7 +739,7 @@ Maybe<bool> ExportJWKEcKey( env->context(), env->jwk_kty_string(), env->jwk_ec_string()).IsNothing()) { - return Nothing<bool>(); + return Nothing<void>(); } if (SetEncodedValue( @@ -753,7 +754,7 @@ Maybe<bool> ExportJWKEcKey( env->jwk_y_string(), y.get(), degree_bytes).IsNothing()) { - return Nothing<bool>(); + return Nothing<void>(); } Local<String> crv_name; @@ -774,14 +775,14 @@ Maybe<bool> ExportJWKEcKey( default: { THROW_ERR_CRYPTO_JWK_UNSUPPORTED_CURVE( env, "Unsupported JWK EC curve: %s.", OBJ_nid2sn(nid)); - return Nothing<bool>(); + return Nothing<void>(); } } if (target->Set( env->context(), env->jwk_crv_string(), crv_name).IsNothing()) { - return Nothing<bool>(); + return Nothing<void>(); } if (key->GetKeyType() == kKeyTypePrivate) { @@ -791,10 +792,10 @@ Maybe<bool> ExportJWKEcKey( target, env->jwk_d_string(), pvt, - degree_bytes); + degree_bytes).IsJust() ? JustVoid() : Nothing<void>(); } - return Just(true); + return JustVoid(); } Maybe<bool> ExportJWKEdKey( |