2016-09-13 13:23:11 +02:00
|
|
|
/* eslint max-nested-callbacks: ["error", 8] */
|
|
|
|
/* eslint-env mocha */
|
|
|
|
'use strict'
|
2020-08-07 15:23:02 +01:00
|
|
|
|
2017-03-21 15:05:22 +00:00
|
|
|
const chai = require('chai')
|
|
|
|
const dirtyChai = require('dirty-chai')
|
|
|
|
const expect = chai.expect
|
|
|
|
chai.use(dirtyChai)
|
2020-08-07 15:23:02 +01:00
|
|
|
const uint8ArrayFromString = require('uint8arrays/from-string')
|
2017-01-16 05:17:50 +01:00
|
|
|
|
2017-07-22 10:57:27 -07:00
|
|
|
const crypto = require('../../src')
|
2016-09-13 13:23:11 +02:00
|
|
|
|
|
|
|
const hashes = ['SHA1', 'SHA256', 'SHA512']
|
|
|
|
|
|
|
|
describe('HMAC', () => {
|
|
|
|
hashes.forEach((hash) => {
|
2019-07-10 17:15:26 +01:00
|
|
|
it(`${hash} - sign and verify`, async () => {
|
2020-08-07 15:23:02 +01:00
|
|
|
const hmac = await crypto.hmac.create(hash, uint8ArrayFromString('secret'))
|
|
|
|
const sig = await hmac.digest(uint8ArrayFromString('hello world'))
|
2019-07-10 17:15:26 +01:00
|
|
|
expect(sig).to.have.length(hmac.length)
|
2016-09-13 13:23:11 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|