react-native-quick-crypto
Version:
A fast implementation of Node's `crypto` module written in C/C++ JSI
25 lines (24 loc) • 962 B
JavaScript
;
import { NitroModules } from 'react-native-nitro-modules';
import { binaryLikeToArrayBuffer } from './conversion';
let utils;
function getNative() {
if (utils == null) {
utils = NitroModules.createHybridObject('Utils');
}
return utils;
}
export function timingSafeEqual(a, b) {
// Use binaryLikeToArrayBuffer (not abvToArrayBuffer) so that TypedArray /
// Buffer views are sliced to their `byteOffset`/`byteLength` window. The
// zero-copy `abvToArrayBuffer` returns the entire backing buffer, which
// would (a) compare unrelated bytes and (b) silently fail the byte-length
// check for any view smaller than its backing.
const bufA = binaryLikeToArrayBuffer(a);
const bufB = binaryLikeToArrayBuffer(b);
if (bufA.byteLength !== bufB.byteLength) {
throw new RangeError('Input buffers must have the same byte length');
}
return getNative().timingSafeEqual(bufA, bufB);
}
//# sourceMappingURL=timingSafeEqual.js.map