w3c / w3c/webcrypto

Why isn't `crypto.getRandomValues` accept a data view?

Open
#284 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
294
Forks
78
PR merge metrics
No merged PRs in 30d

Description

I struggle to understand why crypto.getRandomValues doesn't accept a DataView object?

Indeed, the spec. says:

If array is not an Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, BigInt64Array, or BigUint64Array, then throw a TypeMismatchError and terminate the algorithm.

Is there any reason why DataView isn't among these acceptable classes of objects? Does the procedure actually utilize different writing granularity depending on what kind of typed array it is provided, and hence it wouldn't be meaningful for it to work with a view? It could access the underlying buffer anyway, wouldn't it? I mean, this would certainly be implementation defined -- how the procedure loads the underlying buffer with the random data -- but can't a case be made that if all of the above are allowed, principally providing access to an underlying buffer, then so should be DataView? That's what it's for, isn't it? On that note, even passing ArrayBuffer could be acceptable then, on the same argument, no?

Apologies if I have missed something obvious.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Crypto.getRandomValues procedure linked in the issue and compare its accepted typed-array classes with DataView and ArrayBuffer behavior. Determine whether the desired outcome is a specification change or an explanation of the existing restriction; done means the issue has a documented rationale or a decided proposal for supported input types.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api, security
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.