]> git.codecow.com Git - nano25519.git/commitdiff
Throw if hex input is an odd number of characters.
authorChris Duncan <chris@codecow.com>
Thu, 14 May 2026 13:54:01 +0000 (06:54 -0700)
committerChris Duncan <chris@codecow.com>
Thu, 14 May 2026 13:54:01 +0000 (06:54 -0700)
src/lib/nano25519.ts

index c9d6fca22dfb6ebefe7635dc5b15d5756dbfb71a..5654d22dd418b5de005e38d8d0a5f7f560cfa682 100644 (file)
@@ -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)) || [])
                }