lib: rename checkIsArrayBufferView()

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 <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This commit is contained in:
Ben Noordhuis 2018-05-30 16:14:37 +02:00
parent d669251f67
commit 59ace5752a
4 changed files with 16 additions and 15 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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);
};

View File

@ -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,