diff options
author | Luca Casonato <hello@lcas.dev> | 2021-12-10 15:06:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-10 15:06:03 +0100 |
commit | 292682772691402bb3c1e4fee554d85746147621 (patch) | |
tree | 2df72a3edd51cf7bac39412a05f2c36cbf7de34a /ext/crypto/00_crypto.js | |
parent | 38f163022373c9adb050f17140f7d29bb403abe2 (diff) |
refactor(ext/crypto): clean up rust side importKey (#13036)
This commit cleans up the Rust side of `import_key` by using a bunch of
enums instead of structs with "type" and "data" fields.
This commit does add some duplicated code for the time being, because
a lot of the other ops still need to get the same cleanup treatment.
Diffstat (limited to 'ext/crypto/00_crypto.js')
-rw-r--r-- | ext/crypto/00_crypto.js | 70 |
1 files changed, 29 insertions, 41 deletions
diff --git a/ext/crypto/00_crypto.js b/ext/crypto/00_crypto.js index ddc88bdcb..16c862829 100644 --- a/ext/crypto/00_crypto.js +++ b/ext/crypto/00_crypto.js @@ -759,6 +759,7 @@ * @param {KeyUsages[]} keyUsages * @returns {Promise<any>} */ + // deno-lint-ignore require-await async importKey(format, keyData, algorithm, extractable, keyUsages) { webidl.assertBranded(this, SubtleCrypto); const prefix = "Failed to execute 'importKey' on 'SubtleCrypto'"; @@ -812,7 +813,7 @@ ); } case "ECDSA": { - return await importKeyECDSA( + return importKeyECDSA( format, normalizedAlgorithm, keyData, @@ -823,7 +824,7 @@ case "RSASSA-PKCS1-v1_5": case "RSA-PSS": case "RSA-OAEP": { - return await importKeyRSA( + return importKeyRSA( format, normalizedAlgorithm, keyData, @@ -850,7 +851,7 @@ ); } case "AES-KW": { - return await importKeyAES( + return importKeyAES( format, normalizedAlgorithm, keyData, @@ -2194,7 +2195,7 @@ return key; } - async function importKeyECDSA( + function importKeyECDSA( format, normalizedAlgorithm, keyData, @@ -2227,16 +2228,13 @@ } // 3. - const { data } = await core.opAsync("op_crypto_import_key", { + const { rawData } = core.opSync("op_crypto_import_key", { algorithm: "ECDSA", namedCurve: normalizedAlgorithm.namedCurve, - }, keyData); + }, { raw: keyData }); const handle = {}; - WeakMapPrototypeSet(KEY_STORE, handle, { - type: "public", - data, - }); + WeakMapPrototypeSet(KEY_STORE, handle, rawData); // 4-5. const algorithm = { @@ -2275,7 +2273,7 @@ }, }; - async function importKeyRSA( + function importKeyRSA( format, normalizedAlgorithm, keyData, @@ -2299,23 +2297,18 @@ } // 2-9. - const { modulusLength, publicExponent, data } = await core - .opAsync( - "op_crypto_import_key", - { - algorithm: normalizedAlgorithm.name, - format: "pkcs8", - // Needed to perform step 7 without normalization. - hash: normalizedAlgorithm.hash.name, - }, - keyData, - ); + const { modulusLength, publicExponent, rawData } = core.opSync( + "op_crypto_import_key", + { + algorithm: normalizedAlgorithm.name, + // Needed to perform step 7 without normalization. + hash: normalizedAlgorithm.hash.name, + }, + { pkcs8: keyData }, + ); const handle = {}; - WeakMapPrototypeSet(KEY_STORE, handle, { - type: "private", - data, - }); + WeakMapPrototypeSet(KEY_STORE, handle, rawData); const algorithm = { name: normalizedAlgorithm.name, @@ -2350,23 +2343,18 @@ } // 2-9. - const { modulusLength, publicExponent, data } = await core - .opAsync( - "op_crypto_import_key", - { - algorithm: normalizedAlgorithm.name, - format: "spki", - // Needed to perform step 7 without normalization. - hash: normalizedAlgorithm.hash.name, - }, - keyData, - ); + const { modulusLength, publicExponent, rawData } = core.opSync( + "op_crypto_import_key", + { + algorithm: normalizedAlgorithm.name, + // Needed to perform step 7 without normalization. + hash: normalizedAlgorithm.hash.name, + }, + { spki: keyData }, + ); const handle = {}; - WeakMapPrototypeSet(KEY_STORE, handle, { - type: "public", - data, - }); + WeakMapPrototypeSet(KEY_STORE, handle, rawData); const algorithm = { name: normalizedAlgorithm.name, |