aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js/crypto.test.js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-06-22 23:21:48 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-06-22 23:21:48 -0700
commit729d445b6885f69dd2c6355f38707bd42851c791 (patch)
treef87a7c408929ea3f57bbb7ace380cf869da83c0e /test/bun.js/crypto.test.js
parent25f820c6bf1d8ec6d444ef579cc036b8c0607b75 (diff)
downloadbun-729d445b6885f69dd2c6355f38707bd42851c791.tar.gz
bun-729d445b6885f69dd2c6355f38707bd42851c791.tar.zst
bun-729d445b6885f69dd2c6355f38707bd42851c791.zip
change the directory structurejarred/rename
Diffstat (limited to 'test/bun.js/crypto.test.js')
-rw-r--r--test/bun.js/crypto.test.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/test/bun.js/crypto.test.js b/test/bun.js/crypto.test.js
new file mode 100644
index 000000000..c489e11c1
--- /dev/null
+++ b/test/bun.js/crypto.test.js
@@ -0,0 +1,70 @@
+import {
+ sha,
+ MD5,
+ MD4,
+ SHA1,
+ SHA256,
+ SHA384,
+ SHA512,
+ SHA512_256,
+ gc,
+} from "bun";
+import { it, expect, describe } from "bun:test";
+import { readFileSync } from "fs";
+
+describe("crypto", () => {
+ for (let Hash of [MD5, MD4, SHA1, SHA256, SHA384, SHA512, SHA512_256]) {
+ for (let [input, label] of [
+ ["hello world", '"hello world"'],
+ ["hello world".repeat(20).slice(), '"hello world" x 20'],
+ ["", "empty string"],
+ ["a", '"a"'],
+ ]) {
+ describe(label, () => {
+ gc(true);
+
+ it(`${Hash.name} base64`, () => {
+ gc(true);
+ const result = new Hash();
+ result.update(input);
+ expect(typeof result.digest("base64")).toBe("string");
+ gc(true);
+ });
+
+ it(`${Hash.name} hash base64`, () => {
+ Hash.hash(input, "base64");
+ gc(true);
+ });
+
+ it(`${Hash.name} hex`, () => {
+ const result = new Hash();
+ result.update(input);
+ expect(typeof result.digest("hex")).toBe("string");
+ gc(true);
+ });
+
+ it(`${Hash.name} hash hex`, () => {
+ expect(typeof Hash.hash(input, "hex")).toBe("string");
+ gc(true);
+ });
+
+ it(`${Hash.name} buffer`, () => {
+ var buf = new Uint8Array(256);
+ const result = new Hash();
+
+ result.update(input);
+ expect(result.digest(buf)).toBe(buf);
+ expect(buf[0] != 0).toBe(true);
+ gc(true);
+ });
+
+ it(`${Hash.name} buffer`, () => {
+ var buf = new Uint8Array(256);
+
+ expect(Hash.hash(input, buf) instanceof Uint8Array).toBe(true);
+ gc(true);
+ });
+ });
+ }
+ }
+});