1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-11-01 19:07:38 +01:00
unleash.unleash/src/lib/util/constantTimeCompare.ts
Fredrik Strand Oseberg 874d8459ce
Feat/add alias to api tokens (#1931)
* refactor: remove unused API definition routes

* feat: embed proxy endpoints

* feat: check token metadata for alias if none is found

* fix: rename param

* feat: add test for retrieving token by alias

* fix: update schema

* fix: refactor to alias

* fix: refactor to null

* fix: update snapshot

* fix: update openapi snapshot

* fix: add check to getUserForToken

* refactor: add more token alias tests

* refactor: use timingSafeEqual for token comparisons

Co-authored-by: olav <mail@olav.io>
2022-08-19 10:48:33 +02:00

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'),
);
};