Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80540 views
1
2
var test = require('tape')
3
4
var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160']
5
var vectors = require('hash-test-vectors/hmac')
6
testLib('createHmac in crypto-browserify',require('../').createHmac);
7
testLib('create-hmac/browser',require('create-hmac/browser'));
8
function testLib(name, createHmac) {
9
test(name, function (t){
10
algorithms.forEach(function (alg) {
11
12
t.test('hmac('+alg+')', function (t) {
13
vectors.forEach(function (input, i) {
14
var output = createHmac(alg, new Buffer(input.key, 'hex'))
15
.update(input.data, 'hex').digest()
16
17
output = input.truncate ? output.slice(0, input.truncate) : output
18
t.equal(output.toString('hex'), input[alg])
19
})
20
t.end()
21
})
22
23
t.test('hmac('+alg+')', function (t) {
24
vectors.forEach(function (input, i) {
25
var hmac = createHmac(alg, new Buffer(input.key, 'hex'))
26
27
hmac.end(input.data, 'hex')
28
var output = hmac.read()
29
30
output = input.truncate ? output.slice(0, input.truncate) : output
31
t.equal(output.toString('hex'), input[alg])
32
})
33
t.end()
34
})
35
36
})
37
})
38
39
}
40
41