Skip to content

Commit

Permalink
crypto: use assert instead of directly throwing an error
Browse files Browse the repository at this point in the history
  • Loading branch information
eladkishon committed Apr 20, 2021
1 parent 4139650 commit 9ded02e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/internal/crypto/diffiehellman.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {
SafeSet,
} = primordials;

const assert = require('internal/assert');
const { Buffer } = require('buffer');

const {
Expand Down Expand Up @@ -104,8 +105,8 @@ function DiffieHellman(sizeOrKey, keyEncoding, generator, genEncoding) {
if (typeof sizeOrKey === 'number')
validateInt32(sizeOrKey, 'sizeOrKey');

if (typeof sizeOrKey === 'string' && sizeOrKey.length === 0) {
throw new ERR_INVALID_ARG_VALUE('sizeOrKey', sizeOrKey);
if (typeof sizeOrKey === 'string') {
assert(sizeOrKey.length > 0, 'key must not be empty');
}

if (keyEncoding && !Buffer.isEncoding(keyEncoding) &&
Expand Down

0 comments on commit 9ded02e

Please sign in to comment.