Skip to content

Commit

Permalink
lib: rename checkIsArrayBufferView()
Browse files Browse the repository at this point in the history
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: #20816
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
  • Loading branch information
bnoordhuis authored and targos committed Jun 13, 2018
1 parent f3570f2 commit fb71337
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
6 changes: 3 additions & 3 deletions lib/internal/crypto/pbkdf2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions lib/internal/crypto/scrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const {
ERR_INVALID_CALLBACK,
} = require('internal/errors').codes;
const {
checkIsArrayBufferView,
getDefaultEncoding,
validateArrayBufferView,
} = require('internal/crypto/util');

const defaults = {
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 8 additions & 7 deletions lib/internal/crypto/sig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
};
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
};
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/crypto/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -96,7 +96,7 @@ function checkIsArrayBufferView(name, buffer) {
}

module.exports = {
checkIsArrayBufferView,
validateArrayBufferView,
getCiphers,
getCurves,
getDefaultEncoding,
Expand Down

0 comments on commit fb71337

Please sign in to comment.