From 99c1d9af689e5325f3cf535c4007b3aeb8325229 Mon Sep 17 00:00:00 2001 From: Minteck Date: Tue, 10 Jan 2023 14:54:04 +0100 Subject: Update - This is an automated commit --- school/node_modules/node-forge/nodejs/test/hmac.js | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 school/node_modules/node-forge/nodejs/test/hmac.js (limited to 'school/node_modules/node-forge/nodejs/test/hmac.js') 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')()); +} + +})(); -- cgit