summaryrefslogtreecommitdiff
path: root/ext/crypto/00_crypto.js
diff options
context:
space:
mode:
authordiachedelic <diachedelic@gmail.com>2022-06-08 12:59:42 +1000
committerGitHub <noreply@github.com>2022-06-08 08:29:42 +0530
commitff5def9ed5725f853f0a2cd33662211ce3418317 (patch)
treef241dc2476f33884ff3e8873075a58124b581890 /ext/crypto/00_crypto.js
parent753f32024f2dcbdf0b90df95929bfea6b6068556 (diff)
feat(ext/crypto): export elliptic keys as "raw" (#14764)
This commit adds support for the "raw" format when exporting public ECDH/ECDSA keys via the SubtleCrypto.exportKey method.
Diffstat (limited to 'ext/crypto/00_crypto.js')
-rw-r--r--ext/crypto/00_crypto.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/ext/crypto/00_crypto.js b/ext/crypto/00_crypto.js
index c825089e7..2b14a204e 100644
--- a/ext/crypto/00_crypto.js
+++ b/ext/crypto/00_crypto.js
@@ -3433,6 +3433,24 @@
function exportKeyEC(format, key, innerKey) {
switch (format) {
+ case "raw": {
+ // 1.
+ if (key[_type] !== "public") {
+ throw new DOMException(
+ "Key is not a public key",
+ "InvalidAccessError",
+ );
+ }
+
+ // 2.
+ const data = core.opSync("op_crypto_export_key", {
+ algorithm: key[_algorithm].name,
+ namedCurve: key[_algorithm].namedCurve,
+ format: "raw",
+ }, innerKey);
+
+ return data.buffer;
+ }
case "pkcs8": {
// 1.
if (key[_type] !== "private") {