Skip to content

Commit f042929

Browse files
joyeecheungjasnell
authored andcommitted
src: throw ERR_INVALID_ARG_VALUE in node_crypto.cc
PR-URL: #20121 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 7946910 commit f042929

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/node_crypto.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,8 @@ void SecureContext::SetDHParam(const FunctionCallbackInfo<Value>& args) {
956956
DH_get0_pqg(dh, &p, nullptr, nullptr);
957957
const int size = BN_num_bits(p);
958958
if (size < 1024) {
959-
return env->ThrowError("DH parameter is less than 1024 bits");
959+
return THROW_ERR_INVALID_ARG_VALUE(
960+
env, "DH parameter is less than 1024 bits");
960961
} else if (size < 2048) {
961962
args.GetReturnValue().Set(FIXED_ONE_BYTE_STRING(
962963
env->isolate(), "DH parameter is less than 2048 bits"));
@@ -1203,7 +1204,8 @@ void SecureContext::SetTicketKeys(const FunctionCallbackInfo<Value>& args) {
12031204
THROW_AND_RETURN_IF_NOT_BUFFER(env, args[0], "Ticket keys");
12041205

12051206
if (Buffer::Length(args[0]) != 48) {
1206-
return env->ThrowTypeError("Ticket keys length must be 48 bytes");
1207+
return THROW_ERR_INVALID_ARG_VALUE(
1208+
env, "Ticket keys length must be 48 bytes");
12071209
}
12081210

12091211
memcpy(wrap->ticket_key_name_, Buffer::Data(args[0]), 16);
@@ -4391,7 +4393,8 @@ void ECDH::New(const FunctionCallbackInfo<Value>& args) {
43914393

43924394
int nid = OBJ_sn2nid(*curve);
43934395
if (nid == NID_undef)
4394-
return env->ThrowTypeError("First argument should be a valid curve name");
4396+
return THROW_ERR_INVALID_ARG_VALUE(env,
4397+
"First argument should be a valid curve name");
43954398

43964399
EC_KEY* key = EC_KEY_new_by_curve_name(nid);
43974400
if (key == nullptr)

src/node_errors.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace node {
1919
#define ERRORS_WITH_CODE(V) \
2020
V(ERR_BUFFER_OUT_OF_BOUNDS, RangeError) \
2121
V(ERR_INDEX_OUT_OF_RANGE, RangeError) \
22+
V(ERR_INVALID_ARG_VALUE, TypeError) \
2223
V(ERR_INVALID_ARG_TYPE, TypeError) \
2324
V(ERR_MEMORY_ALLOCATION_FAILED, Error) \
2425
V(ERR_MISSING_MODULE, Error) \

0 commit comments

Comments
 (0)