diff options
author | Minteck <contact@minteck.org> | 2022-10-18 08:59:09 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-10-18 08:59:09 +0200 |
commit | 2c4ae43e688a9873e86211ea0e7aeb9ba770dd77 (patch) | |
tree | 17848d95522dab25d3cdeb9c4a6450e2a234861f /alarm/node_modules/node-forge/nodejs/test/sha256.js | |
parent | 108525534c28013cfe1897c30e4565f9893f3766 (diff) | |
download | pluralconnect-2c4ae43e688a9873e86211ea0e7aeb9ba770dd77.tar.gz pluralconnect-2c4ae43e688a9873e86211ea0e7aeb9ba770dd77.tar.bz2 pluralconnect-2c4ae43e688a9873e86211ea0e7aeb9ba770dd77.zip |
Update
Diffstat (limited to 'alarm/node_modules/node-forge/nodejs/test/sha256.js')
-rw-r--r-- | alarm/node_modules/node-forge/nodejs/test/sha256.js | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/alarm/node_modules/node-forge/nodejs/test/sha256.js b/alarm/node_modules/node-forge/nodejs/test/sha256.js new file mode 100644 index 0000000..2d5eb8a --- /dev/null +++ b/alarm/node_modules/node-forge/nodejs/test/sha256.js @@ -0,0 +1,81 @@ +(function() { + +function Tests(ASSERT, SHA256, UTIL) { + describe('sha256', function() { + it('should digest the empty string', function() { + var md = SHA256.create(); + ASSERT.equal( + md.digest().toHex(), + 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'); + }); + + it('should digest "abc"', function() { + var md = SHA256.create(); + md.update('abc'); + ASSERT.equal( + md.digest().toHex(), + 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'); + }); + + it('should digest "The quick brown fox jumps over the lazy dog"', function() { + var md = SHA256.create(); + md.update('The quick brown fox jumps over the lazy dog'); + ASSERT.equal( + md.digest().toHex(), + 'd7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592'); + }); + + it('should digest "c\'\u00e8"', function() { + var md = SHA256.create(); + md.update("c\'\u00e8", 'utf8'); + ASSERT.equal( + md.digest().toHex(), + '1aa15c717afffd312acce2217ce1c2e5dabca53c92165999132ec9ca5decdaca'); + }); + + it('should digest "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"', function() { + var md = SHA256.create(); + md.start(); + md.update('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'); + // do twice to check continuing digest + ASSERT.equal( + md.digest().toHex(), + '248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1'); + ASSERT.equal( + md.digest().toHex(), + '248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1'); + }); + + it('should digest a long message', function() { + // Note: might be too slow on old browsers + var md = SHA256.create(); + md.update(UTIL.fillString('a', 1000000)); + ASSERT.equal( + md.digest().toHex(), + 'cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0'); + }); + }); +} + +// check for AMD +if(typeof define === 'function') { + define([ + 'forge/sha256', + 'forge/util' + ], function(SHA256, UTIL) { + Tests( + // Global provided by test harness + ASSERT, + SHA256(), + UTIL() + ); + }); +} else if(typeof module === 'object' && module.exports) { + // assume NodeJS + Tests( + require('assert'), + require('../../js/sha256')(), + require('../../js/util')()); +} + +})(); |