Skip to content
Myr

buffer.ts

This file

Path

src/utils/buffer.ts

66 lines · 1.2 KiB · TypeScript

Last changed by

Merge pull request #2769 from honojs/nextYusuke Wadabefore adoptionacd3634

History of this file

Take it

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

Merge pull request #2769 from honojs/nextYusuke Wadabefore adoptionacd3634

lines 1–5why, one step back
1/**
2 * @module3 * Buffer utility.4 */5

fix(hono-base): fix not found handler calling timing when one middleware (#2080)Taku Amanobefore adoption4a239ad

lines 6–7why, one step back
6import { sha256 } from './crypto'
7

Merge pull request #2769 from honojs/nextYusuke Wadabefore adoptionacd3634

line 8why, one step back
8export const equal = (a: ArrayBuffer, b: ArrayBuffer): boolean => {

fix(hono-base): fix not found handler calling timing when one middleware (#2080)Taku Amanobefore adoption4a239ad

lines 9–32why, one step back
9 if (a === b) {
10 return true11 }12 if (a.byteLength !== b.byteLength) {13 return false14 }1516 const va = new DataView(a)17 const vb = new DataView(b)1819 let i = va.byteLength20 while (i--) {21 if (va.getUint8(i) !== vb.getUint8(i)) {22 return false23 }24 }2526 return true27}2829export const timingSafeEqual = async (30 a: string | object | boolean,31 b: string | object | boolean,32 hashFunction?: Function

Merge pull request #2769 from honojs/nextYusuke Wadabefore adoptionacd3634

line 33why, one step back
33): Promise<boolean> => {

fix(hono-base): fix not found handler calling timing when one middleware (#2080)Taku Amanobefore adoption4a239ad

lines 34–55why, one step back
34 if (!hashFunction) {
35 hashFunction = sha25636 }3738 const sa = await hashFunction(a)39 const sb = await hashFunction(b)4041 if (!sa || !sb) {42 return false43 }4445 return sa === sb && a === b46}4748export const bufferToString = (buffer: ArrayBuffer): string => {49 if (buffer instanceof ArrayBuffer) {50 const enc = new TextDecoder('utf-8')51 return enc.decode(buffer)52 }53 return buffer54}55

perf(types): add type annotations (#2663)Yusuke Wadabefore adoptione5975ed

lines 56–59why, one step back
56export const bufferToFormData = (
57 arrayBuffer: ArrayBuffer,58 contentType: string59): Promise<FormData> => {

fix(hono-base): fix not found handler calling timing when one middleware (#2080)Taku Amanobefore adoption4a239ad

lines 60–66why, one step back
60 const response = new Response(arrayBuffer, {
61 headers: {62 'Content-Type': contentType,63 },64 })65 return response.formData()66}