Skip to content

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

@amn

Description

@amn

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions