precondition.js 507 B

12345678910111213141516171819
  1. var MAX_ALLOC = Math.pow(2, 30) - 1 // default in iojs
  2. module.exports = function (iterations, keylen) {
  3. if (typeof iterations !== 'number') {
  4. throw new TypeError('Iterations not a number')
  5. }
  6. if (iterations < 0) {
  7. throw new TypeError('Bad iterations')
  8. }
  9. if (typeof keylen !== 'number') {
  10. throw new TypeError('Key length not a number')
  11. }
  12. if (keylen < 0 || keylen > MAX_ALLOC || keylen !== keylen) { /* eslint no-self-compare: 0 */
  13. throw new TypeError('Bad key length')
  14. }
  15. }