a zip code crypto-currency system good for red ONLY

1234567891011121314151617181920212223242526272829
  1. var MAX_ALLOC = Math.pow(2, 30) - 1 // default in iojs
  2. function checkBuffer (buf, name) {
  3. if (typeof buf !== 'string' && !Buffer.isBuffer(buf)) {
  4. throw new TypeError(name + ' must be a buffer or string')
  5. }
  6. }
  7. module.exports = function (password, salt, iterations, keylen) {
  8. checkBuffer(password, 'Password')
  9. checkBuffer(salt, 'Salt')
  10. if (typeof iterations !== 'number') {
  11. throw new TypeError('Iterations not a number')
  12. }
  13. if (iterations < 0) {
  14. throw new TypeError('Bad iterations')
  15. }
  16. if (typeof keylen !== 'number') {
  17. throw new TypeError('Key length not a number')
  18. }
  19. if (keylen < 0 || keylen > MAX_ALLOC || keylen !== keylen) { /* eslint no-self-compare: 0 */
  20. throw new TypeError('Bad key length')
  21. }
  22. }