react / wstein / node_modules / browserify / node_modules / crypto-browserify / test / create-hmac.js
80538 views1var test = require('tape')23var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160']4var vectors = require('hash-test-vectors/hmac')5testLib('createHmac in crypto-browserify',require('../').createHmac);6testLib('create-hmac/browser',require('create-hmac/browser'));7function testLib(name, createHmac) {8test(name, function (t){9algorithms.forEach(function (alg) {1011t.test('hmac('+alg+')', function (t) {12vectors.forEach(function (input, i) {13var output = createHmac(alg, new Buffer(input.key, 'hex'))14.update(input.data, 'hex').digest()1516output = input.truncate ? output.slice(0, input.truncate) : output17t.equal(output.toString('hex'), input[alg])18})19t.end()20})2122t.test('hmac('+alg+')', function (t) {23vectors.forEach(function (input, i) {24var hmac = createHmac(alg, new Buffer(input.key, 'hex'))2526hmac.end(input.data, 'hex')27var output = hmac.read()2829output = input.truncate ? output.slice(0, input.truncate) : output30t.equal(output.toString('hex'), input[alg])31})32t.end()33})3435})36})3738}394041