Skip to content

Commit

Permalink
fix invalid invocation on getRandomValues()
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Sep 17, 2024
1 parent 563d72f commit e54450b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/node/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
//
import { ERR_METHOD_NOT_IMPLEMENTED } from 'node-internal:internal_errors';

// eslint-disable-next-line @typescript-eslint/unbound-method
export const getRandomValues = crypto.getRandomValues;
export const getRandomValues = crypto.getRandomValues.bind(crypto);
export const subtle = crypto.subtle;
export const webcrypto = crypto;

Expand Down
10 changes: 10 additions & 0 deletions src/workerd/api/node/tests/crypto_random-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,13 @@ export const timingSafeEqualTest = {
timingSafeEqual(new Uint8Array(1), new Uint8Array(1));
},
};

// Ref: https://github.com/cloudflare/workerd/issues/2716
export const getRandomValuesIllegalInvocation = {
async test() {
const crypto = await import('node:crypto');
const getRandomValues = crypto.getRandomValues;
strictEqual(getRandomValues(new Uint8Array(6)).length, 6);
strictEqual(crypto.getRandomValues(new Uint8Array(6)).length, 6);
},
};

0 comments on commit e54450b

Please sign in to comment.