Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src,crypto: avoid tristate Maybe<bool> in ExportJWKEcKey() #42223

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/crypto/crypto_ec.cc
Expand Up @@ -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;
Expand Down Expand Up @@ -711,7 +712,7 @@ WebCryptoKeyExportStatus ECKeyExportTraits::DoExport(
}
}

Maybe<bool> ExportJWKEcKey(
Maybe<void> ExportJWKEcKey(
Environment* env,
std::shared_ptr<KeyObjectData> key,
Local<Object> target) {
Expand All @@ -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(
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/crypto_ec.h
Expand Up @@ -144,7 +144,7 @@ struct ECKeyExportTraits final {

using ECKeyExportJob = KeyExportJob<ECKeyExportTraits>;

v8::Maybe<bool> ExportJWKEcKey(
v8::Maybe<void> ExportJWKEcKey(
Environment* env,
std::shared_ptr<KeyObjectData> key,
v8::Local<v8::Object> target);
Expand Down
3 changes: 2 additions & 1 deletion src/crypto/crypto_keys.cc
Expand Up @@ -497,7 +497,8 @@ Maybe<bool> ExportJWKAsymmetricKey(
break;
}
case EVP_PKEY_RSA: return ExportJWKRsaKey(env, key, target);
case EVP_PKEY_EC: return ExportJWKEcKey(env, key, target);
case EVP_PKEY_EC: return ExportJWKEcKey(env, key, target).IsJust() ?
Just(true) : Nothing<bool>();
case EVP_PKEY_ED25519:
// Fall through
case EVP_PKEY_ED448:
Expand Down