From: Chris Duncan Date: Thu, 14 May 2026 13:54:01 +0000 (-0700) Subject: Throw if hex input is an odd number of characters. X-Git-Tag: v1.0.3~4 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=a3f114bacc11805d9b245a1e1dcaa6d586f2a8d4;p=nano25519.git Throw if hex input is an odd number of characters. --- diff --git a/src/lib/nano25519.ts b/src/lib/nano25519.ts index c9d6fca..5654d22 100644 --- a/src/lib/nano25519.ts +++ b/src/lib/nano25519.ts @@ -152,7 +152,10 @@ const nano25519_init = (bytes: number[]): { derive: typeof derive, sign: typeof if (typeof value === 'string') { const regex = RegExp(`^[A-Fa-f0-9]{${byteLengthMin << 1},${byteLengthMax << 1}}$`) if (!regex.test(value)) { - throw new TypeError(`Invalid ${name} ${value}`) + throw new TypeError(`Invalid hexadecimal characters in ${name} ${value}`) + } + if (value.length & 1) { + throw new TypeError(`Invalid hexadecimal length for ${name} ${value}`) } value = new Uint8Array(value.match(/[A-Fa-f0-9]{2}/g)?.map(b => parseInt(b, 16)) || []) }