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.

50 lines
1.1 KiB

4 years ago
  1. # buffer-equal-constant-time
  2. Constant-time `Buffer` comparison for node.js. Should work with browserify too.
  3. [![Build Status](https://travis-ci.org/goinstant/buffer-equal-constant-time.png?branch=master)](https://travis-ci.org/goinstant/buffer-equal-constant-time)
  4. ```sh
  5. npm install buffer-equal-constant-time
  6. ```
  7. # Usage
  8. ```js
  9. var bufferEq = require('buffer-equal-constant-time');
  10. var a = new Buffer('asdf');
  11. var b = new Buffer('asdf');
  12. if (bufferEq(a,b)) {
  13. // the same!
  14. } else {
  15. // different in at least one byte!
  16. }
  17. ```
  18. If you'd like to install an `.equal()` method onto the node.js `Buffer` and
  19. `SlowBuffer` prototypes:
  20. ```js
  21. require('buffer-equal-constant-time').install();
  22. var a = new Buffer('asdf');
  23. var b = new Buffer('asdf');
  24. if (a.equal(b)) {
  25. // the same!
  26. } else {
  27. // different in at least one byte!
  28. }
  29. ```
  30. To get rid of the installed `.equal()` method, call `.restore()`:
  31. ```js
  32. require('buffer-equal-constant-time').restore();
  33. ```
  34. # Legal
  35. © 2013 GoInstant Inc., a salesforce.com company
  36. Licensed under the BSD 3-clause license.