1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-11 08:33:43 -05:00

fix(ext/crypto): handle idlValue not being present (#11685)

This commit is contained in:
Divy Srivastava 2021-08-13 23:04:24 +05:30 committed by GitHub
parent 74d523e924
commit c6e3f93ebb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -88,6 +88,7 @@
}; };
// See https://www.w3.org/TR/WebCryptoAPI/#dfn-normalize-an-algorithm // See https://www.w3.org/TR/WebCryptoAPI/#dfn-normalize-an-algorithm
// 18.4.4
function normalizeAlgorithm(algorithm, op) { function normalizeAlgorithm(algorithm, op) {
if (typeof algorithm == "string") { if (typeof algorithm == "string") {
return normalizeAlgorithm({ name: algorithm }, op); return normalizeAlgorithm({ name: algorithm }, op);
@ -125,18 +126,22 @@
return { name: algName }; return { name: algName };
} }
// 6.
const normalizedAlgorithm = webidl.converters[desiredType](algorithm, { const normalizedAlgorithm = webidl.converters[desiredType](algorithm, {
prefix: "Failed to normalize algorithm", prefix: "Failed to normalize algorithm",
context: "passed algorithm", context: "passed algorithm",
}); });
// 7.
normalizedAlgorithm.name = algName; normalizedAlgorithm.name = algName;
// 9.
const dict = simpleAlgorithmDictionaries[desiredType]; const dict = simpleAlgorithmDictionaries[desiredType];
// 10.
for (const member in dict) { for (const member in dict) {
const idlType = dict[member]; const idlType = dict[member];
const idlValue = normalizedAlgorithm[member]; const idlValue = normalizedAlgorithm[member];
// 3.
if (idlType === "BufferSource") { if (idlType === "BufferSource" && idlValue) {
normalizedAlgorithm[member] = new Uint8Array( normalizedAlgorithm[member] = new Uint8Array(
TypedArrayPrototypeSlice( TypedArrayPrototypeSlice(
(ArrayBufferIsView(idlValue) ? idlValue.buffer : idlValue), (ArrayBufferIsView(idlValue) ? idlValue.buffer : idlValue),