mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
fix(ext/crypto): take a copy of keyData bytes (#11666)
This commit is contained in:
parent
8481377500
commit
c1f97056f4
2 changed files with 33 additions and 0 deletions
|
@ -1,5 +1,26 @@
|
|||
import { assert, assertEquals, unitTest } from "./test_util.ts";
|
||||
|
||||
// https://github.com/denoland/deno/issues/11664
|
||||
unitTest(async function testImportArrayBufferKey() {
|
||||
const subtle = window.crypto.subtle;
|
||||
assert(subtle);
|
||||
|
||||
// deno-fmt-ignore
|
||||
const key = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
|
||||
|
||||
const cryptoKey = await subtle.importKey(
|
||||
"raw",
|
||||
key.buffer,
|
||||
{ name: "HMAC", hash: "SHA-1" },
|
||||
true,
|
||||
["sign"],
|
||||
);
|
||||
assert(cryptoKey);
|
||||
|
||||
// Test key usage
|
||||
await subtle.sign({ name: "HMAC" }, cryptoKey, new Uint8Array(8));
|
||||
});
|
||||
|
||||
// TODO(@littledivy): Remove this when we enable WPT for sign_verify
|
||||
unitTest(async function testSignVerify() {
|
||||
const subtle = window.crypto.subtle;
|
||||
|
|
|
@ -463,6 +463,18 @@
|
|||
context: "Argument 5",
|
||||
});
|
||||
|
||||
// 2.
|
||||
if (ArrayBufferIsView(keyData)) {
|
||||
keyData = new Uint8Array(
|
||||
keyData.buffer,
|
||||
keyData.byteOffset,
|
||||
keyData.byteLength,
|
||||
);
|
||||
} else {
|
||||
keyData = new Uint8Array(keyData);
|
||||
}
|
||||
keyData = TypedArrayPrototypeSlice(keyData);
|
||||
|
||||
const normalizedAlgorithm = normalizeAlgorithm(algorithm, "importKey");
|
||||
|
||||
if (
|
||||
|
|
Loading…
Reference in a new issue