GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — crypto: copy parameters without array species · nodejs/node@7db05b5

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/crypto
    • util.js
  • test/parallel
    • test-webcrypto-parameter-species.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/crypto/util.js‎

Copy file name to clipboardExpand all lines: lib/internal/crypto/util.js
+6-9Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const {
1212
DataViewPrototypeGetByteLength,
1313
DataViewPrototypeGetByteOffset,
1414
MathFloor,
15+
MathMin,
1516
Number,
1617
ObjectDefineProperty,
1718
ObjectEntries,
@@ -31,7 +32,6 @@ const {
3132
TypedArrayPrototypeGetByteLength,
3233
TypedArrayPrototypeGetByteOffset,
3334
TypedArrayPrototypeGetLength,
34-
TypedArrayPrototypeSlice,
3535
Uint8Array,
3636
} = primordials;
3737

@@ -712,14 +712,11 @@ function truncateToBitLength(length, bytes) {
712712
new Uint8Array(
713713
getDataViewOrTypedArrayBuffer(bytes),
714714
getDataViewOrTypedArrayByteOffset(bytes),
715-
getDataViewOrTypedArrayByteLength(bytes),
715+
MathMin(lengthBytes, getDataViewOrTypedArrayByteLength(bytes)),
716716
) :
717-
new Uint8Array(bytes, 0, ArrayBufferPrototypeGetByteLength(bytes));
718-
const result = TypedArrayPrototypeSlice(
719-
byteView,
720-
0,
721-
lengthBytes,
722-
);
717+
new Uint8Array(bytes, 0,
718+
MathMin(lengthBytes, ArrayBufferPrototypeGetByteLength(bytes)));
719+
const result = new Uint8Array(byteView);
723720

724721
const remainder = length % 8;
725722
if (remainder !== 0)
@@ -795,7 +792,7 @@ function normalizeAlgorithm(algorithm, op) {
795792
const idlValue = normalizedAlgorithm[member];
796793
// 3.
797794
if (idlType === 'BufferSource' && idlValue) {
798-
normalizedAlgorithm[member] = TypedArrayPrototypeSlice(
795+
normalizedAlgorithm[member] = new Uint8Array(
799796
getBufferSourceBytes(idlValue),
800797
);
801798
} else if (idlType === 'HashAlgorithmIdentifier') {
Collapse file

‎test/parallel/test-webcrypto-parameter-species.js‎

Copy file name to clipboard
+36Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
if (!common.hasCrypto)
5+
common.skip('missing crypto');
6+
7+
const assert = require('assert');
8+
const { subtle } = globalThis.crypto;
9+
10+
function withSpecies(callback) {
11+
Object.defineProperty(Uint8Array, Symbol.species, {
12+
configurable: true,
13+
value: Float64Array,
14+
});
15+
try {
16+
return callback();
17+
} finally {
18+
delete Uint8Array[Symbol.species];
19+
}
20+
}
21+
22+
(async () => {
23+
const key = await subtle.importKey('raw', new Uint8Array(16),
24+
'AES-GCM', false, ['encrypt']);
25+
const algorithm = { name: 'AES-GCM', iv: new Uint8Array(12).fill(1) };
26+
const data = new Uint8Array(16);
27+
const expected = await subtle.encrypt(algorithm, key, data);
28+
assert.deepStrictEqual(await withSpecies(() => subtle.encrypt(algorithm, key, data)), expected);
29+
30+
const hmac = { name: 'HMAC', hash: 'SHA-256', length: 100 };
31+
const secret = new Uint8Array(13).fill(1);
32+
const normal = await subtle.importKey('raw', secret, hmac, true, ['sign']);
33+
const tampered = await withSpecies(() => subtle.importKey('raw', secret, hmac, true, ['sign']));
34+
assert.deepStrictEqual(await subtle.exportKey('raw', tampered), await subtle.exportKey('raw', normal));
35+
assert.deepStrictEqual(await subtle.sign('HMAC', tampered, data), await subtle.sign('HMAC', normal, data));
36+
})().then(common.mustCall());

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.