diff options
author | Asher Gomez <ashersaupingomez@gmail.com> | 2024-03-13 19:17:23 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-13 08:17:23 +0000 |
commit | 5cfa03ceca396b1c21a826cb44a984329cf35078 (patch) | |
tree | b1fae2dafbb53aeff0a3b973c39d6a6bbe03415c /ext/node/polyfills/internal/crypto | |
parent | 6e6c316c9d3950cd23cb28af41b0525695438c3c (diff) |
fix(ext/node): initial `crypto.createPublicKey()` support (#22509)
Closes #21807
Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
Diffstat (limited to 'ext/node/polyfills/internal/crypto')
-rw-r--r-- | ext/node/polyfills/internal/crypto/keys.ts | 24 |
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); |