UNPKG

better-auth

Version:

The most comprehensive authentication framework for TypeScript.

18 lines (17 loc) 623 B
//#region src/crypto/buffer.ts /** * Compare two buffers in constant time. */ function constantTimeEqual(a, b) { if (typeof a === "string") a = new TextEncoder().encode(a); if (typeof b === "string") b = new TextEncoder().encode(b); const aBuffer = new Uint8Array(a); const bBuffer = new Uint8Array(b); let c = aBuffer.length ^ bBuffer.length; const length = Math.max(aBuffer.length, bBuffer.length); for (let i = 0; i < length; i++) c |= (i < aBuffer.length ? aBuffer[i] : 0) ^ (i < bBuffer.length ? bBuffer[i] : 0); return c === 0; } //#endregion export { constantTimeEqual }; //# sourceMappingURL=buffer.mjs.map