@@ -155,10 +155,9 @@ function scrypt(password, salt, logN, r, dkLen, interruptStep, callback, encodin
155
155
function PBKDF2_HMAC_SHA256_OneIter ( password , salt , dkLen ) {
156
156
// compress password if it's longer than hash block length
157
157
if ( password . length > 64 ) {
158
- // coerces the structure into an array type if it lacks support for the .push operation
159
- // use [...password] when you instead of the "Array.prototype.slice.call" when you deprecate pre-ES6
160
- // it's supposed to be faster in most browsers.
161
- password = SHA256 ( password . push ? password : Array . prototype . slice . call ( password , 0 ) )
158
+ // SHA256 expects password to be an Array. If it's not
159
+ // (i.e. it doesn't have .push method), convert it to one.
160
+ password = SHA256 ( password . push ? password : Array . prototype . slice . call ( password , 0 ) ) ;
162
161
}
163
162
164
163
var i , innerLen = 64 + salt . length + 4 ,
@@ -404,12 +403,11 @@ function scrypt(password, salt, logN, r, dkLen, interruptStep, callback, encodin
404
403
}
405
404
}
406
405
407
- // bug on the following line: p can never be detected as invalid if set to zero. It will silently switch to 1.
408
- // recommended fix: p = typeof opts.p === "undefined" ? 1 : opts.p;
406
+ // XXX: If opts.p or opts.dkLen is 0, it will be set to the default value
407
+ // instead of throwing due to incorrect value. To avoid breaking
408
+ // compatibility, this will only be changed in the next major version.
409
409
p = opts . p || 1 ;
410
410
r = opts . r ;
411
-
412
- // recommended code: dkLen = typeof opts.dkLen === "undefined" ? 32 : opts.dkLen;
413
411
dkLen = opts . dkLen || 32 ;
414
412
interruptStep = opts . interruptStep || 0 ;
415
413
encoding = opts . encoding ;
0 commit comments