Skip to content

Commit

Permalink
revert: ⏪ revert delete of RandomTypedArrays (margelo#330)
Browse files Browse the repository at this point in the history
* revert: ⏪ revert delete of RandomTypedArrays

* revert: ⏪ add RandomTypedArrays for tests
  • Loading branch information
DavideSegullo committed Jun 2, 2024
1 parent 39aeb85 commit 56ae784
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
9 changes: 3 additions & 6 deletions example/src/testing/Tests/webcryptoTests/import_export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ import {
} from 'react-native-quick-base64';
import crypto from 'react-native-quick-crypto';
import { describe, it } from '../../MochaRNAdapter';
import {
ab2str,
binaryLikeToArrayBuffer,
type TypedArray,
} from '../../../../../src/Utils';
import { ab2str, binaryLikeToArrayBuffer } from '../../../../../src/Utils';
import { assertThrowsAsync } from '../util';
import type { JWK, KeyUsage, NamedCurve } from '../../../../../src/keys';
import type { RandomTypedArrays } from '../../../../../src/random';

const { subtle } = crypto;

Expand Down Expand Up @@ -238,7 +235,7 @@ describe('subtle - importKey / exportKey', () => {
expect(key.keyAlgorithm.length).to.equal(256);
});

const test = (rawKeyData: TypedArray, descr: string): void => {
const test = (rawKeyData: RandomTypedArrays, descr: string): void => {
it(`AES import raw / export jwk (${descr})`, async () => {
const keyData = binaryLikeToArrayBuffer(rawKeyData);
const keyB64 = arrayBufferToBase64(keyData, true);
Expand Down
13 changes: 12 additions & 1 deletion src/random.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,18 @@ function asyncRefillRandomIntCache() {
});
}

export function getRandomValues(data: TypedArray) {
// to require('crypto').randomFillSync() with an
// additional limitation that the input buffer is
// not allowed to exceed 65536 bytes, and can only
// be an integer-type TypedArray.
export type RandomTypedArrays =
| Int8Array
| Int16Array
| Int32Array
| Uint8Array
| Uint16Array
| Uint32Array;
export function getRandomValues(data: RandomTypedArrays) {
if (data.byteLength > 65536) {
throw new Error('The requested length exceeds 65,536 bytes');
}
Expand Down

0 comments on commit 56ae784

Please sign in to comment.