Skip to content

Commit fb71337

Browse files
bnoordhuistargos
authored andcommitted
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: #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]>
1 parent f3570f2 commit fb71337

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

lib/internal/crypto/pbkdf2.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const {
1111
ERR_INVALID_CALLBACK,
1212
} = require('internal/errors').codes;
1313
const {
14-
checkIsArrayBufferView,
1514
getDefaultEncoding,
15+
validateArrayBufferView,
1616
} = require('internal/crypto/util');
1717

1818
function pbkdf2(password, salt, iterations, keylen, digest, callback) {
@@ -57,8 +57,8 @@ function check(password, salt, iterations, keylen, digest, callback) {
5757
digest = 'sha1';
5858
}
5959

60-
password = checkIsArrayBufferView('password', password);
61-
salt = checkIsArrayBufferView('salt', salt);
60+
password = validateArrayBufferView(password, 'password');
61+
salt = validateArrayBufferView(salt, 'salt');
6262
iterations = validateInt32(iterations, 'iterations', 0, INT_MAX);
6363
keylen = validateInt32(keylen, 'keylen', 0, INT_MAX);
6464

lib/internal/crypto/scrypt.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const {
1010
ERR_INVALID_CALLBACK,
1111
} = require('internal/errors').codes;
1212
const {
13-
checkIsArrayBufferView,
1413
getDefaultEncoding,
14+
validateArrayBufferView,
1515
} = require('internal/crypto/util');
1616

1717
const defaults = {
@@ -74,8 +74,8 @@ function check(password, salt, keylen, options, callback) {
7474
if (_scrypt === undefined)
7575
throw new ERR_CRYPTO_SCRYPT_NOT_SUPPORTED();
7676

77-
password = checkIsArrayBufferView('password', password);
78-
salt = checkIsArrayBufferView(salt, 'salt');
77+
password = validateArrayBufferView(password, 'password');
78+
salt = validateArrayBufferView(salt, 'salt');
7979
keylen = validateInt32(keylen, 'keylen', 0, INT_MAX);
8080

8181
let { N, r, p, maxmem } = defaults;

lib/internal/crypto/sig.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ const {
1414
RSA_PKCS1_PADDING
1515
} = process.binding('constants').crypto;
1616
const {
17-
checkIsArrayBufferView,
1817
getDefaultEncoding,
19-
toBuf
18+
toBuf,
19+
validateArrayBufferView,
2020
} = require('internal/crypto/util');
2121
const { Writable } = require('stream');
2222
const { inherits } = require('util');
@@ -41,7 +41,8 @@ Sign.prototype._write = function _write(chunk, encoding, callback) {
4141

4242
Sign.prototype.update = function update(data, encoding) {
4343
encoding = encoding || getDefaultEncoding();
44-
data = checkIsArrayBufferView('data', toBuf(data, encoding));
44+
data = validateArrayBufferView(toBuf(data, encoding),
45+
'data');
4546
this._handle.update(data);
4647
return this;
4748
};
@@ -77,7 +78,7 @@ Sign.prototype.sign = function sign(options, encoding) {
7778

7879
var pssSaltLength = getSaltLength(options);
7980

80-
key = checkIsArrayBufferView('key', key);
81+
key = validateArrayBufferView(key, 'key');
8182

8283
var ret = this._handle.sign(key, passphrase, rsaPadding, pssSaltLength);
8384

@@ -114,10 +115,10 @@ Verify.prototype.verify = function verify(options, signature, sigEncoding) {
114115

115116
var pssSaltLength = getSaltLength(options);
116117

117-
key = checkIsArrayBufferView('key', key);
118+
key = validateArrayBufferView(key, 'key');
118119

119-
signature = checkIsArrayBufferView('signature',
120-
toBuf(signature, sigEncoding));
120+
signature = validateArrayBufferView(toBuf(signature, sigEncoding),
121+
'signature');
121122

122123
return this._handle.verify(key, signature, rsaPadding, pssSaltLength);
123124
};

lib/internal/crypto/util.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function timingSafeEqual(buf1, buf2) {
8383
return _timingSafeEqual(buf1, buf2);
8484
}
8585

86-
function checkIsArrayBufferView(name, buffer) {
86+
function validateArrayBufferView(buffer, name) {
8787
buffer = toBuf(buffer);
8888
if (!isArrayBufferView(buffer)) {
8989
throw new ERR_INVALID_ARG_TYPE(
@@ -96,7 +96,7 @@ function checkIsArrayBufferView(name, buffer) {
9696
}
9797

9898
module.exports = {
99-
checkIsArrayBufferView,
99+
validateArrayBufferView,
100100
getCiphers,
101101
getCurves,
102102
getDefaultEncoding,

0 commit comments

Comments
 (0)