From 19df7824727824a8e1dc38f8d744e0436fe208d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Mon, 20 Mar 2023 02:19:49 +0000 Subject: [PATCH] src: replace impossible THROW with CHECK The JS layer already verifies that divisor_bits is either a non-negative 32-bit signed integer or null/undefined, in which case it passes -1 to the C++ layer. In either case, the C++ layer receives a 32-bit signed integer greater than or equal to -1. --- src/crypto/crypto_dsa.cc | 6 +----- test/parallel/test-crypto-keygen.js | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/crypto/crypto_dsa.cc b/src/crypto/crypto_dsa.cc index 6839283fbf4ca7..3fa4a415dc911a 100644 --- a/src/crypto/crypto_dsa.cc +++ b/src/crypto/crypto_dsa.cc @@ -83,16 +83,12 @@ Maybe DsaKeyGenTraits::AdditionalConfig( const FunctionCallbackInfo& args, unsigned int* offset, DsaKeyPairGenConfig* params) { - Environment* env = Environment::GetCurrent(args); CHECK(args[*offset]->IsUint32()); // modulus bits CHECK(args[*offset + 1]->IsInt32()); // divisor bits params->params.modulus_bits = args[*offset].As()->Value(); params->params.divisor_bits = args[*offset + 1].As()->Value(); - if (params->params.divisor_bits < -1) { - THROW_ERR_OUT_OF_RANGE(env, "invalid value for divisor_bits"); - return Nothing(); - } + CHECK_GE(params->params.divisor_bits, -1); *offset += 2; diff --git a/test/parallel/test-crypto-keygen.js b/test/parallel/test-crypto-keygen.js index 1a77266b057041..df8c5d93a90342 100644 --- a/test/parallel/test-crypto-keygen.js +++ b/test/parallel/test-crypto-keygen.js @@ -1278,7 +1278,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); } // Test invalid divisor lengths. (out of range) - for (const divisorLength of [-6, -9, 2147483648]) { + for (const divisorLength of [-1, -6, -9, 2147483648]) { assert.throws(() => generateKeyPair('dsa', { modulusLength: 2048, divisorLength