diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2022-02-01 17:32:10 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-01 17:32:10 +0530 |
commit | abf89f8c4675ed78c992fafd6d758bf4bfca8a1a (patch) | |
tree | 24136ce21b5376f3bea6ac2fa50629484e8c6f02 /ext | |
parent | 7d356250e8bbe4e37e3651b328fda76178489588 (diff) |
fix(ext/crypto): utf16 jwk encoding (#13535)
Diffstat (limited to 'ext')
-rw-r--r-- | ext/crypto/00_crypto.js | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/ext/crypto/00_crypto.js b/ext/crypto/00_crypto.js index aa328d1d7..620b39849 100644 --- a/ext/crypto/00_crypto.js +++ b/ext/crypto/00_crypto.js @@ -12,7 +12,6 @@ const core = window.Deno.core; const webidl = window.__bootstrap.webidl; const { DOMException } = window.__bootstrap.domException; - const { TextEncoder, TextDecoder } = window.__bootstrap.encoding; const { ArrayBuffer, @@ -29,6 +28,8 @@ ObjectAssign, StringPrototypeToLowerCase, StringPrototypeToUpperCase, + StringPrototypeCharCodeAt, + StringFromCharCode, Symbol, SymbolFor, SyntaxError, @@ -1327,8 +1328,11 @@ bytes = new Uint8Array(exportedKey); } else { const jwk = JSONStringify(exportedKey); - - bytes = new TextEncoder("utf-8").encode(jwk); + const ret = new Uint8Array(jwk.length); + for (let i = 0; i < jwk.length; i++) { + ret[i] = StringPrototypeCharCodeAt(jwk, i); + } + bytes = ret; } // 14-15. @@ -1519,9 +1523,12 @@ if (format !== "jwk") { bytes = key; } else { - const utf8 = new TextDecoder("utf-8").decode(key); - - bytes = JSONParse(utf8); + const k = new Uint8Array(key); + let str = ""; + for (let i = 0; i < k.length; i++) { + str += StringFromCharCode(k[i]); + } + bytes = JSONParse(str); } // 15. |