Skip to content
Myr

buffer.ts

This file

Path

src/utils/buffer.ts

49 lines · 916 bytes · TypeScript

Last changed by

Merge pull request #905 from honojs/nextYusuke Wadabefore adoption4b75b94

History of this file

Take it

The walk stopped after 200 commits: lines older than e9a54bb point at it.

fix(reg-exp-router): Allows registering a star after a long prefix. (#684)Taku Amanobefore adoptione9a54bb

lines 1–31why, one step back
1import { sha256 } from './crypto'
23export const equal = (a: ArrayBuffer, b: ArrayBuffer) => {4 if (a === b) {5 return true6 }7 if (a.byteLength !== b.byteLength) {8 return false9 }1011 const va = new DataView(a)12 const vb = new DataView(b)1314 let i = va.byteLength15 while (i--) {16 if (va.getUint8(i) !== vb.getUint8(i)) {17 return false18 }19 }2021 return true22}2324export const timingSafeEqual = async (25 a: string | object | boolean,26 b: string | object | boolean,27 hashFunction?: Function28) => {29 if (!hashFunction) {30 hashFunction = sha25631 }

Merge pull request #905 from honojs/nextYusuke Wadabefore adoption4b75b94

line 32why, one step back
32

fix(reg-exp-router): Allows registering a star after a long prefix. (#684)Taku Amanobefore adoptione9a54bb

lines 33–34why, one step back
33 const sa = await hashFunction(a)
34 const sb = await hashFunction(b)

Merge pull request #905 from honojs/nextYusuke Wadabefore adoption4b75b94

lines 35–39why, one step back
35
36 if (!sa || !sb) {37 return false38 }39

fix(reg-exp-router): Allows registering a star after a long prefix. (#684)Taku Amanobefore adoptione9a54bb

lines 40–49why, one step back
40 return sa === sb && a === b
41}4243export const bufferToString = (buffer: ArrayBuffer): string => {44 if (buffer instanceof ArrayBuffer) {45 const enc = new TextDecoder('utf-8')46 return enc.decode(buffer)47 }48 return buffer49}