mirror of
https://github.com/Unleash/unleash.git
synced 2024-11-01 19:07:38 +01:00
13 lines
285 B
TypeScript
13 lines
285 B
TypeScript
|
import crypto from 'crypto';
|
||
|
|
||
|
export const constantTimeCompare = (a: string, b: string): boolean => {
|
||
|
if (!a || !b || a.length !== b.length) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
return crypto.timingSafeEqual(
|
||
|
Buffer.from(a, 'utf8'),
|
||
|
Buffer.from(b, 'utf8'),
|
||
|
);
|
||
|
};
|