diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2024-08-28 20:56:11 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-28 20:56:11 +0530 |
commit | 0e50bb1d4abd80da3fc1be17978760ddfa8560fa (patch) | |
tree | a05bb648a7c593c71fd28dcb88a10760212a5e20 /ext/node/polyfills/internal/crypto | |
parent | b9c144df6fdee9b5e89f6f7787463b366164d622 (diff) |
fix(ext/node): import RSA JWK keys (#25267)
Fixes https://github.com/denoland/deno/issues/24129
Diffstat (limited to 'ext/node/polyfills/internal/crypto')
-rw-r--r-- | ext/node/polyfills/internal/crypto/keys.ts | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/ext/node/polyfills/internal/crypto/keys.ts b/ext/node/polyfills/internal/crypto/keys.ts index 49a618b65..c91c23cc3 100644 --- a/ext/node/polyfills/internal/crypto/keys.ts +++ b/ext/node/polyfills/internal/crypto/keys.ts @@ -16,6 +16,7 @@ import { op_node_create_ed_raw, op_node_create_private_key, op_node_create_public_key, + op_node_create_rsa_jwk, op_node_create_secret_key, op_node_derive_public_key_from_private_key, op_node_export_private_key_der, @@ -324,7 +325,32 @@ function getKeyObjectHandleFromJwk(key, ctx) { return op_node_create_ec_jwk(key, isPublic); } - throw new TypeError("rsa jwk imports not implemented"); + // RSA + validateString(key.n, "key.n"); + validateString(key.e, "key.e"); + + const jwk = { + kty: key.kty, + n: key.n, + e: key.e, + }; + + if (!isPublic) { + validateString(key.d, "key.d"); + validateString(key.p, "key.p"); + validateString(key.q, "key.q"); + validateString(key.dp, "key.dp"); + validateString(key.dq, "key.dq"); + validateString(key.qi, "key.qi"); + jwk.d = key.d; + jwk.p = key.p; + jwk.q = key.q; + jwk.dp = key.dp; + jwk.dq = key.dq; + jwk.qi = key.qi; + } + + return op_node_create_rsa_jwk(jwk, isPublic); } export function prepareAsymmetricKey( |