From fb71337bdfab77ebc750397ff32e66d4993d1ecb Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 30 May 2018 16:14:37 +0200 Subject: [PATCH] lib: rename checkIsArrayBufferView() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rename it to validateArrayBufferView() to align with validateInt32() and friends. Swap the name and the value in the argument list for consistency, although any reasonable person will agree it's a crime against humanity to put the value before the name. PR-URL: https://github.com/nodejs/node/pull/20816 Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Tobias Nießen --- lib/internal/crypto/pbkdf2.js | 6 +++--- lib/internal/crypto/scrypt.js | 6 +++--- lib/internal/crypto/sig.js | 15 ++++++++------- lib/internal/crypto/util.js | 4 ++-- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/internal/crypto/pbkdf2.js b/lib/internal/crypto/pbkdf2.js index 7dd51e8f72881a..b6b61d35857628 100644 --- a/lib/internal/crypto/pbkdf2.js +++ b/lib/internal/crypto/pbkdf2.js @@ -11,8 +11,8 @@ const { ERR_INVALID_CALLBACK, } = require('internal/errors').codes; const { - checkIsArrayBufferView, getDefaultEncoding, + validateArrayBufferView, } = require('internal/crypto/util'); function pbkdf2(password, salt, iterations, keylen, digest, callback) { @@ -57,8 +57,8 @@ function check(password, salt, iterations, keylen, digest, callback) { digest = 'sha1'; } - password = checkIsArrayBufferView('password', password); - salt = checkIsArrayBufferView('salt', salt); + password = validateArrayBufferView(password, 'password'); + salt = validateArrayBufferView(salt, 'salt'); iterations = validateInt32(iterations, 'iterations', 0, INT_MAX); keylen = validateInt32(keylen, 'keylen', 0, INT_MAX); diff --git a/lib/internal/crypto/scrypt.js b/lib/internal/crypto/scrypt.js index a512af0f810bc3..fedf7f5b107b32 100644 --- a/lib/internal/crypto/scrypt.js +++ b/lib/internal/crypto/scrypt.js @@ -10,8 +10,8 @@ const { ERR_INVALID_CALLBACK, } = require('internal/errors').codes; const { - checkIsArrayBufferView, getDefaultEncoding, + validateArrayBufferView, } = require('internal/crypto/util'); const defaults = { @@ -74,8 +74,8 @@ function check(password, salt, keylen, options, callback) { if (_scrypt === undefined) throw new ERR_CRYPTO_SCRYPT_NOT_SUPPORTED(); - password = checkIsArrayBufferView('password', password); - salt = checkIsArrayBufferView(salt, 'salt'); + password = validateArrayBufferView(password, 'password'); + salt = validateArrayBufferView(salt, 'salt'); keylen = validateInt32(keylen, 'keylen', 0, INT_MAX); let { N, r, p, maxmem } = defaults; diff --git a/lib/internal/crypto/sig.js b/lib/internal/crypto/sig.js index fa440eb6a3475c..b6f8ceb50186d1 100644 --- a/lib/internal/crypto/sig.js +++ b/lib/internal/crypto/sig.js @@ -14,9 +14,9 @@ const { RSA_PKCS1_PADDING } = process.binding('constants').crypto; const { - checkIsArrayBufferView, getDefaultEncoding, - toBuf + toBuf, + validateArrayBufferView, } = require('internal/crypto/util'); const { Writable } = require('stream'); const { inherits } = require('util'); @@ -41,7 +41,8 @@ Sign.prototype._write = function _write(chunk, encoding, callback) { Sign.prototype.update = function update(data, encoding) { encoding = encoding || getDefaultEncoding(); - data = checkIsArrayBufferView('data', toBuf(data, encoding)); + data = validateArrayBufferView(toBuf(data, encoding), + 'data'); this._handle.update(data); return this; }; @@ -77,7 +78,7 @@ Sign.prototype.sign = function sign(options, encoding) { var pssSaltLength = getSaltLength(options); - key = checkIsArrayBufferView('key', key); + key = validateArrayBufferView(key, 'key'); var ret = this._handle.sign(key, passphrase, rsaPadding, pssSaltLength); @@ -114,10 +115,10 @@ Verify.prototype.verify = function verify(options, signature, sigEncoding) { var pssSaltLength = getSaltLength(options); - key = checkIsArrayBufferView('key', key); + key = validateArrayBufferView(key, 'key'); - signature = checkIsArrayBufferView('signature', - toBuf(signature, sigEncoding)); + signature = validateArrayBufferView(toBuf(signature, sigEncoding), + 'signature'); return this._handle.verify(key, signature, rsaPadding, pssSaltLength); }; diff --git a/lib/internal/crypto/util.js b/lib/internal/crypto/util.js index e2cd810a011bfa..32c9eb7f6a12b6 100644 --- a/lib/internal/crypto/util.js +++ b/lib/internal/crypto/util.js @@ -83,7 +83,7 @@ function timingSafeEqual(buf1, buf2) { return _timingSafeEqual(buf1, buf2); } -function checkIsArrayBufferView(name, buffer) { +function validateArrayBufferView(buffer, name) { buffer = toBuf(buffer); if (!isArrayBufferView(buffer)) { throw new ERR_INVALID_ARG_TYPE( @@ -96,7 +96,7 @@ function checkIsArrayBufferView(name, buffer) { } module.exports = { - checkIsArrayBufferView, + validateArrayBufferView, getCiphers, getCurves, getDefaultEncoding,