Constant time string/buffer equals
npm install tsse
⏱ Constant time string/buffer equals.
Coded with ❤️ by Simone Primarosa.
> This differs from crypto.timingSafeEqual because it:
> - supports both strings and Buffers;
> - supports inputs of different lengths.
```
$ npm install --save tsse
`js
const tsse = require('tsse');
const hash = '0a4d55a8d778e5022fab701977c5d840bbc486d0';
const givenHash = '1265a5eb08997ced279d3854629cba68a378b528';
if (tsse(hash, givenHash)) {
console.log('good hash');
} else {
console.log('bad hash');
}
// => bad hash
`
and inputStr have different lengths hiddenStr` is compared to itself, which makes the comparison non-commutative (time-wise).Kind: global function
Returns: boolean - true if equals, false otherwise.
Access: public
| Param | Type | Description |
| --- | --- | --- |
| hiddenStr | string \| Buffer | A string that you don't want to leak. |
| inputStr | string \| Buffer | Another string. |
See also the list of [contributors][contributors] who participated in this project.
[new issue]: https://github.com/simonepri/tsse/issues/new
[contributors]: https://github.com/simonepri/tsse/contributors
[license]: https://github.com/simonepri/tsse/tree/master/license
[github:simonepri]: https://github.com/simonepri
[twitter:simoneprimarosa]: http://twitter.com/intent/user?screen_name=simoneprimarosa