diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2023-02-20 22:22:28 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-20 22:22:28 +0530 |
commit | ea7ca00c895c401af57a7201f3c41524333e7939 (patch) | |
tree | a238ea54a003111ab6c1b7b1cb14e0669cb4f7af /ext/node/polyfills/internal/crypto/cipher.ts | |
parent | a16c11c5d10052c688ba4c2eca09fd1a225e395a (diff) |
perf: use ops for node:crypto ciphers (#17819)
Towards #17809
Diffstat (limited to 'ext/node/polyfills/internal/crypto/cipher.ts')
-rw-r--r-- | ext/node/polyfills/internal/crypto/cipher.ts | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/ext/node/polyfills/internal/crypto/cipher.ts b/ext/node/polyfills/internal/crypto/cipher.ts index 2778b40fa..ddef00076 100644 --- a/ext/node/polyfills/internal/crypto/cipher.ts +++ b/ext/node/polyfills/internal/crypto/cipher.ts @@ -16,19 +16,8 @@ import type { BinaryLike, Encoding, } from "internal:deno_node/polyfills/internal/crypto/types.ts"; -import { - privateDecrypt, - privateEncrypt, - publicDecrypt, - publicEncrypt, -} from "internal:deno_node/polyfills/_crypto/crypto_browserify/public_encrypt/mod.js"; -export { - privateDecrypt, - privateEncrypt, - publicDecrypt, - publicEncrypt, -} from "internal:deno_node/polyfills/_crypto/crypto_browserify/public_encrypt/mod.js"; +const { ops } = globalThis.__bootstrap.core; export type CipherCCMTypes = | "aes-128-ccm" @@ -281,6 +270,34 @@ export function getCipherInfo( notImplemented("crypto.getCipherInfo"); } +export function privateEncrypt( + privateKey: ArrayBufferView | string | KeyObject, + buffer: ArrayBufferView | string | KeyObject, +): Buffer { + const padding = privateKey.padding || 1; + return ops.op_node_private_encrypt(privateKey, buffer, padding); +} + +export function privateDecrypt( + privateKey: ArrayBufferView | string | KeyObject, + buffer: ArrayBufferView | string | KeyObject, +): Buffer { + const padding = privateKey.padding || 1; + return ops.op_node_private_decrypt(privateKey, buffer, padding); +} + +export function publicEncrypt( + publicKey: ArrayBufferView | string | KeyObject, + buffer: ArrayBufferView | string | KeyObject, +): Buffer { + const padding = publicKey.padding || 1; + return ops.op_node_public_encrypt(publicKey, buffer, padding); +} + +export function publicDecrypt() { + notImplemented("crypto.publicDecrypt"); +} + export default { privateDecrypt, privateEncrypt, |