aboutsummaryrefslogtreecommitdiff
path: root/test/js/node/crypto/node-crypto.test.js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-07-09 22:36:24 -0700
committerGravatar GitHub <noreply@github.com> 2023-07-09 22:36:24 -0700
commit963d4311e614ac197427104b9cf265bbe2a890af (patch)
tree4c912420b7ec13e5c2aabbbb51157a0cac0c98ca /test/js/node/crypto/node-crypto.test.js
parent2f5e4fffe9554fcc7afa6980b3af6b33bc3a3a5e (diff)
downloadbun-963d4311e614ac197427104b9cf265bbe2a890af.tar.gz
bun-963d4311e614ac197427104b9cf265bbe2a890af.tar.zst
bun-963d4311e614ac197427104b9cf265bbe2a890af.zip
Fixes #3530 (#3587)
* Fixes #3530 * Handle OOM * Add test --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'test/js/node/crypto/node-crypto.test.js')
-rw-r--r--test/js/node/crypto/node-crypto.test.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/js/node/crypto/node-crypto.test.js b/test/js/node/crypto/node-crypto.test.js
index 5a68540cf..2489f96c7 100644
--- a/test/js/node/crypto/node-crypto.test.js
+++ b/test/js/node/crypto/node-crypto.test.js
@@ -43,6 +43,50 @@ describe("createHash", () => {
expect(Buffer.isBuffer(hash.digest())).toBeTrue();
});
+ const otherEncodings = {
+ ucs2: [
+ 11626, 2466, 37699, 38942, 64564, 53010, 48101, 47943, 44761, 18499, 12442, 26994, 46434, 62582, 39395, 20542,
+ ],
+ latin1: [
+ 106, 45, 162, 9, 67, 147, 30, 152, 52, 252, 18, 207, 229, 187, 71, 187, 217, 174, 67, 72, 154, 48, 114, 105, 98,
+ 181, 118, 244, 227, 153, 62, 80,
+ ],
+ binary: [
+ 106, 45, 162, 9, 67, 147, 30, 152, 52, 252, 18, 207, 229, 187, 71, 187, 217, 174, 67, 72, 154, 48, 114, 105, 98,
+ 181, 118, 244, 227, 153, 62, 80,
+ ],
+ base64: [
+ 97, 105, 50, 105, 67, 85, 79, 84, 72, 112, 103, 48, 47, 66, 76, 80, 53, 98, 116, 72, 117, 57, 109, 117, 81, 48,
+ 105, 97, 77, 72, 74, 112, 89, 114, 86, 50, 57, 79, 79, 90, 80, 108, 65, 61,
+ ],
+ hex: [
+ 54, 97, 50, 100, 97, 50, 48, 57, 52, 51, 57, 51, 49, 101, 57, 56, 51, 52, 102, 99, 49, 50, 99, 102, 101, 53, 98,
+ 98, 52, 55, 98, 98, 100, 57, 97, 101, 52, 51, 52, 56, 57, 97, 51, 48, 55, 50, 54, 57, 54, 50, 98, 53, 55, 54, 102,
+ 52, 101, 51, 57, 57, 51, 101, 53, 48,
+ ],
+ ascii: [
+ 106, 45, 34, 9, 67, 19, 30, 24, 52, 124, 18, 79, 101, 59, 71, 59, 89, 46, 67, 72, 26, 48, 114, 105, 98, 53, 118,
+ 116, 99, 25, 62, 80,
+ ],
+ utf8: [
+ 106, 45, 65533, 9, 67, 65533, 30, 65533, 52, 65533, 18, 65533, 65533, 71, 65533, 1646, 67, 72, 65533, 48, 114,
+ 105, 98, 65533, 118, 65533, 65533, 62, 80,
+ ],
+ };
+
+ for (let encoding in otherEncodings) {
+ it("digest " + encoding, () => {
+ const hash = crypto.createHash("sha256");
+ hash.update("some data to hash");
+ expect(
+ hash
+ .digest(encoding)
+ .split("")
+ .map(a => a.charCodeAt(0)),
+ ).toEqual(otherEncodings[encoding]);
+ });
+ }
+
it("stream (sync)", () => {
const hash = crypto.createHash("sha256");
hash.write("some data to hash");