Skip to content
Myr

buffer.test.ts

This file

Path

src/utils/buffer.test.ts

55 lines · 2.1 KiB · TypeScript

Last changed by

refactor(TypeScript): enable strict null check (#280)Yusuke Wadabefore adoptionb55eb2e

History of this file

Take it

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

feat(type): anyYusuke Wadabefore adoption1204e12

lines 1–13why, one step back
1import { SHA256 as sha256CryptoJS } from 'crypto-js'
2import { timingSafeEqual, bufferToString } from './buffer'34describe('buffer', () => {5 it('positive', async () => {6 expect(7 await timingSafeEqual(8 '127e6fbfe24a750e72930c220a8e138275656b8e5d8f48a98c3c92df2caba935',9 '127e6fbfe24a750e72930c220a8e138275656b8e5d8f48a98c3c92df2caba935'10 )11 ).toBe(true)12 expect(await timingSafeEqual('a', 'a')).toBe(true)13 expect(await timingSafeEqual('', '')).toBe(true)

refactor(TypeScript): enable strict null check (#280)Yusuke Wadabefore adoptionb55eb2e

lines 14–15why, one step back
14 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
15 // @ts-ignore

feat(type): anyYusuke Wadabefore adoption1204e12

lines 16–31why, one step back
16 expect(await timingSafeEqual(undefined, undefined)).toBe(true)
17 expect(await timingSafeEqual(true, true)).toBe(true)18 expect(await timingSafeEqual(false, false)).toBe(true)19 expect(await timingSafeEqual(true, true, (d: string) => sha256CryptoJS(d).toString()))20 })2122 it('negative', async () => {23 expect(await timingSafeEqual('a', 'b')).toBe(false)24 expect(25 await timingSafeEqual('a', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')26 ).toBe(false)27 expect(28 await timingSafeEqual('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'a')29 ).toBe(false)30 expect(await timingSafeEqual('alpha', 'beta')).toBe(false)31 expect(await timingSafeEqual(false, true)).toBe(false)

refactor(TypeScript): enable strict null check (#280)Yusuke Wadabefore adoptionb55eb2e

lines 32–33why, one step back
32 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
33 // @ts-ignore

feat(type): anyYusuke Wadabefore adoption1204e12

lines 34–55why, one step back
34 expect(await timingSafeEqual(false, undefined)).toBe(false)
35 expect(36 await timingSafeEqual(37 () => {},38 () => {}39 )40 ).toBe(false)41 expect(await timingSafeEqual({}, {})).toBe(false)42 expect(await timingSafeEqual({ a: 1 }, { a: 1 })).toBe(false)43 expect(await timingSafeEqual({ a: 1 }, { a: 2 })).toBe(false)44 expect(await timingSafeEqual([1, 2], [1, 2])).toBe(false)45 expect(await timingSafeEqual([1, 2], [1, 2, 3])).toBe(false)46 })47})4849describe('bufferToString', () => {50 it('Should return あいうえお', () => {51 const bytes = [227, 129, 130, 227, 129, 132, 227, 129, 134, 227, 129, 136, 227, 129, 138]52 const buffer = Uint8Array.from(bytes).buffer53 expect(bufferToString(buffer)).toBe('あいうえお')54 })55})