From: Chris Duncan Date: Sat, 29 Aug 2026 06:33:32 +0000 (-0700) Subject: Fix buffer slicing when normalizing. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=dc026bf9a285d8ba3f6a6aa19ed36f95cb3d6d52;p=nano25519.git Fix buffer slicing when normalizing. --- diff --git a/src/lib/wasm.ts b/src/lib/wasm.ts index f08d3d1..37bdbb4 100644 --- a/src/lib/wasm.ts +++ b/src/lib/wasm.ts @@ -124,10 +124,13 @@ export function normalize (name: string, byteLengthMin: number, byteLengthMax: n return new Uint8Array(value.match(/[0-9a-f]{2}/gi)?.map(b => parseInt(b, 16)) || []) } - if (!(value instanceof ArrayBuffer || value instanceof Uint8Array)) { + if (value instanceof ArrayBuffer) { + value = new Uint8Array(value) + } + if (!(value instanceof Uint8Array)) { throw new TypeError(`${name} must be Uint8Array or ArrayBuffer`) } - const bytes = new Uint8Array(value.slice()) + const bytes = value.slice() if (bytes.byteLength < byteLengthMin) { throw new TypeError(`${name} must be at least ${byteLengthMin} bytes`) }