From de98e0b232509d5f40c135d540a70e415272ff85 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 3 May 2017 15:35:00 +0200 Subject: node_modules --- node_modules/create-hmac/test.js | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 node_modules/create-hmac/test.js (limited to 'node_modules/create-hmac/test.js') diff --git a/node_modules/create-hmac/test.js b/node_modules/create-hmac/test.js new file mode 100644 index 000000000..cb0cd5765 --- /dev/null +++ b/node_modules/create-hmac/test.js @@ -0,0 +1,41 @@ +var test = require('tape') + +var algorithms = ['sha1', 'sha224','sha256', 'sha384', 'sha512', 'SHA512', 'md5', 'rmd160'] +var formats = [undefined, 'base64', 'hex', 'binary'] + +var vectors = require('hash-test-vectors/hmac') +var createHmac = require('./browser') +algorithms.forEach(function (alg) { + vectors.forEach(function (input) { + var key = new Buffer(input.key, 'hex') + var inputBuffer = new Buffer(input.data, 'hex') + + formats.forEach(function (format) { + test('hmac(' + alg + ') w/ ' + input.data.slice(0, 6) + '... as ' + format, function (t) { + var hmac = createHmac(alg, key) + + var formattedInput = format ? inputBuffer.toString(format) : inputBuffer + hmac.update(formattedInput, format) + + var formattedOutput = hmac.digest(format) + var output = new Buffer(formattedOutput, format) + + var truncated = input.truncate ? output.slice(0, input.truncate) : output + t.equal(truncated.toString('hex'), input[alg.toLowerCase()]) + t.end() + }) + }) + }) + + vectors.forEach(function (input) { + test('hmac(' + alg + ') as stream w/ ' + input.data.slice(0, 6) + '...', function (t) { + var hmac = createHmac(alg, new Buffer(input.key, 'hex')) + hmac.end(input.data, 'hex') + + var output = hmac.read() + var truncated = input.truncate ? output.slice(0, input.truncate) : output + t.equal(truncated.toString('hex'), input[alg.toLowerCase()]) + t.end() + }) + }) +}) -- cgit v1.2.3