From 98552f3630576c108a350a5784a904bfc1d05e3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Tue, 26 Mar 2019 12:16:30 +0100 Subject: [PATCH] crypto: allow undefined for saltLength and padding PR-URL: https://github.com/nodejs/node/pull/26921 Reviewed-By: Sam Roberts Reviewed-By: James M Snell Reviewed-By: Ben Noordhuis Signed-off-by: Beth Griggs --- lib/internal/crypto/sig.js | 4 ++-- test/parallel/test-crypto-sign-verify.js | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/internal/crypto/sig.js b/lib/internal/crypto/sig.js index aa70126029dcee..10c044f82d0a2e 100644 --- a/lib/internal/crypto/sig.js +++ b/lib/internal/crypto/sig.js @@ -60,8 +60,8 @@ function getSaltLength(options) { } function getIntOption(name, defaultValue, options) { - if (options.hasOwnProperty(name)) { - const value = options[name]; + const value = options[name]; + if (value !== undefined) { if (value === value >> 0) { return value; } else { diff --git a/test/parallel/test-crypto-sign-verify.js b/test/parallel/test-crypto-sign-verify.js index da4e8aa331aaa4..06f1d85f90f9a8 100644 --- a/test/parallel/test-crypto-sign-verify.js +++ b/test/parallel/test-crypto-sign-verify.js @@ -32,23 +32,23 @@ const modSize = 1024; common.expectsError( () => crypto.createVerify('SHA256').verify({ key: certPem, - padding: undefined, + padding: null, }, ''), { code: 'ERR_INVALID_OPT_VALUE', type: TypeError, - message: 'The value "undefined" is invalid for option "padding"' + message: 'The value "null" is invalid for option "padding"' }); common.expectsError( () => crypto.createVerify('SHA256').verify({ key: certPem, - saltLength: undefined, + saltLength: null, }, ''), { code: 'ERR_INVALID_OPT_VALUE', type: TypeError, - message: 'The value "undefined" is invalid for option "saltLength"' + message: 'The value "null" is invalid for option "saltLength"' }); // Test signing and verifying @@ -233,7 +233,7 @@ common.expectsError( // Test exceptions for invalid `padding` and `saltLength` values { - [null, undefined, NaN, 'boom', {}, [], true, false] + [null, NaN, 'boom', {}, [], true, false] .forEach((invalidValue) => { common.expectsError(() => { crypto.createSign('SHA256')