precondition.js 564 B

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