diff options
author | Minteck <contact@minteck.org> | 2023-01-10 14:54:04 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2023-01-10 14:54:04 +0100 |
commit | 99c1d9af689e5325f3cf535c4007b3aeb8325229 (patch) | |
tree | e663b3c2ebdbd67c818ac0c5147f0ce1d2463cda /school/node_modules/node-forge/nodejs/test/hmac.js | |
parent | 9871b03912fc28ad38b4037ebf26a78aa937baba (diff) | |
download | pluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.tar.gz pluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.tar.bz2 pluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.zip |
Update - This is an automated commit
Diffstat (limited to 'school/node_modules/node-forge/nodejs/test/hmac.js')
-rw-r--r-- | school/node_modules/node-forge/nodejs/test/hmac.js | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/school/node_modules/node-forge/nodejs/test/hmac.js b/school/node_modules/node-forge/nodejs/test/hmac.js new file mode 100644 index 0000000..404b36b --- /dev/null +++ b/school/node_modules/node-forge/nodejs/test/hmac.js @@ -0,0 +1,85 @@ +(function() { + +function Tests(ASSERT, HMAC, UTIL) { + describe('hmac', function() { + it('should md5 hash "Hi There", 16-byte key', function() { + var key = UTIL.hexToBytes('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b'); + var hmac = HMAC.create(); + hmac.start('MD5', key); + hmac.update('Hi There'); + ASSERT.equal(hmac.digest().toHex(), '9294727a3638bb1c13f48ef8158bfc9d'); + }); + + it('should md5 hash "what do ya want for nothing?", "Jefe" key', function() { + var hmac = HMAC.create(); + hmac.start('MD5', 'Jefe'); + hmac.update('what do ya want for nothing?'); + ASSERT.equal(hmac.digest().toHex(), '750c783e6ab0b503eaa86e310a5db738'); + }); + + it('should md5 hash "Test Using Larger Than Block-Size Key - Hash Key First", 80-byte key', function() { + var key = UTIL.hexToBytes( + 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + + 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + + 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + + 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'); + var hmac = HMAC.create(); + hmac.start('MD5', key); + hmac.update('Test Using Larger Than Block-Size Key - Hash Key First'); + ASSERT.equal(hmac.digest().toHex(), '6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd'); + }); + + it('should sha1 hash "Hi There", 20-byte key', function() { + var key = UTIL.hexToBytes('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b'); + var hmac = HMAC.create(); + hmac.start('SHA1', key); + hmac.update('Hi There'); + ASSERT.equal( + hmac.digest().toHex(), 'b617318655057264e28bc0b6fb378c8ef146be00'); + }); + + it('should sha1 hash "what do ya want for nothing?", "Jefe" key', function() { + var hmac = HMAC.create(); + hmac.start('SHA1', 'Jefe'); + hmac.update('what do ya want for nothing?'); + ASSERT.equal( + hmac.digest().toHex(), 'effcdf6ae5eb2fa2d27416d5f184df9c259a7c79'); + }); + + it('should sha1 hash "Test Using Larger Than Block-Size Key - Hash Key First", 80-byte key', function() { + var key = UTIL.hexToBytes( + 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + + 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + + 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + + 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'); + var hmac = HMAC.create(); + hmac.start('SHA1', key); + hmac.update('Test Using Larger Than Block-Size Key - Hash Key First'); + ASSERT.equal( + hmac.digest().toHex(), 'aa4ae5e15272d00e95705637ce8a3b55ed402112'); + }); + }); +} + +// check for AMD +if(typeof define === 'function') { + define([ + 'forge/hmac', + 'forge/util' + ], function(HMAC, UTIL) { + Tests( + // Global provided by test harness + ASSERT, + HMAC(), + UTIL() + ); + }); +} else if(typeof module === 'object' && module.exports) { + // assume NodeJS + Tests( + require('assert'), + require('../../js/hmac')(), + require('../../js/util')()); +} + +})(); |