0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 17:34:47 -05:00

fix(ext/crypto): utf16 jwk encoding (#13535)

This commit is contained in:
Divy Srivastava 2022-02-01 17:32:10 +05:30 committed by GitHub
parent 7d356250e8
commit abf89f8c46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,7 +12,6 @@
const core = window.Deno.core; const core = window.Deno.core;
const webidl = window.__bootstrap.webidl; const webidl = window.__bootstrap.webidl;
const { DOMException } = window.__bootstrap.domException; const { DOMException } = window.__bootstrap.domException;
const { TextEncoder, TextDecoder } = window.__bootstrap.encoding;
const { const {
ArrayBuffer, ArrayBuffer,
@ -29,6 +28,8 @@
ObjectAssign, ObjectAssign,
StringPrototypeToLowerCase, StringPrototypeToLowerCase,
StringPrototypeToUpperCase, StringPrototypeToUpperCase,
StringPrototypeCharCodeAt,
StringFromCharCode,
Symbol, Symbol,
SymbolFor, SymbolFor,
SyntaxError, SyntaxError,
@ -1327,8 +1328,11 @@
bytes = new Uint8Array(exportedKey); bytes = new Uint8Array(exportedKey);
} else { } else {
const jwk = JSONStringify(exportedKey); const jwk = JSONStringify(exportedKey);
const ret = new Uint8Array(jwk.length);
bytes = new TextEncoder("utf-8").encode(jwk); for (let i = 0; i < jwk.length; i++) {
ret[i] = StringPrototypeCharCodeAt(jwk, i);
}
bytes = ret;
} }
// 14-15. // 14-15.
@ -1519,9 +1523,12 @@
if (format !== "jwk") { if (format !== "jwk") {
bytes = key; bytes = key;
} else { } else {
const utf8 = new TextDecoder("utf-8").decode(key); const k = new Uint8Array(key);
let str = "";
bytes = JSONParse(utf8); for (let i = 0; i < k.length; i++) {
str += StringFromCharCode(k[i]);
}
bytes = JSONParse(str);
} }
// 15. // 15.