diff options
Diffstat (limited to 'test/js/node/crypto/crypto.test.ts')
| -rw-r--r-- | test/js/node/crypto/crypto.test.ts | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/test/js/node/crypto/crypto.test.ts b/test/js/node/crypto/crypto.test.ts index b5b8e9286..3efd4c317 100644 --- a/test/js/node/crypto/crypto.test.ts +++ b/test/js/node/crypto/crypto.test.ts @@ -46,6 +46,69 @@ describe("CryptoHasher", () => { ); expect(hasher.algorithm).toBe("sha512"); }); + + it("CryptoHasher sha256", () => { + var hasher = new CryptoHasher("sha256"); + hasher.update("hello world"); + expect(hasher.digest("hex")).toBe( + "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", + ); + expect(hasher.algorithm).toBe("sha256"); + }); + + it("CryptoHasher sha256 multi-part", () => { + var hasher = new CryptoHasher("sha256"); + hasher.update("hello "); + hasher.update("world"); + expect(hasher.digest("hex")).toBe( + "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", + ); + expect(hasher.algorithm).toBe("sha256"); + }); + + it("CryptoHasher resets when digest is called", () => { + var hasher = new CryptoHasher("sha256"); + hasher.update("hello"); + expect(hasher.digest("hex")).toBe( + "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824", + ); + hasher.update("world"); + expect(hasher.digest("hex")).toBe( + "486ea46224d1bb4fb680f34f7c9ad96a8f24ec88be73ea8e5a6c65260e9cb8a7", + ); + }); + + for (let alg of CryptoHasher.algorithms) { + it(`CryptoHasher ${alg} copy is the same`, () => { + const orig = new CryptoHasher(alg); + orig.update("hello"); + const copy = orig.copy(); + + expect(copy.digest("hex")).toBe(orig.digest("hex")); + expect(copy.algorithm).toBe(orig.algorithm); + }); + + + it(`CryptoHasher ${alg} copy is not linked`, () => { + const orig = new CryptoHasher(alg); + orig.update("hello"); + const copy = orig.copy(); + + orig.update("world"); + expect(copy.digest("hex")).not.toBe(orig.digest("hex")); + }); + + + it(`CryptoHasher ${alg} copy updates the same`, () => { + const orig = new CryptoHasher(alg); + orig.update("hello"); + const copy = orig.copy(); + + orig.update("world"); + copy.update("world"); + expect(copy.digest("hex")).toBe(orig.digest("hex")); + }); + } }); describe("crypto", () => { |
