diff options
Diffstat (limited to 'cli/bench/testdata/npm/hono/dist/utils/buffer.js')
-rw-r--r-- | cli/bench/testdata/npm/hono/dist/utils/buffer.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/cli/bench/testdata/npm/hono/dist/utils/buffer.js b/cli/bench/testdata/npm/hono/dist/utils/buffer.js new file mode 100644 index 000000000..58ee6f9ae --- /dev/null +++ b/cli/bench/testdata/npm/hono/dist/utils/buffer.js @@ -0,0 +1,39 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.bufferToString = exports.timingSafeEqual = exports.equal = void 0; +const crypto_1 = require("./crypto"); +const equal = (a, b) => { + if (a === b) { + return true; + } + if (a.byteLength !== b.byteLength) { + return false; + } + const va = new DataView(a); + const vb = new DataView(b); + let i = va.byteLength; + while (i--) { + if (va.getUint8(i) !== vb.getUint8(i)) { + return false; + } + } + return true; +}; +exports.equal = equal; +const timingSafeEqual = async (a, b, hashFunction) => { + if (!hashFunction) { + hashFunction = crypto_1.sha256; + } + const sa = await hashFunction(a); + const sb = await hashFunction(b); + return sa === sb && a === b; +}; +exports.timingSafeEqual = timingSafeEqual; +const bufferToString = (buffer) => { + if (buffer instanceof ArrayBuffer) { + const enc = new TextDecoder('utf-8'); + return enc.decode(buffer); + } + return buffer; +}; +exports.bufferToString = bufferToString; |