diff options
Diffstat (limited to 'ext/crypto/00_crypto.js')
-rw-r--r-- | ext/crypto/00_crypto.js | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/ext/crypto/00_crypto.js b/ext/crypto/00_crypto.js index f76232136..6408d39d4 100644 --- a/ext/crypto/00_crypto.js +++ b/ext/crypto/00_crypto.js @@ -12,6 +12,7 @@ const core = window.Deno.core; const webidl = window.__bootstrap.webidl; const { DOMException } = window.__bootstrap.domException; + const { TextEncoder, TextDecoder } = window.__bootstrap.encoding; const { ArrayBuffer, @@ -23,6 +24,8 @@ Int16Array, Int32Array, Int8Array, + JSONParse, + JSONStringify, ObjectAssign, StringPrototypeToLowerCase, StringPrototypeToUpperCase, @@ -1259,11 +1262,9 @@ if (format !== "jwk") { bytes = new Uint8Array(exportedKey); } else { - // TODO(@littledivy): Implement JWK. - throw new DOMException( - "Not implemented", - "NotSupportedError", - ); + const jwk = JSONStringify(exportedKey); + + bytes = new TextEncoder("utf-8").encode(jwk); } // 14-15. @@ -1278,7 +1279,17 @@ } else if ( supportedAlgorithms["encrypt"][normalizedAlgorithm.name] !== undefined ) { - return await encrypt(normalizedAlgorithm, wrappingKey, bytes); + return await encrypt( + normalizedAlgorithm, + constructKey( + wrappingKey[_type], + wrappingKey[_extractable], + ["encrypt"], + wrappingKey[_algorithm], + wrappingKey[_handle], + ), + bytes, + ); } else { throw new DOMException( "Algorithm not supported", @@ -1390,7 +1401,13 @@ ) { key = await this.decrypt( normalizedAlgorithm, - unwrappingKey, + constructKey( + unwrappingKey[_type], + unwrappingKey[_extractable], + ["decrypt"], + unwrappingKey[_algorithm], + unwrappingKey[_handle], + ), wrappedKey, ); } else { @@ -1400,14 +1417,14 @@ ); } + let bytes; // 14. - const bytes = key; - if (format == "jwk") { - // TODO(@littledivy): Implement JWK. - throw new DOMException( - "Not implemented", - "NotSupportedError", - ); + if (format !== "jwk") { + bytes = key; + } else { + const utf8 = new TextDecoder("utf-8").decode(key); + + bytes = JSONParse(utf8); } // 15. |