You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
406B

  1. /**
  2. * Expose secure-compare
  3. */
  4. module.exports = compare;
  5. /**
  6. * Secure compare
  7. */
  8. function compare (a, b) {
  9. if (typeof a !== 'string' || typeof b !== 'string') return false;
  10. var mismatch = a.length === b.length ? 0 : 1;
  11. if (mismatch) {
  12. b = a;
  13. }
  14. for (var i = 0, il = a.length; i < il; ++i) {
  15. mismatch |= (a.charCodeAt(i) ^ b.charCodeAt(i));
  16. }
  17. return mismatch === 0;
  18. };