Skip to content

Commit

Permalink
chore: use more restrictive types for timingSafeEqual (#936)
Browse files Browse the repository at this point in the history
This is a types-only change.

[`crypto.timingSafeEqual`][0] has some subtle behavior (highlighted in
bold red in the docs!) when passing a `Float32Array` or `Float64Array`.
Rather than adapt our wrapper to support this unusual situation, this
updates the types to avoid it.

We never took advantage of this unusual case, and now we are even less
likely to.

[0]: https://nodejs.org/api/crypto.html#cryptotimingsafeequala-b
  • Loading branch information
EvanHahn authored Oct 22, 2024
1 parent 5975e03 commit bddf7be
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/lib/timing-safe-equal.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as crypto from 'node:crypto'

/**
* @param {string | NodeJS.ArrayBufferView} value
* @returns {NodeJS.ArrayBufferView}
* @param {Readonly<string | Uint8Array>} value
* @returns {Uint8Array}
*/
const bufferify = (value) =>
// We use UTF-16 because it's the only supported encoding that doesn't
Expand All @@ -19,7 +19,7 @@ const bufferify = (value) =>
* Like `crypto.timingSafeEqual`, but works with strings and doesn't throw if
* lengths differ.
*
* @template {string | NodeJS.ArrayBufferView} T
* @template {string | Uint8Array} T
* @param {T} a
* @param {T} b
* @returns {boolean}
Expand Down

0 comments on commit bddf7be

Please sign in to comment.