js-libp2p-crypto/test/hmac/hmac.spec.js

24 lines
668 B
JavaScript
Raw Normal View History

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