Skip to content

Commit 9ded02e

Browse files
committed
crypto: use assert instead of directly throwing an error
Fixes: #38302
1 parent 4139650 commit 9ded02e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/internal/crypto/diffiehellman.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {
99
SafeSet,
1010
} = primordials;
1111

12+
const assert = require('internal/assert');
1213
const { Buffer } = require('buffer');
1314

1415
const {
@@ -104,8 +105,8 @@ function DiffieHellman(sizeOrKey, keyEncoding, generator, genEncoding) {
104105
if (typeof sizeOrKey === 'number')
105106
validateInt32(sizeOrKey, 'sizeOrKey');
106107

107-
if (typeof sizeOrKey === 'string' && sizeOrKey.length === 0) {
108-
throw new ERR_INVALID_ARG_VALUE('sizeOrKey', sizeOrKey);
108+
if (typeof sizeOrKey === 'string') {
109+
assert(sizeOrKey.length > 0, 'key must not be empty');
109110
}
110111

111112
if (keyEncoding && !Buffer.isEncoding(keyEncoding) &&

0 commit comments

Comments
 (0)