Skip to content

Commit 3fbb793

Browse files
committed
Add Uint8Array support
1 parent e4fc8b6 commit 3fbb793

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/precondition.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
var MAX_ALLOC = Math.pow(2, 30) - 1 // default in iojs
22

3-
function checkBuffer (buf, name) {
4-
if (typeof buf !== 'string' && !Buffer.isBuffer(buf)) {
3+
function checkType (variable, name) {
4+
// checks whether the type of 'variable' is one of string, Buffer or Uint8Array
5+
if (typeof variable !== 'string' && !Buffer.isBuffer(variable) && Object.prototype.toString.call(variable) !== '[object Uint8Array]') {
56
throw new TypeError(name + ' must be a buffer or string')
67
}
78
}
89

910
module.exports = function (password, salt, iterations, keylen) {
10-
checkBuffer(password, 'Password')
11-
checkBuffer(salt, 'Salt')
11+
checkType(password, 'Password')
12+
checkType(salt, 'Salt')
1213

1314
if (typeof iterations !== 'number') {
1415
throw new TypeError('Iterations not a number')

0 commit comments

Comments
 (0)