From 676fa5f965147ab98fe50e521027833659d02364 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 --- 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 4a0c66f9cf5a70..ed3693d6fe90e8 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 ca7f2986e11cff..e0b0d3fd7bf656 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')