aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-12-29 05:53:12 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-12-29 06:05:43 -0800
commit85eda2058755261bf5ac64a3d82112d7bad5419c (patch)
tree924056e03bab81bf3d991fceaa2bee1b97b8181b /test/bun.js
parent940ecd05a8a3a1f0326256148a93306b71936c1e (diff)
downloadbun-85eda2058755261bf5ac64a3d82112d7bad5419c.tar.gz
bun-85eda2058755261bf5ac64a3d82112d7bad5419c.tar.zst
bun-85eda2058755261bf5ac64a3d82112d7bad5419c.zip
Introduce `Bun.CryptoHasher`
Diffstat (limited to 'test/bun.js')
-rw-r--r--test/bun.js/crypto.test.js47
1 files changed, 45 insertions, 2 deletions
diff --git a/test/bun.js/crypto.test.js b/test/bun.js/crypto.test.js
index 30a0f227d..8b93dab64 100644
--- a/test/bun.js/crypto.test.js
+++ b/test/bun.js/crypto.test.js
@@ -8,8 +8,8 @@ import {
SHA384,
SHA512,
SHA512_256,
- RIPEMD160,
gc,
+ CryptoHasher,
} from "bun";
import { it, expect, describe } from "bun:test";
import { readFileSync } from "fs";
@@ -23,9 +23,52 @@ const HashClasses = [
SHA384,
SHA512,
SHA512_256,
- RIPEMD160,
];
+describe("CryptoHasher", () => {
+ it("CryptoHasher.algorithms", () => {
+ expect(CryptoHasher.algorithms).toEqual([
+ "blake2b256",
+ "md4",
+ "md5",
+ "ripemd160",
+ "sha1",
+ "sha224",
+ "sha256",
+ "sha384",
+ "sha512",
+ "sha512-256",
+ ]);
+ });
+
+ it("CryptoHasher md5", () => {
+ var hasher = new CryptoHasher("md5");
+ hasher.update("hello world");
+ expect(hasher.digest("hex")).toBe("5eb63bbbe01eeed093cb22bb8f5acdc3");
+ expect(hasher.algorithm).toBe("md5");
+ });
+
+ it("CryptoHasher blake2b256", () => {
+ var hasher = new CryptoHasher("blake2b256");
+ hasher.update("hello world");
+ expect(hasher.algorithm).toBe("blake2b256");
+
+ expect(hasher.digest("hex")).toBe(
+ // b2sum --length=256
+ "256c83b297114d201b30179f3f0ef0cace9783622da5974326b436178aeef610",
+ );
+ });
+
+ it("CryptoHasher sha512", () => {
+ var hasher = new CryptoHasher("sha512");
+ hasher.update("hello world");
+ expect(hasher.digest("hex")).toBe(
+ "309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f",
+ );
+ expect(hasher.algorithm).toBe("sha512");
+ });
+});
+
describe("crypto", () => {
for (let Hash of HashClasses) {
for (let [input, label] of [