summaryrefslogtreecommitdiff
path: root/ext/crypto/00_crypto.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/crypto/00_crypto.js')
-rw-r--r--ext/crypto/00_crypto.js61
1 files changed, 60 insertions, 1 deletions
diff --git a/ext/crypto/00_crypto.js b/ext/crypto/00_crypto.js
index 85849153d..55e1ba9ad 100644
--- a/ext/crypto/00_crypto.js
+++ b/ext/crypto/00_crypto.js
@@ -975,6 +975,66 @@
return key;
}
+ // TODO(@littledivy): RSA-PSS
+ case "ECDSA": {
+ switch (format) {
+ case "raw": {
+ // 1.
+ if (
+ !ArrayPrototypeIncludes(
+ supportedNamedCurves,
+ normalizedAlgorithm.namedCurve,
+ )
+ ) {
+ throw new DOMException(
+ "Invalid namedCurve",
+ "DataError",
+ );
+ }
+
+ // 2.
+ if (
+ ArrayPrototypeFind(
+ keyUsages,
+ (u) => !ArrayPrototypeIncludes(["verify"], u),
+ ) !== undefined
+ ) {
+ throw new DOMException("Invalid key usages", "SyntaxError");
+ }
+
+ // 3.
+ const { data } = await core.opAsync("op_crypto_import_key", {
+ algorithm: "ECDSA",
+ namedCurve: normalizedAlgorithm.namedCurve,
+ }, keyData);
+
+ const handle = {};
+ WeakMapPrototypeSet(KEY_STORE, handle, {
+ type: "raw",
+ data,
+ });
+
+ // 4-5.
+ const algorithm = {
+ name: "ECDSA",
+ namedCurve: normalizedAlgorithm.namedCurve,
+ };
+
+ // 6-8.
+ const key = constructKey(
+ "public",
+ extractable,
+ usageIntersection(keyUsages, recognisedUsages),
+ algorithm,
+ handle,
+ );
+
+ return key;
+ }
+ default:
+ throw new DOMException("Not implemented", "NotSupportedError");
+ }
+ }
case "RSASSA-PKCS1-v1_5": {
switch (format) {
case "pkcs8": {
@@ -1149,7 +1209,6 @@
throw new DOMException("Not implemented", "NotSupportedError");
}
}
- // TODO(@littledivy): ECDSA
case "HKDF": {
if (format !== "raw") {
throw new DOMException("Format not supported", "NotSupportedError");