diff options
Diffstat (limited to 'ext/node/polyfills/internal/crypto')
-rw-r--r-- | ext/node/polyfills/internal/crypto/cipher.ts | 41 | ||||
-rw-r--r-- | ext/node/polyfills/internal/crypto/util.ts | 25 |
2 files changed, 52 insertions, 14 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, diff --git a/ext/node/polyfills/internal/crypto/util.ts b/ext/node/polyfills/internal/crypto/util.ts index f9fce8b2d..8a7f7a1b6 100644 --- a/ext/node/polyfills/internal/crypto/util.ts +++ b/ext/node/polyfills/internal/crypto/util.ts @@ -1,7 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // Copyright Joyent, Inc. and Node.js contributors. All rights reserved. MIT license. -import { getCiphers } from "internal:deno_node/polyfills/_crypto/crypto_browserify/browserify_aes/mod.js"; import { notImplemented } from "internal:deno_node/polyfills/_utils.ts"; import { Buffer } from "internal:deno_node/polyfills/buffer.ts"; import { @@ -47,6 +46,28 @@ const digestAlgorithms = [ "sha1", ]; +// deno-fmt-ignore +const supportedCiphers = [ + "aes-128-ecb", "aes-192-ecb", + "aes-256-ecb", "aes-128-cbc", + "aes-192-cbc", "aes-256-cbc", + "aes128", "aes192", + "aes256", "aes-128-cfb", + "aes-192-cfb", "aes-256-cfb", + "aes-128-cfb8", "aes-192-cfb8", + "aes-256-cfb8", "aes-128-cfb1", + "aes-192-cfb1", "aes-256-cfb1", + "aes-128-ofb", "aes-192-ofb", + "aes-256-ofb", "aes-128-ctr", + "aes-192-ctr", "aes-256-ctr", + "aes-128-gcm", "aes-192-gcm", + "aes-256-gcm" +]; + +export function getCiphers(): string[] { + return supportedCiphers; +} + let defaultEncoding = "buffer"; export function setDefaultEncoding(val: string) { @@ -112,7 +133,7 @@ export function setEngine(_engine: string, _flags: typeof constants) { notImplemented("crypto.setEngine"); } -export { getCiphers, kHandle, kKeyObject }; +export { kHandle, kKeyObject }; export default { getDefaultEncoding, |