summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/internal/crypto/keys.ts
diff options
context:
space:
mode:
Diffstat (limited to 'ext/node/polyfills/internal/crypto/keys.ts')
-rw-r--r--ext/node/polyfills/internal/crypto/keys.ts24
1 files changed, 20 insertions, 4 deletions
diff --git a/ext/node/polyfills/internal/crypto/keys.ts b/ext/node/polyfills/internal/crypto/keys.ts
index ab753582f..33034d824 100644
--- a/ext/node/polyfills/internal/crypto/keys.ts
+++ b/ext/node/polyfills/internal/crypto/keys.ts
@@ -4,7 +4,10 @@
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
-import { op_node_create_private_key } from "ext:core/ops";
+import {
+ op_node_create_private_key,
+ op_node_create_public_key,
+} from "ext:core/ops";
import {
kHandle,
@@ -239,9 +242,12 @@ export function createPrivateKey(
}
export function createPublicKey(
- _key: PublicKeyInput | string | Buffer | KeyObject | JsonWebKeyInput,
-): KeyObject {
- notImplemented("crypto.createPublicKey");
+ key: PublicKeyInput | string | Buffer | JsonWebKeyInput,
+): PublicKeyObject {
+ const { data, format, type } = prepareAsymmetricKey(key);
+ const details = op_node_create_public_key(data, format, type);
+ const handle = setOwnedKey(copyBuffer(data));
+ return new PublicKeyObject(handle, details);
}
function getKeyTypes(allowKeyObject: boolean, bufferOnly = false) {
@@ -358,6 +364,16 @@ class PrivateKeyObject extends AsymmetricKeyObject {
}
}
+class PublicKeyObject extends AsymmetricKeyObject {
+ constructor(handle: unknown, details: unknown) {
+ super("public", handle, details);
+ }
+
+ export(_options: unknown) {
+ notImplemented("crypto.PublicKeyObject.prototype.export");
+ }
+}
+
export function setOwnedKey(key: Uint8Array): unknown {
const handle = {};
KEY_STORE.set(handle, key);