]> git.codecow.com Git - nano25519.git/commitdiff
Add more type checking on batch block length. Capture String static method.
authorChris Duncan <chris@codecow.com>
Fri, 16 Oct 2026 16:23:06 +0000 (09:23 -0700)
committerChris Duncan <chris@codecow.com>
Fri, 16 Oct 2026 16:23:06 +0000 (09:23 -0700)
src/lib/bytes.ts
src/lib/verify.ts

index 835ca1b70daa04650ede25272463fdb5fd6bef41..567650adda97a887c2c0ea336aaca59ca7054668 100644 (file)
@@ -7,12 +7,12 @@ import { Nano25519RangeError, Nano25519TypeError, } from './errors'
  * Prototype methods and accessors used on a call path, captured once when this
  * module is evaluated and called through a bound `Function.prototype.call`, so
  * that code patching a prototype afterwards cannot change what is validated,
- * copied, scrubbed or decoded. The `%TypedArray%.prototype` getters also read
- * internal slots, which a caller's subclass cannot override, so use these
- * helpers on every typed array instead of its own properties. Use the captured
- * `allocate()` and `words()` instead of `Uint8Array` and `Uint32Array`. Other
- * global constructors and static functions are looked up at time-of-call, and
- * capturing them is out of scope.
+ * copied, scrubbed or decoded. Static functions are captured on load, and the
+ * bound functions are used instead. The `%TypedArray%.prototype` getters also
+ * read internal slots, which a caller's subclass cannot override, so use these
+ * helpers on every typed array instead of its own properties, and use
+ * `allocate(byteLength)` instead of `new Uint8Array(byteLength)` and
+ * `words(buffer)` instead of `new Uint32Array(buffer)`.
  */
 
 /** Type aliases for legibility. */
@@ -111,6 +111,7 @@ export function words (bytes: Bytes): Words {
 }
 
 const charCodeAt = Function.prototype.call.bind(String.prototype.charCodeAt)
+const fromCharCode = String.fromCharCode
 
 /** 0-9a-f for a valid hex digit 0..15 */
 function hexcode (c: number): number {
@@ -137,7 +138,7 @@ export function bytesToHex (bytes: Uint8Array): string {
        let hex = ''
        for (let i = 0; i < byteLength; i++) {
                const byte = bytes[i]
-               hex += String.fromCharCode(hexcode(byte >> 4), hexcode(byte & 15))
+               hex += fromCharCode(hexcode(byte >> 4), hexcode(byte & 15))
        }
        return hex
 }
index 6fec00733e7beda1a876266edd5f93d7083141e5..48ad7b98850a192173a965703da589aa1aba9047 100644 (file)
@@ -32,7 +32,7 @@ export function verify (sig: unknown, msg: unknown, pub: unknown): boolean {
 export function verify_blocks (pub: unknown, data: unknown): readonly boolean[] {
        const blocks: unknown[] = isArray(data) ? data : [data]
        const count: unknown = blocks.length
-       if (typeof count !== 'number') {
+       if (typeof count !== 'number' || !count || count === Infinity || count === -Infinity) {
                throw new Nano25519TypeError('Invalid blocks length', { cause: data })
        }
        if (count < 1) {