diff options
author | Felipe Baltor <fbaltor@gmail.com> | 2023-06-26 23:04:49 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-27 11:04:49 +0900 |
commit | 814edcdd570b3fbef2001f7e6434320743a8f834 (patch) | |
tree | db47be5770509341c0a25e1a402b0cf06b1aa58c /ext/node | |
parent | a8d472f88e79703b1890bfdc87d7a3bb20b21428 (diff) |
test(ext/node): port crypto_test.ts from deno_std (#19561)
Diffstat (limited to 'ext/node')
-rw-r--r-- | ext/node/lib.rs | 1 | ||||
-rw-r--r-- | ext/node/ops/crypto/digest.rs | 13 | ||||
-rw-r--r-- | ext/node/ops/crypto/mod.rs | 5 | ||||
-rw-r--r-- | ext/node/polyfills/crypto.ts | 8 | ||||
-rw-r--r-- | ext/node/polyfills/internal/crypto/hash.ts | 8 | ||||
-rw-r--r-- | ext/node/polyfills/internal/crypto/util.ts | 37 |
6 files changed, 33 insertions, 39 deletions
diff --git a/ext/node/lib.rs b/ext/node/lib.rs index 99c138b8f..bb8d744c8 100644 --- a/ext/node/lib.rs +++ b/ext/node/lib.rs @@ -139,6 +139,7 @@ deno_core::extension!(deno_node, ops::crypto::op_node_cipheriv_final, ops::crypto::op_node_create_cipheriv, ops::crypto::op_node_create_hash, + ops::crypto::op_node_get_hashes, ops::crypto::op_node_decipheriv_decrypt, ops::crypto::op_node_decipheriv_final, ops::crypto::op_node_hash_update, diff --git a/ext/node/ops/crypto/digest.rs b/ext/node/ops/crypto/digest.rs index 4fab58a43..685fc32d0 100644 --- a/ext/node/ops/crypto/digest.rs +++ b/ext/node/ops/crypto/digest.rs @@ -99,6 +99,19 @@ impl Hash { Sha512(context) => context.finalize(), } } + + pub fn get_hashes() -> Vec<&'static str> { + vec![ + "md4", + "md5", + "ripemd160", + "sha1", + "sha224", + "sha256", + "sha384", + "sha512", + ] + } } impl Clone for Hash { diff --git a/ext/node/ops/crypto/mod.rs b/ext/node/ops/crypto/mod.rs index a83263fff..1155a4d15 100644 --- a/ext/node/ops/crypto/mod.rs +++ b/ext/node/ops/crypto/mod.rs @@ -89,6 +89,11 @@ pub fn op_node_create_hash(state: &mut OpState, algorithm: &str) -> u32 { } #[op(fast)] +pub fn op_node_get_hashes() -> Vec<&'static str> { + digest::Hash::get_hashes() +} + +#[op(fast)] pub fn op_node_hash_update(state: &mut OpState, rid: u32, data: &[u8]) -> bool { let context = match state.resource_table.get::<digest::Context>(rid) { Ok(context) => context, diff --git a/ext/node/polyfills/crypto.ts b/ext/node/polyfills/crypto.ts index bc18410c7..1c166240c 100644 --- a/ext/node/polyfills/crypto.ts +++ b/ext/node/polyfills/crypto.ts @@ -134,7 +134,12 @@ import type { VerifyKeyObjectInput, VerifyPublicKeyInput, } from "ext:deno_node/internal/crypto/sig.ts"; -import { createHash, Hash, Hmac } from "ext:deno_node/internal/crypto/hash.ts"; +import { + createHash, + getHashes, + Hash, + Hmac, +} from "ext:deno_node/internal/crypto/hash.ts"; import { X509Certificate } from "ext:deno_node/internal/crypto/x509.ts"; import type { PeerCertificate, @@ -143,7 +148,6 @@ import type { import { getCiphers, getCurves, - getHashes, secureHeapUsed, setEngine, } from "ext:deno_node/internal/crypto/util.ts"; diff --git a/ext/node/polyfills/internal/crypto/hash.ts b/ext/node/polyfills/internal/crypto/hash.ts index 34e3c1230..51c9ec955 100644 --- a/ext/node/polyfills/internal/crypto/hash.ts +++ b/ext/node/polyfills/internal/crypto/hash.ts @@ -229,6 +229,14 @@ export function createHash(algorithm: string, opts?: TransformOptions) { return new Hash(algorithm, opts); } +/** + * Get the list of implemented hash algorithms. + * @returns Array of hash algorithm names. + */ +export function getHashes() { + return ops.op_node_get_hashes(); +} + export default { Hash, Hmac, diff --git a/ext/node/polyfills/internal/crypto/util.ts b/ext/node/polyfills/internal/crypto/util.ts index 2e269b7fa..18495c349 100644 --- a/ext/node/polyfills/internal/crypto/util.ts +++ b/ext/node/polyfills/internal/crypto/util.ts @@ -17,35 +17,6 @@ import { kKeyObject, } from "ext:deno_node/internal/crypto/constants.ts"; -// TODO(kt3k): Generate this list from `digestAlgorithms` -// of std/crypto/_wasm/mod.ts -const digestAlgorithms = [ - "blake2b256", - "blake2b384", - "blake2b", - "blake2s", - "blake3", - "keccak-224", - "keccak-256", - "keccak-384", - "keccak-512", - "sha384", - "sha3-224", - "sha3-256", - "sha3-384", - "sha3-512", - "shake128", - "shake256", - "tiger", - "rmd160", - "sha224", - "sha256", - "sha512", - "md4", - "md5", - "sha1", -]; - export type EllipticCurve = { name: string; ephemeral: boolean; @@ -148,13 +119,6 @@ export const validateByteSource = hideStackFrames((val, name) => { ); }); -/** - * Returns an array of the names of the supported hash algorithms, such as 'sha1'. - */ -export function getHashes(): readonly string[] { - return digestAlgorithms; -} - const curveNames = ellipticCurves.map((x) => x.name); export function getCurves(): readonly string[] { return curveNames; @@ -181,7 +145,6 @@ export { kAesKeyLengths, kHandle, kKeyObject }; export default { getDefaultEncoding, - getHashes, setDefaultEncoding, getCiphers, getCurves, |