PIbd-21_Danilov_V.V._Intern.../Lab3/node_modules/secure-compare/index.js
Владимир Данилов 83490711d5 отчет
2023-12-19 20:23:11 +04:00

26 lines
406 B
JavaScript

/**
* Expose secure-compare
*/
module.exports = compare;
/**
* Secure compare
*/
function compare (a, b) {
if (typeof a !== 'string' || typeof b !== 'string') return false;
var mismatch = a.length === b.length ? 0 : 1;
if (mismatch) {
b = a;
}
for (var i = 0, il = a.length; i < il; ++i) {
mismatch |= (a.charCodeAt(i) ^ b.charCodeAt(i));
}
return mismatch === 0;
};