mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
src: use Maybe<void> in ManagedEVPPKey
With recent versions of V8, it is not necessary to use Maybe<bool> anymore. This changes member functions of ManagedEVPPKey to use Maybe<void> instead, as well as (transitive) dependencies. PR-URL: https://github.com/nodejs/node/pull/53811 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
1 parent
38b7ce3b1e
commit
e08a654fae
6 files changed
+52
-57
No files matched your search
+9
-10
@@ -839,10 +839,9 @@ Maybe<void> ExportJWKEcKey(
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
Maybe<bool> ExportJWKEdKey(
|
||||
Environment* env,
|
||||
std::shared_ptr<KeyObjectData> key,
|
||||
Local<Object> target) {
|
||||
Maybe<void> ExportJWKEdKey(Environment* env,
|
||||
std::shared_ptr<KeyObjectData> key,
|
||||
Local<Object> target) {
|
||||
ManagedEVPPKey pkey = key->GetAsymmetricKey();
|
||||
Mutex::ScopedLock lock(*pkey.mutex());
|
||||
|
||||
@@ -867,7 +866,7 @@ Maybe<bool> ExportJWKEdKey(
|
||||
env->context(),
|
||||
env->jwk_crv_string(),
|
||||
OneByteString(env->isolate(), curve)).IsNothing()) {
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
size_t len = 0;
|
||||
@@ -875,7 +874,7 @@ Maybe<bool> ExportJWKEdKey(
|
||||
Local<Value> error;
|
||||
|
||||
if (!EVP_PKEY_get_raw_public_key(pkey.get(), nullptr, &len))
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
|
||||
ByteSource::Builder out(len);
|
||||
|
||||
@@ -888,7 +887,7 @@ Maybe<bool> ExportJWKEdKey(
|
||||
!target->Set(env->context(), env->jwk_d_string(), encoded).IsJust()) {
|
||||
if (!error.IsEmpty())
|
||||
env->isolate()->ThrowException(error);
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -900,17 +899,17 @@ Maybe<bool> ExportJWKEdKey(
|
||||
!target->Set(env->context(), env->jwk_x_string(), encoded).IsJust()) {
|
||||
if (!error.IsEmpty())
|
||||
env->isolate()->ThrowException(error);
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
if (target->Set(
|
||||
env->context(),
|
||||
env->jwk_kty_string(),
|
||||
env->jwk_okp_string()).IsNothing()) {
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
std::shared_ptr<KeyObjectData> ImportJWKEcKey(
|
||||
|
||||
@@ -148,10 +148,9 @@ v8::Maybe<void> ExportJWKEcKey(
|
||||
std::shared_ptr<KeyObjectData> key,
|
||||
v8::Local<v8::Object> target);
|
||||
|
||||
v8::Maybe<bool> ExportJWKEdKey(
|
||||
Environment* env,
|
||||
std::shared_ptr<KeyObjectData> key,
|
||||
v8::Local<v8::Object> target);
|
||||
v8::Maybe<void> ExportJWKEdKey(Environment* env,
|
||||
std::shared_ptr<KeyObjectData> key,
|
||||
v8::Local<v8::Object> target);
|
||||
|
||||
std::shared_ptr<KeyObjectData> ImportJWKEcKey(
|
||||
Environment* env,
|
||||
|
||||
+27
-29
@@ -26,6 +26,7 @@ using v8::FunctionTemplate;
|
||||
using v8::Int32;
|
||||
using v8::Isolate;
|
||||
using v8::Just;
|
||||
using v8::JustVoid;
|
||||
using v8::Local;
|
||||
using v8::Maybe;
|
||||
using v8::MaybeLocal;
|
||||
@@ -431,10 +432,9 @@ MaybeLocal<Value> WritePublicKey(Environment* env,
|
||||
return BIOToStringOrBuffer(env, bio.get(), config.format_);
|
||||
}
|
||||
|
||||
Maybe<bool> ExportJWKSecretKey(
|
||||
Environment* env,
|
||||
std::shared_ptr<KeyObjectData> key,
|
||||
Local<Object> target) {
|
||||
Maybe<void> ExportJWKSecretKey(Environment* env,
|
||||
std::shared_ptr<KeyObjectData> key,
|
||||
Local<Object> target) {
|
||||
CHECK_EQ(key->GetKeyType(), kKeyTypeSecret);
|
||||
|
||||
Local<Value> error;
|
||||
@@ -449,10 +449,9 @@ Maybe<bool> ExportJWKSecretKey(
|
||||
if (key_data.IsEmpty()) {
|
||||
CHECK(!error.IsEmpty());
|
||||
env->isolate()->ThrowException(error);
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
if (!key_data.ToLocal(&raw))
|
||||
return Nothing<bool>();
|
||||
if (!key_data.ToLocal(&raw)) return Nothing<void>();
|
||||
|
||||
if (target->Set(
|
||||
env->context(),
|
||||
@@ -462,10 +461,10 @@ Maybe<bool> ExportJWKSecretKey(
|
||||
env->context(),
|
||||
env->jwk_k_string(),
|
||||
raw).IsNothing()) {
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
std::shared_ptr<KeyObjectData> ImportJWKSecretKey(
|
||||
@@ -483,19 +482,18 @@ std::shared_ptr<KeyObjectData> ImportJWKSecretKey(
|
||||
return KeyObjectData::CreateSecret(std::move(key_data));
|
||||
}
|
||||
|
||||
Maybe<bool> ExportJWKAsymmetricKey(
|
||||
Environment* env,
|
||||
std::shared_ptr<KeyObjectData> key,
|
||||
Local<Object> target,
|
||||
bool handleRsaPss) {
|
||||
Maybe<void> ExportJWKAsymmetricKey(Environment* env,
|
||||
std::shared_ptr<KeyObjectData> key,
|
||||
Local<Object> target,
|
||||
bool handleRsaPss) {
|
||||
switch (EVP_PKEY_id(key->GetAsymmetricKey().get())) {
|
||||
case EVP_PKEY_RSA_PSS: {
|
||||
if (handleRsaPss) return ExportJWKRsaKey(env, key, target);
|
||||
break;
|
||||
}
|
||||
case EVP_PKEY_RSA: return ExportJWKRsaKey(env, key, target);
|
||||
case EVP_PKEY_EC: return ExportJWKEcKey(env, key, target).IsJust() ?
|
||||
Just(true) : Nothing<bool>();
|
||||
case EVP_PKEY_EC:
|
||||
return ExportJWKEcKey(env, key, target);
|
||||
case EVP_PKEY_ED25519:
|
||||
// Fall through
|
||||
case EVP_PKEY_ED448:
|
||||
@@ -505,7 +503,7 @@ Maybe<bool> ExportJWKAsymmetricKey(
|
||||
case EVP_PKEY_X448: return ExportJWKEdKey(env, key, target);
|
||||
}
|
||||
THROW_ERR_CRYPTO_JWK_UNSUPPORTED_KEY_TYPE(env);
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
std::shared_ptr<KeyObjectData> ImportJWKAsymmetricKey(
|
||||
@@ -605,12 +603,12 @@ size_t ManagedEVPPKey::size_of_public_key() const {
|
||||
pkey_.get(), nullptr, &len) == 1) ? len : 0;
|
||||
}
|
||||
|
||||
// This maps true to Just<bool>(true) and false to Nothing<bool>().
|
||||
static inline Maybe<bool> Tristate(bool b) {
|
||||
return b ? Just(true) : Nothing<bool>();
|
||||
// This maps true to JustVoid and false to Nothing<void>().
|
||||
static inline Maybe<void> NothingIfFalse(bool b) {
|
||||
return b ? JustVoid() : Nothing<void>();
|
||||
}
|
||||
|
||||
Maybe<bool> ExportJWKInner(Environment* env,
|
||||
Maybe<void> ExportJWKInner(Environment* env,
|
||||
std::shared_ptr<KeyObjectData> key,
|
||||
Local<Value> result,
|
||||
bool handleRsaPss) {
|
||||
@@ -627,17 +625,17 @@ Maybe<bool> ExportJWKInner(Environment* env,
|
||||
}
|
||||
}
|
||||
|
||||
Maybe<bool> ManagedEVPPKey::ToEncodedPublicKey(
|
||||
Maybe<void> ManagedEVPPKey::ToEncodedPublicKey(
|
||||
Environment* env,
|
||||
const PublicKeyEncodingConfig& config,
|
||||
Local<Value>* out) {
|
||||
if (!*this) return Nothing<bool>();
|
||||
if (!*this) return Nothing<void>();
|
||||
if (config.output_key_object_) {
|
||||
// Note that this has the downside of containing sensitive data of the
|
||||
// private key.
|
||||
std::shared_ptr<KeyObjectData> data =
|
||||
KeyObjectData::CreateAsymmetric(kKeyTypePublic, *this);
|
||||
return Tristate(KeyObjectHandle::Create(env, data).ToLocal(out));
|
||||
return NothingIfFalse(KeyObjectHandle::Create(env, data).ToLocal(out));
|
||||
} else if (config.format_ == kKeyFormatJWK) {
|
||||
std::shared_ptr<KeyObjectData> data =
|
||||
KeyObjectData::CreateAsymmetric(kKeyTypePublic, *this);
|
||||
@@ -645,18 +643,18 @@ Maybe<bool> ManagedEVPPKey::ToEncodedPublicKey(
|
||||
return ExportJWKInner(env, data, *out, false);
|
||||
}
|
||||
|
||||
return Tristate(WritePublicKey(env, get(), config).ToLocal(out));
|
||||
return NothingIfFalse(WritePublicKey(env, get(), config).ToLocal(out));
|
||||
}
|
||||
|
||||
Maybe<bool> ManagedEVPPKey::ToEncodedPrivateKey(
|
||||
Maybe<void> ManagedEVPPKey::ToEncodedPrivateKey(
|
||||
Environment* env,
|
||||
const PrivateKeyEncodingConfig& config,
|
||||
Local<Value>* out) {
|
||||
if (!*this) return Nothing<bool>();
|
||||
if (!*this) return Nothing<void>();
|
||||
if (config.output_key_object_) {
|
||||
std::shared_ptr<KeyObjectData> data =
|
||||
KeyObjectData::CreateAsymmetric(kKeyTypePrivate, *this);
|
||||
return Tristate(KeyObjectHandle::Create(env, data).ToLocal(out));
|
||||
return NothingIfFalse(KeyObjectHandle::Create(env, data).ToLocal(out));
|
||||
} else if (config.format_ == kKeyFormatJWK) {
|
||||
std::shared_ptr<KeyObjectData> data =
|
||||
KeyObjectData::CreateAsymmetric(kKeyTypePrivate, *this);
|
||||
@@ -664,7 +662,7 @@ Maybe<bool> ManagedEVPPKey::ToEncodedPrivateKey(
|
||||
return ExportJWKInner(env, data, *out, false);
|
||||
}
|
||||
|
||||
return Tristate(WritePrivateKey(env, get(), config).ToLocal(out));
|
||||
return NothingIfFalse(WritePrivateKey(env, get(), config).ToLocal(out));
|
||||
}
|
||||
|
||||
NonCopyableMaybe<PrivateKeyEncodingConfig>
|
||||
|
||||
@@ -112,11 +112,11 @@ class ManagedEVPPKey : public MemoryRetainer {
|
||||
unsigned int* offset,
|
||||
bool allow_key_object);
|
||||
|
||||
v8::Maybe<bool> ToEncodedPublicKey(Environment* env,
|
||||
v8::Maybe<void> ToEncodedPublicKey(Environment* env,
|
||||
const PublicKeyEncodingConfig& config,
|
||||
v8::Local<v8::Value>* out);
|
||||
|
||||
v8::Maybe<bool> ToEncodedPrivateKey(Environment* env,
|
||||
v8::Maybe<void> ToEncodedPrivateKey(Environment* env,
|
||||
const PrivateKeyEncodingConfig& config,
|
||||
v8::Local<v8::Value>* out);
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ using v8::BackingStore;
|
||||
using v8::FunctionCallbackInfo;
|
||||
using v8::Int32;
|
||||
using v8::Just;
|
||||
using v8::JustVoid;
|
||||
using v8::Local;
|
||||
using v8::Maybe;
|
||||
using v8::Nothing;
|
||||
@@ -359,10 +360,9 @@ WebCryptoCipherStatus RSACipherTraits::DoCipher(
|
||||
return WebCryptoCipherStatus::FAILED;
|
||||
}
|
||||
|
||||
Maybe<bool> ExportJWKRsaKey(
|
||||
Environment* env,
|
||||
std::shared_ptr<KeyObjectData> key,
|
||||
Local<Object> target) {
|
||||
Maybe<void> ExportJWKRsaKey(Environment* env,
|
||||
std::shared_ptr<KeyObjectData> key,
|
||||
Local<Object> target) {
|
||||
ManagedEVPPKey m_pkey = key->GetAsymmetricKey();
|
||||
Mutex::ScopedLock lock(*m_pkey.mutex());
|
||||
int type = EVP_PKEY_id(m_pkey.get());
|
||||
@@ -392,12 +392,12 @@ Maybe<bool> ExportJWKRsaKey(
|
||||
env->context(),
|
||||
env->jwk_kty_string(),
|
||||
env->jwk_rsa_string()).IsNothing()) {
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
if (SetEncodedValue(env, target, env->jwk_n_string(), n).IsNothing() ||
|
||||
SetEncodedValue(env, target, env->jwk_e_string(), e).IsNothing()) {
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
if (key->GetKeyType() == kKeyTypePrivate) {
|
||||
@@ -409,11 +409,11 @@ Maybe<bool> ExportJWKRsaKey(
|
||||
SetEncodedValue(env, target, env->jwk_dp_string(), dp).IsNothing() ||
|
||||
SetEncodedValue(env, target, env->jwk_dq_string(), dq).IsNothing() ||
|
||||
SetEncodedValue(env, target, env->jwk_qi_string(), qi).IsNothing()) {
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
}
|
||||
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
std::shared_ptr<KeyObjectData> ImportJWKRsaKey(
|
||||
|
||||
@@ -114,10 +114,9 @@ struct RSACipherTraits final {
|
||||
|
||||
using RSACipherJob = CipherJob<RSACipherTraits>;
|
||||
|
||||
v8::Maybe<bool> ExportJWKRsaKey(
|
||||
Environment* env,
|
||||
std::shared_ptr<KeyObjectData> key,
|
||||
v8::Local<v8::Object> target);
|
||||
v8::Maybe<void> ExportJWKRsaKey(Environment* env,
|
||||
std::shared_ptr<KeyObjectData> key,
|
||||
v8::Local<v8::Object> target);
|
||||
|
||||
std::shared_ptr<KeyObjectData> ImportJWKRsaKey(
|
||||
Environment* env,
|
||||
|
||||
Reference in new issue
Block a user