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 b7d8f2f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/node/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,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
8 changes: 8 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,11 @@ export const timingSafeEqualTest = {
timingSafeEqual(new Uint8Array(1), new Uint8Array(1));
},
};

export const getRandomValuesIllegalInvocation = {
async test() {
const crypto = await import('node:crypto');
const getRandomValues = crypto.getRandomValues;
strictEqual(getRandomValues(new Uint8Array(6)).length, 6);
},
};

0 comments on commit b7d8f2f

Please sign in to comment.