mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
src: switch crypto APIs to use Maybe<void>
PR-URL: https://github.com/nodejs/node/pull/54775 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This commit is contained in:
1 parent
780f478d0f
commit
08eccaf57f
30 files changed
+351
-378
No files matched your search
@@ -18,6 +18,7 @@ namespace node {
|
||||
|
||||
using v8::FunctionCallbackInfo;
|
||||
using v8::Just;
|
||||
using v8::JustVoid;
|
||||
using v8::Local;
|
||||
using v8::Maybe;
|
||||
using v8::Nothing;
|
||||
@@ -452,7 +453,7 @@ void AESCipherConfig::MemoryInfo(MemoryTracker* tracker) const {
|
||||
}
|
||||
}
|
||||
|
||||
Maybe<bool> AESCipherTraits::AdditionalConfig(
|
||||
Maybe<void> AESCipherTraits::AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const FunctionCallbackInfo<Value>& args,
|
||||
unsigned int offset,
|
||||
@@ -482,22 +483,22 @@ Maybe<bool> AESCipherTraits::AdditionalConfig(
|
||||
params->cipher = EVP_get_cipherbynid(cipher_nid);
|
||||
if (params->cipher == nullptr) {
|
||||
THROW_ERR_CRYPTO_UNKNOWN_CIPHER(env);
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
int cipher_op_mode = EVP_CIPHER_mode(params->cipher);
|
||||
if (cipher_op_mode != EVP_CIPH_WRAP_MODE) {
|
||||
if (!ValidateIV(env, mode, args[offset + 1], params)) {
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
if (cipher_op_mode == EVP_CIPH_CTR_MODE) {
|
||||
if (!ValidateCounter(env, args[offset + 2], params)) {
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
} else if (cipher_op_mode == EVP_CIPH_GCM_MODE) {
|
||||
if (!ValidateAuthTag(env, mode, cipher_mode, args[offset + 2], params) ||
|
||||
!ValidateAdditionalData(env, mode, args[offset + 3], params)) {
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -507,10 +508,10 @@ Maybe<bool> AESCipherTraits::AdditionalConfig(
|
||||
if (params->iv.size() <
|
||||
static_cast<size_t>(EVP_CIPHER_iv_length(params->cipher))) {
|
||||
THROW_ERR_CRYPTO_INVALID_IV(env);
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
WebCryptoCipherStatus AESCipherTraits::DoCipher(Environment* env,
|
||||
|
||||
@@ -60,7 +60,7 @@ struct AESCipherTraits final {
|
||||
|
||||
using AdditionalParameters = AESCipherConfig;
|
||||
|
||||
static v8::Maybe<bool> AdditionalConfig(
|
||||
static v8::Maybe<void> AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args,
|
||||
unsigned int offset,
|
||||
|
||||
@@ -245,9 +245,8 @@ class CipherJob final : public CryptoJob<CipherTraits> {
|
||||
}
|
||||
}
|
||||
|
||||
v8::Maybe<bool> ToResult(
|
||||
v8::Local<v8::Value>* err,
|
||||
v8::Local<v8::Value>* result) override {
|
||||
v8::Maybe<void> ToResult(v8::Local<v8::Value>* err,
|
||||
v8::Local<v8::Value>* result) override {
|
||||
Environment* env = AsyncWrap::env();
|
||||
CryptoErrorStore* errors = CryptoJob<CipherTraits>::errors();
|
||||
|
||||
@@ -258,11 +257,18 @@ class CipherJob final : public CryptoJob<CipherTraits> {
|
||||
CHECK(errors->Empty());
|
||||
*err = v8::Undefined(env->isolate());
|
||||
*result = out_.ToArrayBuffer(env);
|
||||
return v8::Just(!result->IsEmpty());
|
||||
if (result->IsEmpty()) {
|
||||
return v8::Nothing<void>();
|
||||
}
|
||||
} else {
|
||||
*result = v8::Undefined(env->isolate());
|
||||
if (!errors->ToException(env).ToLocal(err)) {
|
||||
return v8::Nothing<void>();
|
||||
}
|
||||
}
|
||||
|
||||
*result = v8::Undefined(env->isolate());
|
||||
return v8::Just(errors->ToException(env).ToLocal(err));
|
||||
CHECK(!result->IsEmpty());
|
||||
CHECK(!err->IsEmpty());
|
||||
return v8::JustVoid();
|
||||
}
|
||||
|
||||
SET_SELF_SIZE(CipherJob)
|
||||
|
||||
+19
-22
@@ -23,7 +23,7 @@ using v8::FunctionCallbackInfo;
|
||||
using v8::FunctionTemplate;
|
||||
using v8::Int32;
|
||||
using v8::Isolate;
|
||||
using v8::Just;
|
||||
using v8::JustVoid;
|
||||
using v8::Local;
|
||||
using v8::Maybe;
|
||||
using v8::MaybeLocal;
|
||||
@@ -338,7 +338,7 @@ void Check(const FunctionCallbackInfo<Value>& args) {
|
||||
// * Private type
|
||||
// * Cipher
|
||||
// * Passphrase
|
||||
Maybe<bool> DhKeyGenTraits::AdditionalConfig(
|
||||
Maybe<void> DhKeyGenTraits::AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const FunctionCallbackInfo<Value>& args,
|
||||
unsigned int* offset,
|
||||
@@ -350,7 +350,7 @@ Maybe<bool> DhKeyGenTraits::AdditionalConfig(
|
||||
auto group = DHPointer::FindGroup(group_name.ToStringView());
|
||||
if (!group) {
|
||||
THROW_ERR_CRYPTO_UNKNOWN_DH_GROUP(env);
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
static constexpr int kStandardizedGenerator = 2;
|
||||
@@ -363,14 +363,14 @@ Maybe<bool> DhKeyGenTraits::AdditionalConfig(
|
||||
int size = args[*offset].As<Int32>()->Value();
|
||||
if (size < 0) {
|
||||
THROW_ERR_OUT_OF_RANGE(env, "Invalid prime size");
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
params->params.prime = size;
|
||||
} else {
|
||||
ArrayBufferOrViewContents<unsigned char> input(args[*offset]);
|
||||
if (UNLIKELY(!input.CheckSizeInt32())) {
|
||||
THROW_ERR_OUT_OF_RANGE(env, "prime is too big");
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
params->params.prime = BignumPointer(input.data(), input.size());
|
||||
}
|
||||
@@ -380,7 +380,7 @@ Maybe<bool> DhKeyGenTraits::AdditionalConfig(
|
||||
*offset += 2;
|
||||
}
|
||||
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
EVPKeyCtxPointer DhKeyGenTraits::Setup(DhKeyPairGenConfig* params) {
|
||||
@@ -424,11 +424,11 @@ EVPKeyCtxPointer DhKeyGenTraits::Setup(DhKeyPairGenConfig* params) {
|
||||
return ctx;
|
||||
}
|
||||
|
||||
Maybe<bool> DHKeyExportTraits::AdditionalConfig(
|
||||
Maybe<void> DHKeyExportTraits::AdditionalConfig(
|
||||
const FunctionCallbackInfo<Value>& args,
|
||||
unsigned int offset,
|
||||
DHKeyExportConfig* params) {
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
WebCryptoKeyExportStatus DHKeyExportTraits::DoExport(
|
||||
@@ -487,7 +487,7 @@ void Stateless(const FunctionCallbackInfo<Value>& args) {
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Maybe<bool> DHBitsTraits::AdditionalConfig(
|
||||
Maybe<void> DHBitsTraits::AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const FunctionCallbackInfo<Value>& args,
|
||||
unsigned int offset,
|
||||
@@ -500,28 +500,25 @@ Maybe<bool> DHBitsTraits::AdditionalConfig(
|
||||
KeyObjectHandle* private_key;
|
||||
KeyObjectHandle* public_key;
|
||||
|
||||
ASSIGN_OR_RETURN_UNWRAP(&public_key, args[offset], Nothing<bool>());
|
||||
ASSIGN_OR_RETURN_UNWRAP(&private_key, args[offset + 1], Nothing<bool>());
|
||||
ASSIGN_OR_RETURN_UNWRAP(&public_key, args[offset], Nothing<void>());
|
||||
ASSIGN_OR_RETURN_UNWRAP(&private_key, args[offset + 1], Nothing<void>());
|
||||
|
||||
if (private_key->Data().GetKeyType() != kKeyTypePrivate ||
|
||||
public_key->Data().GetKeyType() != kKeyTypePublic) {
|
||||
THROW_ERR_CRYPTO_INVALID_KEYTYPE(env);
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
params->public_key = public_key->Data().addRef();
|
||||
params->private_key = private_key->Data().addRef();
|
||||
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
Maybe<bool> DHBitsTraits::EncodeOutput(
|
||||
Environment* env,
|
||||
const DHBitsConfig& params,
|
||||
ByteSource* out,
|
||||
v8::Local<v8::Value>* result) {
|
||||
*result = out->ToArrayBuffer(env);
|
||||
return Just(!result->IsEmpty());
|
||||
MaybeLocal<Value> DHBitsTraits::EncodeOutput(Environment* env,
|
||||
const DHBitsConfig& params,
|
||||
ByteSource* out) {
|
||||
return out->ToArrayBuffer(env);
|
||||
}
|
||||
|
||||
bool DHBitsTraits::DeriveBits(
|
||||
@@ -533,11 +530,11 @@ bool DHBitsTraits::DeriveBits(
|
||||
return true;
|
||||
}
|
||||
|
||||
Maybe<bool> GetDhKeyDetail(Environment* env,
|
||||
Maybe<void> GetDhKeyDetail(Environment* env,
|
||||
const KeyObjectData& key,
|
||||
Local<Object> target) {
|
||||
CHECK_EQ(EVP_PKEY_id(key.GetAsymmetricKey().get()), EVP_PKEY_DH);
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
void DiffieHellman::Initialize(Environment* env, Local<Object> target) {
|
||||
|
||||
@@ -49,7 +49,7 @@ struct DhKeyGenTraits final {
|
||||
|
||||
static EVPKeyCtxPointer Setup(DhKeyPairGenConfig* params);
|
||||
|
||||
static v8::Maybe<bool> AdditionalConfig(
|
||||
static v8::Maybe<void> AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args,
|
||||
unsigned int* offset,
|
||||
@@ -68,7 +68,7 @@ struct DHKeyExportTraits final {
|
||||
static constexpr const char* JobName = "DHKeyExportJob";
|
||||
using AdditionalParameters = DHKeyExportConfig;
|
||||
|
||||
static v8::Maybe<bool> AdditionalConfig(
|
||||
static v8::Maybe<void> AdditionalConfig(
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args,
|
||||
unsigned int offset,
|
||||
DHKeyExportConfig* config);
|
||||
@@ -95,7 +95,7 @@ struct DHBitsTraits final {
|
||||
static constexpr AsyncWrap::ProviderType Provider =
|
||||
AsyncWrap::PROVIDER_DERIVEBITSREQUEST;
|
||||
|
||||
static v8::Maybe<bool> AdditionalConfig(
|
||||
static v8::Maybe<void> AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args,
|
||||
unsigned int offset,
|
||||
@@ -106,16 +106,14 @@ struct DHBitsTraits final {
|
||||
const DHBitsConfig& params,
|
||||
ByteSource* out_);
|
||||
|
||||
static v8::Maybe<bool> EncodeOutput(
|
||||
Environment* env,
|
||||
const DHBitsConfig& params,
|
||||
ByteSource* out,
|
||||
v8::Local<v8::Value>* result);
|
||||
static v8::MaybeLocal<v8::Value> EncodeOutput(Environment* env,
|
||||
const DHBitsConfig& params,
|
||||
ByteSource* out);
|
||||
};
|
||||
|
||||
using DHBitsJob = DeriveBitsJob<DHBitsTraits>;
|
||||
|
||||
v8::Maybe<bool> GetDhKeyDetail(Environment* env,
|
||||
v8::Maybe<void> GetDhKeyDetail(Environment* env,
|
||||
const KeyObjectData& key,
|
||||
v8::Local<v8::Object> target);
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace node {
|
||||
|
||||
using v8::FunctionCallbackInfo;
|
||||
using v8::Int32;
|
||||
using v8::Just;
|
||||
using v8::JustVoid;
|
||||
using v8::Local;
|
||||
using v8::Maybe;
|
||||
using v8::Nothing;
|
||||
@@ -78,7 +78,7 @@ EVPKeyCtxPointer DsaKeyGenTraits::Setup(DsaKeyPairGenConfig* params) {
|
||||
// 7. Private Type
|
||||
// 8. Cipher
|
||||
// 9. Passphrase
|
||||
Maybe<bool> DsaKeyGenTraits::AdditionalConfig(
|
||||
Maybe<void> DsaKeyGenTraits::AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const FunctionCallbackInfo<Value>& args,
|
||||
unsigned int* offset,
|
||||
@@ -92,14 +92,14 @@ Maybe<bool> DsaKeyGenTraits::AdditionalConfig(
|
||||
|
||||
*offset += 2;
|
||||
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
Maybe<bool> DSAKeyExportTraits::AdditionalConfig(
|
||||
Maybe<void> DSAKeyExportTraits::AdditionalConfig(
|
||||
const FunctionCallbackInfo<Value>& args,
|
||||
unsigned int offset,
|
||||
DSAKeyExportConfig* params) {
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
WebCryptoKeyExportStatus DSAKeyExportTraits::DoExport(
|
||||
@@ -126,7 +126,7 @@ WebCryptoKeyExportStatus DSAKeyExportTraits::DoExport(
|
||||
}
|
||||
}
|
||||
|
||||
Maybe<bool> GetDsaKeyDetail(Environment* env,
|
||||
Maybe<void> GetDsaKeyDetail(Environment* env,
|
||||
const KeyObjectData& key,
|
||||
Local<Object> target) {
|
||||
const BIGNUM* p; // Modulus length
|
||||
@@ -157,10 +157,10 @@ Maybe<bool> GetDsaKeyDetail(Environment* env,
|
||||
env->divisor_length_string(),
|
||||
Number::New(env->isolate(), static_cast<double>(divisor_length)))
|
||||
.IsNothing()) {
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
namespace DSAAlg {
|
||||
|
||||
@@ -28,7 +28,7 @@ struct DsaKeyGenTraits final {
|
||||
|
||||
static EVPKeyCtxPointer Setup(DsaKeyPairGenConfig* params);
|
||||
|
||||
static v8::Maybe<bool> AdditionalConfig(
|
||||
static v8::Maybe<void> AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args,
|
||||
unsigned int* offset,
|
||||
@@ -47,7 +47,7 @@ struct DSAKeyExportTraits final {
|
||||
static constexpr const char* JobName = "DSAKeyExportJob";
|
||||
using AdditionalParameters = DSAKeyExportConfig;
|
||||
|
||||
static v8::Maybe<bool> AdditionalConfig(
|
||||
static v8::Maybe<void> AdditionalConfig(
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args,
|
||||
unsigned int offset,
|
||||
DSAKeyExportConfig* config);
|
||||
@@ -60,7 +60,7 @@ struct DSAKeyExportTraits final {
|
||||
|
||||
using DSAKeyExportJob = KeyExportJob<DSAKeyExportTraits>;
|
||||
|
||||
v8::Maybe<bool> GetDsaKeyDetail(Environment* env,
|
||||
v8::Maybe<void> GetDsaKeyDetail(Environment* env,
|
||||
const KeyObjectData& key,
|
||||
v8::Local<v8::Object> target);
|
||||
|
||||
|
||||
+25
-24
@@ -26,10 +26,10 @@ using v8::FunctionCallbackInfo;
|
||||
using v8::FunctionTemplate;
|
||||
using v8::Int32;
|
||||
using v8::Isolate;
|
||||
using v8::Just;
|
||||
using v8::JustVoid;
|
||||
using v8::Local;
|
||||
using v8::Maybe;
|
||||
using v8::MaybeLocal;
|
||||
using v8::Nothing;
|
||||
using v8::Object;
|
||||
using v8::String;
|
||||
@@ -437,16 +437,13 @@ void ECDHBitsConfig::MemoryInfo(MemoryTracker* tracker) const {
|
||||
tracker->TrackField("private", private_);
|
||||
}
|
||||
|
||||
Maybe<bool> ECDHBitsTraits::EncodeOutput(
|
||||
Environment* env,
|
||||
const ECDHBitsConfig& params,
|
||||
ByteSource* out,
|
||||
v8::Local<v8::Value>* result) {
|
||||
*result = out->ToArrayBuffer(env);
|
||||
return Just(!result->IsEmpty());
|
||||
MaybeLocal<Value> ECDHBitsTraits::EncodeOutput(Environment* env,
|
||||
const ECDHBitsConfig& params,
|
||||
ByteSource* out) {
|
||||
return out->ToArrayBuffer(env);
|
||||
}
|
||||
|
||||
Maybe<bool> ECDHBitsTraits::AdditionalConfig(
|
||||
Maybe<void> ECDHBitsTraits::AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const FunctionCallbackInfo<Value>& args,
|
||||
unsigned int offset,
|
||||
@@ -462,20 +459,20 @@ Maybe<bool> ECDHBitsTraits::AdditionalConfig(
|
||||
|
||||
Utf8Value name(env->isolate(), args[offset]);
|
||||
|
||||
ASSIGN_OR_RETURN_UNWRAP(&public_key, args[offset + 1], Nothing<bool>());
|
||||
ASSIGN_OR_RETURN_UNWRAP(&private_key, args[offset + 2], Nothing<bool>());
|
||||
ASSIGN_OR_RETURN_UNWRAP(&public_key, args[offset + 1], Nothing<void>());
|
||||
ASSIGN_OR_RETURN_UNWRAP(&private_key, args[offset + 2], Nothing<void>());
|
||||
|
||||
if (private_key->Data().GetKeyType() != kKeyTypePrivate ||
|
||||
public_key->Data().GetKeyType() != kKeyTypePublic) {
|
||||
THROW_ERR_CRYPTO_INVALID_KEYTYPE(env);
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
params->id_ = GetOKPCurveFromName(*name);
|
||||
params->private_ = private_key->Data().addRef();
|
||||
params->public_ = public_key->Data().addRef();
|
||||
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
bool ECDHBitsTraits::DeriveBits(Environment* env,
|
||||
@@ -591,7 +588,7 @@ EVPKeyCtxPointer EcKeyGenTraits::Setup(EcKeyPairGenConfig* params) {
|
||||
// 7. Private Type
|
||||
// 8. Cipher
|
||||
// 9. Passphrase
|
||||
Maybe<bool> EcKeyGenTraits::AdditionalConfig(
|
||||
Maybe<void> EcKeyGenTraits::AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const FunctionCallbackInfo<Value>& args,
|
||||
unsigned int* offset,
|
||||
@@ -604,19 +601,19 @@ Maybe<bool> EcKeyGenTraits::AdditionalConfig(
|
||||
params->params.curve_nid = GetCurveFromName(*curve_name);
|
||||
if (params->params.curve_nid == NID_undef) {
|
||||
THROW_ERR_CRYPTO_INVALID_CURVE(env);
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
params->params.param_encoding = args[*offset + 1].As<Int32>()->Value();
|
||||
if (params->params.param_encoding != OPENSSL_EC_NAMED_CURVE &&
|
||||
params->params.param_encoding != OPENSSL_EC_EXPLICIT_CURVE) {
|
||||
THROW_ERR_OUT_OF_RANGE(env, "Invalid param_encoding specified");
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
*offset += 2;
|
||||
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
namespace {
|
||||
@@ -677,11 +674,11 @@ WebCryptoKeyExportStatus EC_Raw_Export(const KeyObjectData& key_data,
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Maybe<bool> ECKeyExportTraits::AdditionalConfig(
|
||||
Maybe<void> ECKeyExportTraits::AdditionalConfig(
|
||||
const FunctionCallbackInfo<Value>& args,
|
||||
unsigned int offset,
|
||||
ECKeyExportConfig* params) {
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
WebCryptoKeyExportStatus ECKeyExportTraits::DoExport(
|
||||
@@ -968,7 +965,7 @@ KeyObjectData ImportJWKEcKey(Environment* env,
|
||||
return KeyObjectData::CreateAsymmetric(type, std::move(pkey));
|
||||
}
|
||||
|
||||
Maybe<bool> GetEcKeyDetail(Environment* env,
|
||||
Maybe<void> GetEcKeyDetail(Environment* env,
|
||||
const KeyObjectData& key,
|
||||
Local<Object> target) {
|
||||
Mutex::ScopedLock lock(key.mutex());
|
||||
@@ -981,10 +978,14 @@ Maybe<bool> GetEcKeyDetail(Environment* env,
|
||||
const EC_GROUP* group = EC_KEY_get0_group(ec);
|
||||
int nid = EC_GROUP_get_curve_name(group);
|
||||
|
||||
return target->Set(
|
||||
env->context(),
|
||||
env->named_curve_string(),
|
||||
OneByteString(env->isolate(), OBJ_nid2sn(nid)));
|
||||
if (target
|
||||
->Set(env->context(),
|
||||
env->named_curve_string(),
|
||||
OneByteString(env->isolate(), OBJ_nid2sn(nid)))
|
||||
.IsNothing()) {
|
||||
return Nothing<void>();
|
||||
}
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
// WebCrypto requires a different format for ECDSA signatures than
|
||||
|
||||
@@ -71,7 +71,7 @@ struct ECDHBitsTraits final {
|
||||
static constexpr AsyncWrap::ProviderType Provider =
|
||||
AsyncWrap::PROVIDER_DERIVEBITSREQUEST;
|
||||
|
||||
static v8::Maybe<bool> AdditionalConfig(
|
||||
static v8::Maybe<void> AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args,
|
||||
unsigned int offset,
|
||||
@@ -82,11 +82,9 @@ struct ECDHBitsTraits final {
|
||||
const ECDHBitsConfig& params,
|
||||
ByteSource* out_);
|
||||
|
||||
static v8::Maybe<bool> EncodeOutput(
|
||||
Environment* env,
|
||||
const ECDHBitsConfig& params,
|
||||
ByteSource* out,
|
||||
v8::Local<v8::Value>* result);
|
||||
static v8::MaybeLocal<v8::Value> EncodeOutput(Environment* env,
|
||||
const ECDHBitsConfig& params,
|
||||
ByteSource* out);
|
||||
};
|
||||
|
||||
using ECDHBitsJob = DeriveBitsJob<ECDHBitsTraits>;
|
||||
@@ -107,7 +105,7 @@ struct EcKeyGenTraits final {
|
||||
|
||||
static EVPKeyCtxPointer Setup(EcKeyPairGenConfig* params);
|
||||
|
||||
static v8::Maybe<bool> AdditionalConfig(
|
||||
static v8::Maybe<void> AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args,
|
||||
unsigned int* offset,
|
||||
@@ -129,7 +127,7 @@ struct ECKeyExportTraits final {
|
||||
static constexpr const char* JobName = "ECKeyExportJob";
|
||||
using AdditionalParameters = ECKeyExportConfig;
|
||||
|
||||
static v8::Maybe<bool> AdditionalConfig(
|
||||
static v8::Maybe<void> AdditionalConfig(
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args,
|
||||
unsigned int offset,
|
||||
ECKeyExportConfig* config);
|
||||
@@ -155,7 +153,7 @@ KeyObjectData ImportJWKEcKey(Environment* env,
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args,
|
||||
unsigned int offset);
|
||||
|
||||
v8::Maybe<bool> GetEcKeyDetail(Environment* env,
|
||||
v8::Maybe<void> GetEcKeyDetail(Environment* env,
|
||||
const KeyObjectData& key,
|
||||
v8::Local<v8::Object> target);
|
||||
} // namespace crypto
|
||||
|
||||
+10
-12
@@ -17,6 +17,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;
|
||||
@@ -448,16 +449,13 @@ void HashConfig::MemoryInfo(MemoryTracker* tracker) const {
|
||||
tracker->TrackFieldWithSize("in", in.size());
|
||||
}
|
||||
|
||||
Maybe<bool> HashTraits::EncodeOutput(
|
||||
Environment* env,
|
||||
const HashConfig& params,
|
||||
ByteSource* out,
|
||||
v8::Local<v8::Value>* result) {
|
||||
*result = out->ToArrayBuffer(env);
|
||||
return Just(!result->IsEmpty());
|
||||
MaybeLocal<Value> HashTraits::EncodeOutput(Environment* env,
|
||||
const HashConfig& params,
|
||||
ByteSource* out) {
|
||||
return out->ToArrayBuffer(env);
|
||||
}
|
||||
|
||||
Maybe<bool> HashTraits::AdditionalConfig(
|
||||
Maybe<void> HashTraits::AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const FunctionCallbackInfo<Value>& args,
|
||||
unsigned int offset,
|
||||
@@ -471,13 +469,13 @@ Maybe<bool> HashTraits::AdditionalConfig(
|
||||
params->digest = EVP_get_digestbyname(*digest);
|
||||
if (UNLIKELY(params->digest == nullptr)) {
|
||||
THROW_ERR_CRYPTO_INVALID_DIGEST(env, "Invalid digest: %s", *digest);
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
ArrayBufferOrViewContents<char> data(args[offset + 1]);
|
||||
if (UNLIKELY(!data.CheckSizeInt32())) {
|
||||
THROW_ERR_OUT_OF_RANGE(env, "data is too big");
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
params->in = mode == kCryptoJobAsync
|
||||
? data.ToCopy()
|
||||
@@ -493,12 +491,12 @@ Maybe<bool> HashTraits::AdditionalConfig(
|
||||
if (params->length != expected) {
|
||||
if ((EVP_MD_flags(params->digest) & EVP_MD_FLAG_XOF) == 0) {
|
||||
THROW_ERR_CRYPTO_INVALID_DIGEST(env, "Digest method not supported");
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
bool HashTraits::DeriveBits(
|
||||
|
||||
@@ -64,7 +64,7 @@ struct HashTraits final {
|
||||
static constexpr AsyncWrap::ProviderType Provider =
|
||||
AsyncWrap::PROVIDER_HASHREQUEST;
|
||||
|
||||
static v8::Maybe<bool> AdditionalConfig(
|
||||
static v8::Maybe<void> AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args,
|
||||
unsigned int offset,
|
||||
@@ -75,11 +75,9 @@ struct HashTraits final {
|
||||
const HashConfig& params,
|
||||
ByteSource* out);
|
||||
|
||||
static v8::Maybe<bool> EncodeOutput(
|
||||
Environment* env,
|
||||
const HashConfig& params,
|
||||
ByteSource* out,
|
||||
v8::Local<v8::Value>* result);
|
||||
static v8::MaybeLocal<v8::Value> EncodeOutput(Environment* env,
|
||||
const HashConfig& params,
|
||||
ByteSource* out);
|
||||
};
|
||||
|
||||
using HashJob = DeriveBitsJob<HashTraits>;
|
||||
|
||||
+13
-15
@@ -10,8 +10,9 @@
|
||||
namespace node {
|
||||
|
||||
using v8::FunctionCallbackInfo;
|
||||
using v8::Just;
|
||||
using v8::JustVoid;
|
||||
using v8::Maybe;
|
||||
using v8::MaybeLocal;
|
||||
using v8::Nothing;
|
||||
using v8::Uint32;
|
||||
using v8::Value;
|
||||
@@ -31,16 +32,13 @@ HKDFConfig& HKDFConfig::operator=(HKDFConfig&& other) noexcept {
|
||||
return *new (this) HKDFConfig(std::move(other));
|
||||
}
|
||||
|
||||
Maybe<bool> HKDFTraits::EncodeOutput(
|
||||
Environment* env,
|
||||
const HKDFConfig& params,
|
||||
ByteSource* out,
|
||||
v8::Local<v8::Value>* result) {
|
||||
*result = out->ToArrayBuffer(env);
|
||||
return Just(!result->IsEmpty());
|
||||
MaybeLocal<Value> HKDFTraits::EncodeOutput(Environment* env,
|
||||
const HKDFConfig& params,
|
||||
ByteSource* out) {
|
||||
return out->ToArrayBuffer(env);
|
||||
}
|
||||
|
||||
Maybe<bool> HKDFTraits::AdditionalConfig(
|
||||
Maybe<void> HKDFTraits::AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const FunctionCallbackInfo<Value>& args,
|
||||
unsigned int offset,
|
||||
@@ -59,11 +57,11 @@ Maybe<bool> HKDFTraits::AdditionalConfig(
|
||||
params->digest = ncrypto::getDigestByName(hash.ToStringView());
|
||||
if (params->digest == nullptr) {
|
||||
THROW_ERR_CRYPTO_INVALID_DIGEST(env, "Invalid digest: %s", *hash);
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
KeyObjectHandle* key;
|
||||
ASSIGN_OR_RETURN_UNWRAP(&key, args[offset + 1], Nothing<bool>());
|
||||
ASSIGN_OR_RETURN_UNWRAP(&key, args[offset + 1], Nothing<void>());
|
||||
params->key = key->Data().addRef();
|
||||
|
||||
ArrayBufferOrViewContents<char> salt(args[offset + 2]);
|
||||
@@ -71,11 +69,11 @@ Maybe<bool> HKDFTraits::AdditionalConfig(
|
||||
|
||||
if (UNLIKELY(!salt.CheckSizeInt32())) {
|
||||
THROW_ERR_OUT_OF_RANGE(env, "salt is too big");
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
if (UNLIKELY(!info.CheckSizeInt32())) {
|
||||
THROW_ERR_OUT_OF_RANGE(env, "info is too big");
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
params->salt = mode == kCryptoJobAsync
|
||||
@@ -92,10 +90,10 @@ Maybe<bool> HKDFTraits::AdditionalConfig(
|
||||
// 8-bit counter to each HMAC'd message, starting at 1.
|
||||
if (!ncrypto::checkHkdfLength(params->digest, params->length)) {
|
||||
THROW_ERR_CRYPTO_INVALID_KEYLEN(env);
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
bool HKDFTraits::DeriveBits(
|
||||
|
||||
@@ -36,7 +36,7 @@ struct HKDFTraits final {
|
||||
static constexpr AsyncWrap::ProviderType Provider =
|
||||
AsyncWrap::PROVIDER_DERIVEBITSREQUEST;
|
||||
|
||||
static v8::Maybe<bool> AdditionalConfig(
|
||||
static v8::Maybe<void> AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args,
|
||||
unsigned int offset,
|
||||
@@ -47,11 +47,9 @@ struct HKDFTraits final {
|
||||
const HKDFConfig& params,
|
||||
ByteSource* out);
|
||||
|
||||
static v8::Maybe<bool> EncodeOutput(
|
||||
Environment* env,
|
||||
const HKDFConfig& params,
|
||||
ByteSource* out,
|
||||
v8::Local<v8::Value>* result);
|
||||
static v8::MaybeLocal<v8::Value> EncodeOutput(Environment* env,
|
||||
const HKDFConfig& params,
|
||||
ByteSource* out);
|
||||
};
|
||||
|
||||
using HKDFJob = DeriveBitsJob<HKDFTraits>;
|
||||
|
||||
+13
-19
@@ -18,7 +18,7 @@ using v8::FunctionCallbackInfo;
|
||||
using v8::FunctionTemplate;
|
||||
using v8::HandleScope;
|
||||
using v8::Isolate;
|
||||
using v8::Just;
|
||||
using v8::JustVoid;
|
||||
using v8::Local;
|
||||
using v8::Maybe;
|
||||
using v8::MaybeLocal;
|
||||
@@ -170,7 +170,7 @@ void HmacConfig::MemoryInfo(MemoryTracker* tracker) const {
|
||||
}
|
||||
}
|
||||
|
||||
Maybe<bool> HmacTraits::AdditionalConfig(
|
||||
Maybe<void> HmacTraits::AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const FunctionCallbackInfo<Value>& args,
|
||||
unsigned int offset,
|
||||
@@ -190,17 +190,17 @@ Maybe<bool> HmacTraits::AdditionalConfig(
|
||||
params->digest = EVP_get_digestbyname(*digest);
|
||||
if (params->digest == nullptr) {
|
||||
THROW_ERR_CRYPTO_INVALID_DIGEST(env, "Invalid digest: %s", *digest);
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
KeyObjectHandle* key;
|
||||
ASSIGN_OR_RETURN_UNWRAP(&key, args[offset + 2], Nothing<bool>());
|
||||
ASSIGN_OR_RETURN_UNWRAP(&key, args[offset + 2], Nothing<void>());
|
||||
params->key = key->Data().addRef();
|
||||
|
||||
ArrayBufferOrViewContents<char> data(args[offset + 3]);
|
||||
if (UNLIKELY(!data.CheckSizeInt32())) {
|
||||
THROW_ERR_OUT_OF_RANGE(env, "data is too big");
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
params->data = mode == kCryptoJobAsync
|
||||
? data.ToCopy()
|
||||
@@ -210,14 +210,14 @@ Maybe<bool> HmacTraits::AdditionalConfig(
|
||||
ArrayBufferOrViewContents<char> signature(args[offset + 4]);
|
||||
if (UNLIKELY(!signature.CheckSizeInt32())) {
|
||||
THROW_ERR_OUT_OF_RANGE(env, "signature is too big");
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
params->signature = mode == kCryptoJobAsync
|
||||
? signature.ToCopy()
|
||||
: signature.ToByteSource();
|
||||
}
|
||||
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
bool HmacTraits::DeriveBits(
|
||||
@@ -253,25 +253,19 @@ bool HmacTraits::DeriveBits(
|
||||
return true;
|
||||
}
|
||||
|
||||
Maybe<bool> HmacTraits::EncodeOutput(
|
||||
Environment* env,
|
||||
const HmacConfig& params,
|
||||
ByteSource* out,
|
||||
Local<Value>* result) {
|
||||
MaybeLocal<Value> HmacTraits::EncodeOutput(Environment* env,
|
||||
const HmacConfig& params,
|
||||
ByteSource* out) {
|
||||
switch (params.mode) {
|
||||
case SignConfiguration::kSign:
|
||||
*result = out->ToArrayBuffer(env);
|
||||
break;
|
||||
return out->ToArrayBuffer(env);
|
||||
case SignConfiguration::kVerify:
|
||||
*result = Boolean::New(
|
||||
return Boolean::New(
|
||||
env->isolate(),
|
||||
out->size() > 0 && out->size() == params.signature.size() &&
|
||||
memcmp(out->data(), params.signature.data(), out->size()) == 0);
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
return Just(!result->IsEmpty());
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
} // namespace crypto
|
||||
|
||||
@@ -67,7 +67,7 @@ struct HmacTraits final {
|
||||
static constexpr AsyncWrap::ProviderType Provider =
|
||||
AsyncWrap::PROVIDER_SIGNREQUEST;
|
||||
|
||||
static v8::Maybe<bool> AdditionalConfig(
|
||||
static v8::Maybe<void> AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args,
|
||||
unsigned int offset,
|
||||
@@ -78,11 +78,9 @@ struct HmacTraits final {
|
||||
const HmacConfig& params,
|
||||
ByteSource* out);
|
||||
|
||||
static v8::Maybe<bool> EncodeOutput(
|
||||
Environment* env,
|
||||
const HmacConfig& params,
|
||||
ByteSource* out,
|
||||
v8::Local<v8::Value>* result);
|
||||
static v8::MaybeLocal<v8::Value> EncodeOutput(Environment* env,
|
||||
const HmacConfig& params,
|
||||
ByteSource* out);
|
||||
};
|
||||
|
||||
using HmacJob = DeriveBitsJob<HmacTraits>;
|
||||
|
||||
@@ -14,9 +14,10 @@ namespace node {
|
||||
|
||||
using v8::FunctionCallbackInfo;
|
||||
using v8::Int32;
|
||||
using v8::Just;
|
||||
using v8::JustVoid;
|
||||
using v8::Local;
|
||||
using v8::Maybe;
|
||||
using v8::MaybeLocal;
|
||||
using v8::Object;
|
||||
using v8::Uint32;
|
||||
using v8::Value;
|
||||
@@ -31,7 +32,7 @@ namespace crypto {
|
||||
// 6. Private Type
|
||||
// 7. Cipher
|
||||
// 8. Passphrase
|
||||
Maybe<bool> NidKeyPairGenTraits::AdditionalConfig(
|
||||
Maybe<void> NidKeyPairGenTraits::AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const FunctionCallbackInfo<Value>& args,
|
||||
unsigned int* offset,
|
||||
@@ -41,7 +42,7 @@ Maybe<bool> NidKeyPairGenTraits::AdditionalConfig(
|
||||
|
||||
*offset += 1;
|
||||
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
EVPKeyCtxPointer NidKeyPairGenTraits::Setup(NidKeyPairGenConfig* params) {
|
||||
@@ -57,7 +58,7 @@ void SecretKeyGenConfig::MemoryInfo(MemoryTracker* tracker) const {
|
||||
if (out) tracker->TrackFieldWithSize("out", length);
|
||||
}
|
||||
|
||||
Maybe<bool> SecretKeyGenTraits::AdditionalConfig(
|
||||
Maybe<void> SecretKeyGenTraits::AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const FunctionCallbackInfo<Value>& args,
|
||||
unsigned int* offset,
|
||||
@@ -66,7 +67,7 @@ Maybe<bool> SecretKeyGenTraits::AdditionalConfig(
|
||||
uint32_t bits = args[*offset].As<Uint32>()->Value();
|
||||
params->length = bits / CHAR_BIT;
|
||||
*offset += 1;
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
KeyGenJobStatus SecretKeyGenTraits::DoKeyGen(Environment* env,
|
||||
@@ -78,11 +79,14 @@ 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) {
|
||||
auto 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 {
|
||||
|
||||
+30
-28
@@ -91,26 +91,33 @@ class KeyGenJob final : public CryptoJob<KeyGenTraits> {
|
||||
}
|
||||
}
|
||||
|
||||
v8::Maybe<bool> ToResult(
|
||||
v8::Local<v8::Value>* err,
|
||||
v8::Local<v8::Value>* result) override {
|
||||
v8::Maybe<void> ToResult(v8::Local<v8::Value>* err,
|
||||
v8::Local<v8::Value>* result) override {
|
||||
Environment* env = AsyncWrap::env();
|
||||
CryptoErrorStore* errors = CryptoJob<KeyGenTraits>::errors();
|
||||
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();
|
||||
}
|
||||
} else {
|
||||
if (errors->Empty()) errors->Capture();
|
||||
CHECK(!errors->Empty());
|
||||
*result = Undefined(env->isolate());
|
||||
if (!errors->ToException(env).ToLocal(err)) {
|
||||
return v8::Nothing<void>();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (errors->Empty())
|
||||
errors->Capture();
|
||||
CHECK(!errors->Empty());
|
||||
*result = Undefined(env->isolate());
|
||||
return v8::Just(errors->ToException(env).ToLocal(err));
|
||||
CHECK(!result->IsEmpty());
|
||||
CHECK(!err->IsEmpty());
|
||||
return v8::JustVoid();
|
||||
}
|
||||
|
||||
SET_SELF_SIZE(KeyGenJob)
|
||||
@@ -129,7 +136,7 @@ struct KeyPairGenTraits final {
|
||||
AsyncWrap::PROVIDER_KEYPAIRGENREQUEST;
|
||||
static constexpr const char* JobName = KeyPairAlgorithmTraits::JobName;
|
||||
|
||||
static v8::Maybe<bool> AdditionalConfig(
|
||||
static v8::Maybe<void> AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args,
|
||||
unsigned int* offset,
|
||||
@@ -141,7 +148,7 @@ struct KeyPairGenTraits final {
|
||||
// number of input parameters specific to each job type.
|
||||
if (KeyPairAlgorithmTraits::AdditionalConfig(mode, args, offset, params)
|
||||
.IsNothing()) {
|
||||
return v8::Just(false);
|
||||
return v8::Nothing<void>();
|
||||
}
|
||||
|
||||
params->public_key_encoding = KeyObjectData::GetPublicKeyEncodingFromJs(
|
||||
@@ -153,7 +160,7 @@ struct KeyPairGenTraits final {
|
||||
if (!private_key_encoding.IsEmpty())
|
||||
params->private_key_encoding = private_key_encoding.Release();
|
||||
|
||||
return v8::Just(true);
|
||||
return v8::JustVoid();
|
||||
}
|
||||
|
||||
static KeyGenJobStatus DoKeyGen(
|
||||
@@ -176,10 +183,8 @@ struct KeyPairGenTraits final {
|
||||
return KeyGenJobStatus::OK;
|
||||
}
|
||||
|
||||
static v8::Maybe<bool> EncodeKey(
|
||||
Environment* env,
|
||||
AdditionalParameters* params,
|
||||
v8::Local<v8::Value>* result) {
|
||||
static v8::MaybeLocal<v8::Value> EncodeKey(Environment* env,
|
||||
AdditionalParameters* params) {
|
||||
v8::Local<v8::Value> keys[2];
|
||||
if (params->key
|
||||
.ToEncodedPublicKey(env, params->public_key_encoding, &keys[0])
|
||||
@@ -187,10 +192,9 @@ struct KeyPairGenTraits final {
|
||||
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));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -209,7 +213,7 @@ struct SecretKeyGenTraits final {
|
||||
AsyncWrap::PROVIDER_KEYGENREQUEST;
|
||||
static constexpr const char* JobName = "SecretKeyGenJob";
|
||||
|
||||
static v8::Maybe<bool> AdditionalConfig(
|
||||
static v8::Maybe<void> AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args,
|
||||
unsigned int* offset,
|
||||
@@ -219,10 +223,8 @@ struct SecretKeyGenTraits final {
|
||||
Environment* env,
|
||||
SecretKeyGenConfig* params);
|
||||
|
||||
static v8::Maybe<bool> EncodeKey(
|
||||
Environment* env,
|
||||
SecretKeyGenConfig* params,
|
||||
v8::Local<v8::Value>* result);
|
||||
static v8::MaybeLocal<v8::Value> EncodeKey(Environment* env,
|
||||
SecretKeyGenConfig* params);
|
||||
};
|
||||
|
||||
template <typename AlgorithmParams>
|
||||
@@ -281,7 +283,7 @@ struct NidKeyPairGenTraits final {
|
||||
|
||||
static EVPKeyCtxPointer Setup(NidKeyPairGenConfig* params);
|
||||
|
||||
static v8::Maybe<bool> AdditionalConfig(
|
||||
static v8::Maybe<void> AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args,
|
||||
unsigned int* offset,
|
||||
|
||||
@@ -516,19 +516,23 @@ KeyObjectData ImportJWKAsymmetricKey(Environment* env,
|
||||
return {};
|
||||
}
|
||||
|
||||
Maybe<bool> GetSecretKeyDetail(Environment* env,
|
||||
Maybe<void> GetSecretKeyDetail(Environment* env,
|
||||
const KeyObjectData& key,
|
||||
Local<Object> target) {
|
||||
// For the secret key detail, all we care about is the length,
|
||||
// converted to bits.
|
||||
|
||||
size_t length = key.GetSymmetricKeySize() * CHAR_BIT;
|
||||
return target->Set(env->context(),
|
||||
env->length_string(),
|
||||
Number::New(env->isolate(), static_cast<double>(length)));
|
||||
if (target
|
||||
->Set(env->context(),
|
||||
env->length_string(),
|
||||
Number::New(env->isolate(), static_cast<double>(length)))
|
||||
.IsNothing()) {
|
||||
return Nothing<void>();
|
||||
}
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
Maybe<bool> GetAsymmetricKeyDetail(Environment* env,
|
||||
Maybe<void> GetAsymmetricKeyDetail(Environment* env,
|
||||
const KeyObjectData& key,
|
||||
Local<Object> target) {
|
||||
switch (EVP_PKEY_id(key.GetAsymmetricKey().get())) {
|
||||
@@ -540,7 +544,7 @@ Maybe<bool> GetAsymmetricKeyDetail(Environment* env,
|
||||
case EVP_PKEY_DH: return GetDhKeyDetail(env, key, target);
|
||||
}
|
||||
THROW_ERR_CRYPTO_INVALID_KEYTYPE(env);
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
+15
-10
@@ -362,23 +362,28 @@ class KeyExportJob final : public CryptoJob<KeyExportTraits> {
|
||||
}
|
||||
}
|
||||
|
||||
v8::Maybe<bool> ToResult(
|
||||
v8::Local<v8::Value>* err,
|
||||
v8::Local<v8::Value>* result) override {
|
||||
v8::Maybe<void> ToResult(v8::Local<v8::Value>* err,
|
||||
v8::Local<v8::Value>* result) override {
|
||||
Environment* env = AsyncWrap::env();
|
||||
CryptoErrorStore* errors = CryptoJob<KeyExportTraits>::errors();
|
||||
if (out_.size() > 0) {
|
||||
CHECK(errors->Empty());
|
||||
*err = v8::Undefined(env->isolate());
|
||||
*result = out_.ToArrayBuffer(env);
|
||||
return v8::Just(!result->IsEmpty());
|
||||
if (result->IsEmpty()) {
|
||||
return v8::Nothing<void>();
|
||||
}
|
||||
} else {
|
||||
if (errors->Empty()) errors->Capture();
|
||||
CHECK(!errors->Empty());
|
||||
*result = v8::Undefined(env->isolate());
|
||||
if (!errors->ToException(env).ToLocal(err)) {
|
||||
return v8::Nothing<void>();
|
||||
}
|
||||
}
|
||||
|
||||
if (errors->Empty())
|
||||
errors->Capture();
|
||||
CHECK(!errors->Empty());
|
||||
*result = v8::Undefined(env->isolate());
|
||||
return v8::Just(errors->ToException(env).ToLocal(err));
|
||||
CHECK(!result->IsEmpty());
|
||||
CHECK(!err->IsEmpty());
|
||||
return v8::JustVoid();
|
||||
}
|
||||
|
||||
SET_SELF_SIZE(KeyExportJob)
|
||||
|
||||
+13
-15
@@ -11,8 +11,9 @@ namespace node {
|
||||
|
||||
using v8::FunctionCallbackInfo;
|
||||
using v8::Int32;
|
||||
using v8::Just;
|
||||
using v8::JustVoid;
|
||||
using v8::Maybe;
|
||||
using v8::MaybeLocal;
|
||||
using v8::Nothing;
|
||||
using v8::Value;
|
||||
|
||||
@@ -39,13 +40,10 @@ void PBKDF2Config::MemoryInfo(MemoryTracker* tracker) const {
|
||||
}
|
||||
}
|
||||
|
||||
Maybe<bool> PBKDF2Traits::EncodeOutput(
|
||||
Environment* env,
|
||||
const PBKDF2Config& params,
|
||||
ByteSource* out,
|
||||
v8::Local<v8::Value>* result) {
|
||||
*result = out->ToArrayBuffer(env);
|
||||
return Just(!result->IsEmpty());
|
||||
MaybeLocal<Value> PBKDF2Traits::EncodeOutput(Environment* env,
|
||||
const PBKDF2Config& params,
|
||||
ByteSource* out) {
|
||||
return out->ToArrayBuffer(env);
|
||||
}
|
||||
|
||||
// The input arguments for the job are:
|
||||
@@ -55,7 +53,7 @@ Maybe<bool> PBKDF2Traits::EncodeOutput(
|
||||
// 4. The number of iterations
|
||||
// 5. The number of bytes to generate
|
||||
// 6. The digest algorithm name
|
||||
Maybe<bool> PBKDF2Traits::AdditionalConfig(
|
||||
Maybe<void> PBKDF2Traits::AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const FunctionCallbackInfo<Value>& args,
|
||||
unsigned int offset,
|
||||
@@ -69,12 +67,12 @@ Maybe<bool> PBKDF2Traits::AdditionalConfig(
|
||||
|
||||
if (UNLIKELY(!pass.CheckSizeInt32())) {
|
||||
THROW_ERR_OUT_OF_RANGE(env, "pass is too large");
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
if (UNLIKELY(!salt.CheckSizeInt32())) {
|
||||
THROW_ERR_OUT_OF_RANGE(env, "salt is too large");
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
params->pass = mode == kCryptoJobAsync
|
||||
@@ -92,23 +90,23 @@ Maybe<bool> PBKDF2Traits::AdditionalConfig(
|
||||
params->iterations = args[offset + 2].As<Int32>()->Value();
|
||||
if (params->iterations < 0) {
|
||||
THROW_ERR_OUT_OF_RANGE(env, "iterations must be <= %d", INT_MAX);
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
params->length = args[offset + 3].As<Int32>()->Value();
|
||||
if (params->length < 0) {
|
||||
THROW_ERR_OUT_OF_RANGE(env, "length must be <= %d", INT_MAX);
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
Utf8Value name(args.GetIsolate(), args[offset + 4]);
|
||||
params->digest = ncrypto::getDigestByName(name.ToStringView());
|
||||
if (params->digest == nullptr) {
|
||||
THROW_ERR_CRYPTO_INVALID_DIGEST(env, "Invalid digest: %s", *name);
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
bool PBKDF2Traits::DeriveBits(Environment* env,
|
||||
|
||||
@@ -49,7 +49,7 @@ struct PBKDF2Traits final {
|
||||
static constexpr AsyncWrap::ProviderType Provider =
|
||||
AsyncWrap::PROVIDER_PBKDF2REQUEST;
|
||||
|
||||
static v8::Maybe<bool> AdditionalConfig(
|
||||
static v8::Maybe<void> AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args,
|
||||
unsigned int offset,
|
||||
@@ -60,11 +60,9 @@ struct PBKDF2Traits final {
|
||||
const PBKDF2Config& params,
|
||||
ByteSource* out);
|
||||
|
||||
static v8::Maybe<bool> EncodeOutput(
|
||||
Environment* env,
|
||||
const PBKDF2Config& params,
|
||||
ByteSource* out,
|
||||
v8::Local<v8::Value>* result);
|
||||
static v8::MaybeLocal<v8::Value> EncodeOutput(Environment* env,
|
||||
const PBKDF2Config& params,
|
||||
ByteSource* out);
|
||||
};
|
||||
|
||||
using PBKDF2Job = DeriveBitsJob<PBKDF2Traits>;
|
||||
|
||||
+23
-33
@@ -18,25 +18,22 @@ using v8::BackingStore;
|
||||
using v8::Boolean;
|
||||
using v8::FunctionCallbackInfo;
|
||||
using v8::Int32;
|
||||
using v8::Just;
|
||||
using v8::JustVoid;
|
||||
using v8::Local;
|
||||
using v8::Maybe;
|
||||
using v8::MaybeLocal;
|
||||
using v8::Nothing;
|
||||
using v8::Object;
|
||||
using v8::Uint32;
|
||||
using v8::Value;
|
||||
|
||||
namespace crypto {
|
||||
Maybe<bool> RandomBytesTraits::EncodeOutput(
|
||||
Environment* env,
|
||||
const RandomBytesConfig& params,
|
||||
ByteSource* unused,
|
||||
v8::Local<v8::Value>* result) {
|
||||
*result = v8::Undefined(env->isolate());
|
||||
return Just(!result->IsEmpty());
|
||||
MaybeLocal<Value> RandomBytesTraits::EncodeOutput(
|
||||
Environment* env, const RandomBytesConfig& params, ByteSource* unused) {
|
||||
return v8::Undefined(env->isolate());
|
||||
}
|
||||
|
||||
Maybe<bool> RandomBytesTraits::AdditionalConfig(
|
||||
Maybe<void> RandomBytesTraits::AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const FunctionCallbackInfo<Value>& args,
|
||||
unsigned int offset,
|
||||
@@ -55,7 +52,7 @@ Maybe<bool> RandomBytesTraits::AdditionalConfig(
|
||||
params->buffer = in.data() + byte_offset;
|
||||
params->size = size;
|
||||
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
bool RandomBytesTraits::DeriveBits(
|
||||
@@ -69,11 +66,8 @@ void RandomPrimeConfig::MemoryInfo(MemoryTracker* tracker) const {
|
||||
tracker->TrackFieldWithSize("prime", prime ? bits * 8 : 0);
|
||||
}
|
||||
|
||||
Maybe<bool> RandomPrimeTraits::EncodeOutput(
|
||||
Environment* env,
|
||||
const RandomPrimeConfig& params,
|
||||
ByteSource* unused,
|
||||
v8::Local<v8::Value>* result) {
|
||||
MaybeLocal<Value> RandomPrimeTraits::EncodeOutput(
|
||||
Environment* env, const RandomPrimeConfig& params, ByteSource* unused) {
|
||||
size_t size = params.prime.byteLength();
|
||||
std::shared_ptr<BackingStore> store =
|
||||
ArrayBuffer::NewBackingStore(env->isolate(), size);
|
||||
@@ -82,11 +76,10 @@ Maybe<bool> RandomPrimeTraits::EncodeOutput(
|
||||
params.prime.get(),
|
||||
reinterpret_cast<unsigned char*>(store->Data()),
|
||||
size));
|
||||
*result = ArrayBuffer::New(env->isolate(), store);
|
||||
return Just(true);
|
||||
return ArrayBuffer::New(env->isolate(), store);
|
||||
}
|
||||
|
||||
Maybe<bool> RandomPrimeTraits::AdditionalConfig(
|
||||
Maybe<void> RandomPrimeTraits::AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const FunctionCallbackInfo<Value>& args,
|
||||
unsigned int offset,
|
||||
@@ -104,7 +97,7 @@ Maybe<bool> RandomPrimeTraits::AdditionalConfig(
|
||||
params->add.reset(add.data(), add.size());
|
||||
if (!params->add) {
|
||||
THROW_ERR_CRYPTO_OPERATION_FAILED(env, "could not generate prime");
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +106,7 @@ Maybe<bool> RandomPrimeTraits::AdditionalConfig(
|
||||
params->rem.reset(rem.data(), rem.size());
|
||||
if (!params->rem) {
|
||||
THROW_ERR_CRYPTO_OPERATION_FAILED(env, "could not generate prime");
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,14 +121,14 @@ Maybe<bool> RandomPrimeTraits::AdditionalConfig(
|
||||
// loop within OpenSSL, blocking the main thread or one of the threads
|
||||
// in the thread pool.
|
||||
THROW_ERR_OUT_OF_RANGE(env, "invalid options.add");
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
if (params->rem && params->add <= params->rem) {
|
||||
// This would definitely lead to an infinite loop if allowed since
|
||||
// OpenSSL does not check this condition.
|
||||
THROW_ERR_OUT_OF_RANGE(env, "invalid options.rem");
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,10 +137,10 @@ Maybe<bool> RandomPrimeTraits::AdditionalConfig(
|
||||
params->prime = BignumPointer::NewSecure();
|
||||
if (!params->prime) {
|
||||
THROW_ERR_CRYPTO_OPERATION_FAILED(env, "could not generate prime");
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
bool RandomPrimeTraits::DeriveBits(Environment* env,
|
||||
@@ -174,7 +167,7 @@ void CheckPrimeConfig::MemoryInfo(MemoryTracker* tracker) const {
|
||||
tracker->TrackFieldWithSize("prime", candidate ? candidate.byteLength() : 0);
|
||||
}
|
||||
|
||||
Maybe<bool> CheckPrimeTraits::AdditionalConfig(
|
||||
Maybe<void> CheckPrimeTraits::AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const FunctionCallbackInfo<Value>& args,
|
||||
unsigned int offset,
|
||||
@@ -187,7 +180,7 @@ Maybe<bool> CheckPrimeTraits::AdditionalConfig(
|
||||
params->checks = args[offset + 1].As<Int32>()->Value();
|
||||
CHECK_GE(params->checks, 0);
|
||||
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
bool CheckPrimeTraits::DeriveBits(
|
||||
@@ -209,13 +202,10 @@ bool CheckPrimeTraits::DeriveBits(
|
||||
return true;
|
||||
}
|
||||
|
||||
Maybe<bool> CheckPrimeTraits::EncodeOutput(
|
||||
Environment* env,
|
||||
const CheckPrimeConfig& params,
|
||||
ByteSource* out,
|
||||
v8::Local<v8::Value>* result) {
|
||||
*result = Boolean::New(env->isolate(), out->data<char>()[0] != 0);
|
||||
return Just(true);
|
||||
MaybeLocal<Value> CheckPrimeTraits::EncodeOutput(Environment* env,
|
||||
const CheckPrimeConfig& params,
|
||||
ByteSource* out) {
|
||||
return Boolean::New(env->isolate(), out->data<char>()[0] != 0);
|
||||
}
|
||||
|
||||
namespace Random {
|
||||
|
||||
+12
-18
@@ -26,7 +26,7 @@ struct RandomBytesTraits final {
|
||||
static constexpr AsyncWrap::ProviderType Provider =
|
||||
AsyncWrap::PROVIDER_RANDOMBYTESREQUEST;
|
||||
|
||||
static v8::Maybe<bool> AdditionalConfig(
|
||||
static v8::Maybe<void> AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args,
|
||||
unsigned int offset,
|
||||
@@ -37,11 +37,9 @@ struct RandomBytesTraits final {
|
||||
const RandomBytesConfig& params,
|
||||
ByteSource* out_);
|
||||
|
||||
static v8::Maybe<bool> EncodeOutput(
|
||||
Environment* env,
|
||||
const RandomBytesConfig& params,
|
||||
ByteSource* unused,
|
||||
v8::Local<v8::Value>* result);
|
||||
static v8::MaybeLocal<v8::Value> EncodeOutput(Environment* env,
|
||||
const RandomBytesConfig& params,
|
||||
ByteSource* unused);
|
||||
};
|
||||
|
||||
using RandomBytesJob = DeriveBitsJob<RandomBytesTraits>;
|
||||
@@ -63,7 +61,7 @@ struct RandomPrimeTraits final {
|
||||
static constexpr AsyncWrap::ProviderType Provider =
|
||||
AsyncWrap::PROVIDER_RANDOMPRIMEREQUEST;
|
||||
|
||||
static v8::Maybe<bool> AdditionalConfig(
|
||||
static v8::Maybe<void> AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args,
|
||||
unsigned int offset,
|
||||
@@ -74,11 +72,9 @@ struct RandomPrimeTraits final {
|
||||
const RandomPrimeConfig& params,
|
||||
ByteSource* out_);
|
||||
|
||||
static v8::Maybe<bool> EncodeOutput(
|
||||
Environment* env,
|
||||
const RandomPrimeConfig& params,
|
||||
ByteSource* unused,
|
||||
v8::Local<v8::Value>* result);
|
||||
static v8::MaybeLocal<v8::Value> EncodeOutput(Environment* env,
|
||||
const RandomPrimeConfig& params,
|
||||
ByteSource* unused);
|
||||
};
|
||||
|
||||
using RandomPrimeJob = DeriveBitsJob<RandomPrimeTraits>;
|
||||
@@ -99,7 +95,7 @@ struct CheckPrimeTraits final {
|
||||
static constexpr AsyncWrap::ProviderType Provider =
|
||||
AsyncWrap::PROVIDER_CHECKPRIMEREQUEST;
|
||||
|
||||
static v8::Maybe<bool> AdditionalConfig(
|
||||
static v8::Maybe<void> AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args,
|
||||
unsigned int offset,
|
||||
@@ -110,11 +106,9 @@ struct CheckPrimeTraits final {
|
||||
const CheckPrimeConfig& params,
|
||||
ByteSource* out);
|
||||
|
||||
static v8::Maybe<bool> EncodeOutput(
|
||||
Environment* env,
|
||||
const CheckPrimeConfig& params,
|
||||
ByteSource* out,
|
||||
v8::Local<v8::Value>* result);
|
||||
static v8::MaybeLocal<v8::Value> EncodeOutput(Environment* env,
|
||||
const CheckPrimeConfig& params,
|
||||
ByteSource* out);
|
||||
};
|
||||
|
||||
using CheckPrimeJob = DeriveBitsJob<CheckPrimeTraits>;
|
||||
|
||||
+20
-21
@@ -18,7 +18,6 @@ using v8::ArrayBuffer;
|
||||
using v8::BackingStore;
|
||||
using v8::FunctionCallbackInfo;
|
||||
using v8::Int32;
|
||||
using v8::Just;
|
||||
using v8::JustVoid;
|
||||
using v8::Local;
|
||||
using v8::Maybe;
|
||||
@@ -123,7 +122,7 @@ EVPKeyCtxPointer RsaKeyGenTraits::Setup(RsaKeyPairGenConfig* params) {
|
||||
// 11. Private Type
|
||||
// 12. Cipher
|
||||
// 13. Passphrase
|
||||
Maybe<bool> RsaKeyGenTraits::AdditionalConfig(
|
||||
Maybe<void> RsaKeyGenTraits::AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const FunctionCallbackInfo<Value>& args,
|
||||
unsigned int* offset,
|
||||
@@ -154,7 +153,7 @@ Maybe<bool> RsaKeyGenTraits::AdditionalConfig(
|
||||
params->params.md = EVP_get_digestbyname(*digest);
|
||||
if (params->params.md == nullptr) {
|
||||
THROW_ERR_CRYPTO_INVALID_DIGEST(env, "Invalid digest: %s", *digest);
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,7 +164,7 @@ Maybe<bool> RsaKeyGenTraits::AdditionalConfig(
|
||||
if (params->params.mgf1_md == nullptr) {
|
||||
THROW_ERR_CRYPTO_INVALID_DIGEST(
|
||||
env, "Invalid MGF1 digest: %s", *digest);
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,14 +175,14 @@ Maybe<bool> RsaKeyGenTraits::AdditionalConfig(
|
||||
THROW_ERR_OUT_OF_RANGE(
|
||||
env,
|
||||
"salt length is out of range");
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
}
|
||||
|
||||
*offset += 3;
|
||||
}
|
||||
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
namespace {
|
||||
@@ -246,14 +245,14 @@ WebCryptoCipherStatus RSA_Cipher(Environment* env,
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Maybe<bool> RSAKeyExportTraits::AdditionalConfig(
|
||||
Maybe<void> RSAKeyExportTraits::AdditionalConfig(
|
||||
const FunctionCallbackInfo<Value>& args,
|
||||
unsigned int offset,
|
||||
RSAKeyExportConfig* params) {
|
||||
CHECK(args[offset]->IsUint32()); // RSAKeyVariant
|
||||
params->variant =
|
||||
static_cast<RSAKeyVariant>(args[offset].As<Uint32>()->Value());
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
WebCryptoKeyExportStatus RSAKeyExportTraits::DoExport(
|
||||
@@ -293,7 +292,7 @@ void RSACipherConfig::MemoryInfo(MemoryTracker* tracker) const {
|
||||
tracker->TrackFieldWithSize("label", label.size());
|
||||
}
|
||||
|
||||
Maybe<bool> RSACipherTraits::AdditionalConfig(
|
||||
Maybe<void> RSACipherTraits::AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const FunctionCallbackInfo<Value>& args,
|
||||
unsigned int offset,
|
||||
@@ -316,14 +315,14 @@ Maybe<bool> RSACipherTraits::AdditionalConfig(
|
||||
params->digest = EVP_get_digestbyname(*digest);
|
||||
if (params->digest == nullptr) {
|
||||
THROW_ERR_CRYPTO_INVALID_DIGEST(env, "Invalid digest: %s", *digest);
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
if (IsAnyBufferSource(args[offset + 2])) {
|
||||
ArrayBufferOrViewContents<char> label(args[offset + 2]);
|
||||
if (UNLIKELY(!label.CheckSizeInt32())) {
|
||||
THROW_ERR_OUT_OF_RANGE(env, "label is too big");
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
params->label = label.ToCopy();
|
||||
}
|
||||
@@ -331,10 +330,10 @@ Maybe<bool> RSACipherTraits::AdditionalConfig(
|
||||
}
|
||||
default:
|
||||
THROW_ERR_CRYPTO_INVALID_KEYTYPE(env);
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
WebCryptoCipherStatus RSACipherTraits::DoCipher(Environment* env,
|
||||
@@ -500,7 +499,7 @@ KeyObjectData ImportJWKRsaKey(Environment* env,
|
||||
return KeyObjectData::CreateAsymmetric(type, std::move(pkey));
|
||||
}
|
||||
|
||||
Maybe<bool> GetRsaKeyDetail(Environment* env,
|
||||
Maybe<void> GetRsaKeyDetail(Environment* env,
|
||||
const KeyObjectData& key,
|
||||
Local<Object> target) {
|
||||
const BIGNUM* e; // Public Exponent
|
||||
@@ -529,7 +528,7 @@ Maybe<bool> GetRsaKeyDetail(Environment* env,
|
||||
Number::New(env->isolate(),
|
||||
static_cast<double>(BignumPointer::GetBitCount(n))))
|
||||
.IsNothing()) {
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
std::unique_ptr<BackingStore> public_exponent;
|
||||
@@ -549,7 +548,7 @@ Maybe<bool> GetRsaKeyDetail(Environment* env,
|
||||
env->public_exponent_string(),
|
||||
ArrayBuffer::New(env->isolate(), std::move(public_exponent)))
|
||||
.IsNothing()) {
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
if (type == EVP_PKEY_RSA_PSS) {
|
||||
@@ -581,7 +580,7 @@ Maybe<bool> GetRsaKeyDetail(Environment* env,
|
||||
env->hash_algorithm_string(),
|
||||
OneByteString(env->isolate(), OBJ_nid2ln(hash_nid)))
|
||||
.IsNothing()) {
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
if (params->maskGenAlgorithm != nullptr) {
|
||||
@@ -604,14 +603,14 @@ Maybe<bool> GetRsaKeyDetail(Environment* env,
|
||||
env->mgf1_hash_algorithm_string(),
|
||||
OneByteString(env->isolate(), OBJ_nid2ln(mgf1_hash_nid)))
|
||||
.IsNothing()) {
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
}
|
||||
|
||||
if (params->saltLength != nullptr) {
|
||||
if (ASN1_INTEGER_get_int64(&salt_length, params->saltLength) != 1) {
|
||||
ThrowCryptoError(env, ERR_get_error(), "ASN1_INTEGER_get_in64 error");
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -621,12 +620,12 @@ Maybe<bool> GetRsaKeyDetail(Environment* env,
|
||||
env->salt_length_string(),
|
||||
Number::New(env->isolate(), static_cast<double>(salt_length)))
|
||||
.IsNothing()) {
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Just<bool>(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
namespace RSAAlg {
|
||||
|
||||
@@ -43,7 +43,7 @@ struct RsaKeyGenTraits final {
|
||||
|
||||
static EVPKeyCtxPointer Setup(RsaKeyPairGenConfig* params);
|
||||
|
||||
static v8::Maybe<bool> AdditionalConfig(
|
||||
static v8::Maybe<void> AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args,
|
||||
unsigned int* offset,
|
||||
@@ -63,7 +63,7 @@ struct RSAKeyExportTraits final {
|
||||
static constexpr const char* JobName = "RSAKeyExportJob";
|
||||
using AdditionalParameters = RSAKeyExportConfig;
|
||||
|
||||
static v8::Maybe<bool> AdditionalConfig(
|
||||
static v8::Maybe<void> AdditionalConfig(
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args,
|
||||
unsigned int offset,
|
||||
RSAKeyExportConfig* config);
|
||||
@@ -95,7 +95,7 @@ struct RSACipherTraits final {
|
||||
static constexpr const char* JobName = "RSACipherJob";
|
||||
using AdditionalParameters = RSACipherConfig;
|
||||
|
||||
static v8::Maybe<bool> AdditionalConfig(
|
||||
static v8::Maybe<void> AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args,
|
||||
unsigned int offset,
|
||||
@@ -121,7 +121,7 @@ KeyObjectData ImportJWKRsaKey(Environment* env,
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args,
|
||||
unsigned int offset);
|
||||
|
||||
v8::Maybe<bool> GetRsaKeyDetail(Environment* env,
|
||||
v8::Maybe<void> GetRsaKeyDetail(Environment* env,
|
||||
const KeyObjectData& key,
|
||||
v8::Local<v8::Object> target);
|
||||
|
||||
|
||||
+11
-13
@@ -11,8 +11,9 @@ namespace node {
|
||||
|
||||
using v8::FunctionCallbackInfo;
|
||||
using v8::Int32;
|
||||
using v8::Just;
|
||||
using v8::JustVoid;
|
||||
using v8::Maybe;
|
||||
using v8::MaybeLocal;
|
||||
using v8::Nothing;
|
||||
using v8::Uint32;
|
||||
using v8::Value;
|
||||
@@ -43,16 +44,13 @@ void ScryptConfig::MemoryInfo(MemoryTracker* tracker) const {
|
||||
}
|
||||
}
|
||||
|
||||
Maybe<bool> ScryptTraits::EncodeOutput(
|
||||
Environment* env,
|
||||
const ScryptConfig& params,
|
||||
ByteSource* out,
|
||||
v8::Local<v8::Value>* result) {
|
||||
*result = out->ToArrayBuffer(env);
|
||||
return Just(!result->IsEmpty());
|
||||
MaybeLocal<Value> ScryptTraits::EncodeOutput(Environment* env,
|
||||
const ScryptConfig& params,
|
||||
ByteSource* out) {
|
||||
return out->ToArrayBuffer(env);
|
||||
}
|
||||
|
||||
Maybe<bool> ScryptTraits::AdditionalConfig(
|
||||
Maybe<void> ScryptTraits::AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const FunctionCallbackInfo<Value>& args,
|
||||
unsigned int offset,
|
||||
@@ -66,12 +64,12 @@ Maybe<bool> ScryptTraits::AdditionalConfig(
|
||||
|
||||
if (UNLIKELY(!pass.CheckSizeInt32())) {
|
||||
THROW_ERR_OUT_OF_RANGE(env, "pass is too large");
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
if (UNLIKELY(!salt.CheckSizeInt32())) {
|
||||
THROW_ERR_OUT_OF_RANGE(env, "salt is too large");
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
params->pass = mode == kCryptoJobAsync
|
||||
@@ -109,10 +107,10 @@ Maybe<bool> ScryptTraits::AdditionalConfig(
|
||||
} else {
|
||||
THROW_ERR_CRYPTO_INVALID_SCRYPT_PARAMS(env);
|
||||
}
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
bool ScryptTraits::DeriveBits(
|
||||
|
||||
@@ -51,7 +51,7 @@ struct ScryptTraits final {
|
||||
static constexpr AsyncWrap::ProviderType Provider =
|
||||
AsyncWrap::PROVIDER_SCRYPTREQUEST;
|
||||
|
||||
static v8::Maybe<bool> AdditionalConfig(
|
||||
static v8::Maybe<void> AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args,
|
||||
unsigned int offset,
|
||||
@@ -62,11 +62,9 @@ struct ScryptTraits final {
|
||||
const ScryptConfig& params,
|
||||
ByteSource* out);
|
||||
|
||||
static v8::Maybe<bool> EncodeOutput(
|
||||
Environment* env,
|
||||
const ScryptConfig& params,
|
||||
ByteSource* out,
|
||||
v8::Local<v8::Value>* result);
|
||||
static v8::MaybeLocal<v8::Value> EncodeOutput(Environment* env,
|
||||
const ScryptConfig& params,
|
||||
ByteSource* out);
|
||||
};
|
||||
|
||||
using ScryptJob = DeriveBitsJob<ScryptTraits>;
|
||||
|
||||
+16
-20
@@ -21,8 +21,10 @@ using v8::HandleScope;
|
||||
using v8::Int32;
|
||||
using v8::Isolate;
|
||||
using v8::Just;
|
||||
using v8::JustVoid;
|
||||
using v8::Local;
|
||||
using v8::Maybe;
|
||||
using v8::MaybeLocal;
|
||||
using v8::Nothing;
|
||||
using v8::Object;
|
||||
using v8::Uint32;
|
||||
@@ -627,7 +629,7 @@ void SignConfiguration::MemoryInfo(MemoryTracker* tracker) const {
|
||||
}
|
||||
}
|
||||
|
||||
Maybe<bool> SignTraits::AdditionalConfig(
|
||||
Maybe<void> SignTraits::AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const FunctionCallbackInfo<Value>& args,
|
||||
unsigned int offset,
|
||||
@@ -646,18 +648,18 @@ Maybe<bool> SignTraits::AdditionalConfig(
|
||||
if (params->mode == SignConfiguration::kVerify) {
|
||||
auto data =
|
||||
KeyObjectData::GetPublicOrPrivateKeyFromJs(args, &keyParamOffset);
|
||||
if (!data) return Nothing<bool>();
|
||||
if (!data) return Nothing<void>();
|
||||
params->key = std::move(data);
|
||||
} else {
|
||||
auto data = KeyObjectData::GetPrivateKeyFromJs(args, &keyParamOffset, true);
|
||||
if (!data) return Nothing<bool>();
|
||||
if (!data) return Nothing<void>();
|
||||
params->key = std::move(data);
|
||||
}
|
||||
|
||||
ArrayBufferOrViewContents<char> data(args[offset + 5]);
|
||||
if (UNLIKELY(!data.CheckSizeInt32())) {
|
||||
THROW_ERR_OUT_OF_RANGE(env, "data is too big");
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
params->data = mode == kCryptoJobAsync
|
||||
? data.ToCopy()
|
||||
@@ -668,7 +670,7 @@ Maybe<bool> SignTraits::AdditionalConfig(
|
||||
params->digest = EVP_get_digestbyname(*digest);
|
||||
if (params->digest == nullptr) {
|
||||
THROW_ERR_CRYPTO_INVALID_DIGEST(env, "Invalid digest: %s", *digest);
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -687,7 +689,7 @@ Maybe<bool> SignTraits::AdditionalConfig(
|
||||
if (params->dsa_encoding != kSigEncDER &&
|
||||
params->dsa_encoding != kSigEncP1363) {
|
||||
THROW_ERR_OUT_OF_RANGE(env, "invalid signature encoding");
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -695,7 +697,7 @@ Maybe<bool> SignTraits::AdditionalConfig(
|
||||
ArrayBufferOrViewContents<char> signature(args[offset + 10]);
|
||||
if (UNLIKELY(!signature.CheckSizeInt32())) {
|
||||
THROW_ERR_OUT_OF_RANGE(env, "signature is too big");
|
||||
return Nothing<bool>();
|
||||
return Nothing<void>();
|
||||
}
|
||||
// If this is an EC key (assuming ECDSA) we need to convert the
|
||||
// the signature from WebCrypto format into DER format...
|
||||
@@ -710,7 +712,7 @@ Maybe<bool> SignTraits::AdditionalConfig(
|
||||
}
|
||||
}
|
||||
|
||||
return Just(true);
|
||||
return JustVoid();
|
||||
}
|
||||
|
||||
bool SignTraits::DeriveBits(
|
||||
@@ -818,22 +820,16 @@ bool SignTraits::DeriveBits(
|
||||
return true;
|
||||
}
|
||||
|
||||
Maybe<bool> SignTraits::EncodeOutput(
|
||||
Environment* env,
|
||||
const SignConfiguration& params,
|
||||
ByteSource* out,
|
||||
Local<Value>* result) {
|
||||
MaybeLocal<Value> SignTraits::EncodeOutput(Environment* env,
|
||||
const SignConfiguration& params,
|
||||
ByteSource* out) {
|
||||
switch (params.mode) {
|
||||
case SignConfiguration::kSign:
|
||||
*result = out->ToArrayBuffer(env);
|
||||
break;
|
||||
return out->ToArrayBuffer(env);
|
||||
case SignConfiguration::kVerify:
|
||||
*result = Boolean::New(env->isolate(), out->data<char>()[0] == 1);
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return Boolean::New(env->isolate(), out->data<char>()[0] == 1);
|
||||
}
|
||||
return Just(!result->IsEmpty());
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
} // namespace crypto
|
||||
|
||||
@@ -140,7 +140,7 @@ struct SignTraits final {
|
||||
static constexpr AsyncWrap::ProviderType Provider =
|
||||
AsyncWrap::PROVIDER_SIGNREQUEST;
|
||||
|
||||
static v8::Maybe<bool> AdditionalConfig(
|
||||
static v8::Maybe<void> AdditionalConfig(
|
||||
CryptoJobMode mode,
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args,
|
||||
unsigned int offset,
|
||||
@@ -151,11 +151,9 @@ struct SignTraits final {
|
||||
const SignConfiguration& params,
|
||||
ByteSource* out);
|
||||
|
||||
static v8::Maybe<bool> EncodeOutput(
|
||||
Environment* env,
|
||||
const SignConfiguration& params,
|
||||
ByteSource* out,
|
||||
v8::Local<v8::Value>* result);
|
||||
static v8::MaybeLocal<v8::Value> EncodeOutput(Environment* env,
|
||||
const SignConfiguration& params,
|
||||
ByteSource* out);
|
||||
};
|
||||
|
||||
using SignJob = DeriveBitsJob<SignTraits>;
|
||||
|
||||
+32
-28
@@ -361,31 +361,31 @@ class CryptoJob : public AsyncWrap, public ThreadPoolWork {
|
||||
v8::HandleScope handle_scope(env->isolate());
|
||||
v8::Context::Scope context_scope(env->context());
|
||||
|
||||
// TODO(tniessen): Remove the exception handling logic here as soon as we
|
||||
// can verify that no code path in ToResult will ever throw an exception.
|
||||
v8::Local<v8::Value> exception;
|
||||
v8::Local<v8::Value> args[2];
|
||||
{
|
||||
node::errors::TryCatchScope try_catch(env);
|
||||
v8::Maybe<bool> ret = ptr->ToResult(&args[0], &args[1]);
|
||||
if (!ret.IsJust()) {
|
||||
// If ToResult returns Nothing, then an exception should have been
|
||||
// thrown and we should have caught it. Otherwise, args[0] and args[1]
|
||||
// both should have been set to a value, even if the value is undefined.
|
||||
if (ptr->ToResult(&args[0], &args[1]).IsNothing()) {
|
||||
CHECK(try_catch.HasCaught());
|
||||
CHECK(try_catch.CanContinue());
|
||||
exception = try_catch.Exception();
|
||||
} else if (!ret.FromJust()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (exception.IsEmpty()) {
|
||||
ptr->MakeCallback(env->ondone_string(), arraysize(args), args);
|
||||
} else {
|
||||
if (!exception.IsEmpty()) {
|
||||
ptr->MakeCallback(env->ondone_string(), 1, &exception);
|
||||
} else {
|
||||
CHECK(!args[0].IsEmpty());
|
||||
CHECK(!args[1].IsEmpty());
|
||||
ptr->MakeCallback(env->ondone_string(), arraysize(args), args);
|
||||
}
|
||||
}
|
||||
|
||||
virtual v8::Maybe<bool> ToResult(
|
||||
v8::Local<v8::Value>* err,
|
||||
v8::Local<v8::Value>* result) = 0;
|
||||
virtual v8::Maybe<void> ToResult(v8::Local<v8::Value>* err,
|
||||
v8::Local<v8::Value>* result) = 0;
|
||||
|
||||
CryptoJobMode mode() const { return mode_; }
|
||||
|
||||
@@ -413,8 +413,9 @@ class CryptoJob : public AsyncWrap, public ThreadPoolWork {
|
||||
v8::Local<v8::Value> ret[2];
|
||||
env->PrintSyncTrace();
|
||||
job->DoThreadPoolWork();
|
||||
v8::Maybe<bool> result = job->ToResult(&ret[0], &ret[1]);
|
||||
if (result.IsJust() && result.FromJust()) {
|
||||
if (job->ToResult(&ret[0], &ret[1]).IsJust()) {
|
||||
CHECK(!ret[0].IsEmpty());
|
||||
CHECK(!ret[1].IsEmpty());
|
||||
args.GetReturnValue().Set(
|
||||
v8::Array::New(env->isolate(), ret, arraysize(ret)));
|
||||
}
|
||||
@@ -504,26 +505,29 @@ class DeriveBitsJob final : public CryptoJob<DeriveBitsTraits> {
|
||||
success_ = true;
|
||||
}
|
||||
|
||||
v8::Maybe<bool> ToResult(
|
||||
v8::Local<v8::Value>* err,
|
||||
v8::Local<v8::Value>* result) override {
|
||||
v8::Maybe<void> ToResult(v8::Local<v8::Value>* err,
|
||||
v8::Local<v8::Value>* result) override {
|
||||
Environment* env = AsyncWrap::env();
|
||||
CryptoErrorStore* errors = CryptoJob<DeriveBitsTraits>::errors();
|
||||
if (success_) {
|
||||
CHECK(errors->Empty());
|
||||
*err = v8::Undefined(env->isolate());
|
||||
return DeriveBitsTraits::EncodeOutput(
|
||||
env,
|
||||
*CryptoJob<DeriveBitsTraits>::params(),
|
||||
&out_,
|
||||
result);
|
||||
if (!DeriveBitsTraits::EncodeOutput(
|
||||
env, *CryptoJob<DeriveBitsTraits>::params(), &out_)
|
||||
.ToLocal(result)) {
|
||||
return v8::Nothing<void>();
|
||||
}
|
||||
} else {
|
||||
if (errors->Empty()) errors->Capture();
|
||||
CHECK(!errors->Empty());
|
||||
*result = v8::Undefined(env->isolate());
|
||||
if (!errors->ToException(env).ToLocal(err)) {
|
||||
return v8::Nothing<void>();
|
||||
}
|
||||
}
|
||||
|
||||
if (errors->Empty())
|
||||
errors->Capture();
|
||||
CHECK(!errors->Empty());
|
||||
*result = v8::Undefined(env->isolate());
|
||||
return v8::Just(errors->ToException(env).ToLocal(err));
|
||||
CHECK(!result->IsEmpty());
|
||||
CHECK(!err->IsEmpty());
|
||||
return v8::JustVoid();
|
||||
}
|
||||
|
||||
SET_SELF_SIZE(DeriveBitsJob)
|
||||
|
||||
Reference in new issue
Block a user