/ test / rlpx-mac.js
rlpx-mac.js
 1  const test = require('tape')
 2  const MAC = require('../src/rlpx/mac')
 3  
 4  const secret = Buffer.from('4caf4671e713d083128973de159d02688dc86f51535a80178264631e193ed2ea', 'hex')
 5  
 6  test('digest should work on empty data', (t) => {
 7    const mac = new MAC(secret)
 8    t.equal(mac.digest().toString('hex'), 'c5d2460186f7233c927e7db2dcc703c0')
 9    t.end()
10  })
11  
12  test('#update', (t) => {
13    const mac = new MAC(secret)
14    mac.update('test')
15    t.equal(mac.digest().toString('hex'), '9c22ff5f21f0b81b113e63f7db6da94f')
16    t.end()
17  })
18  
19  test('#updateHeader', (t) => {
20    const mac = new MAC(secret)
21    mac.updateHeader('this is a header data struct')
22    t.equal(mac.digest().toString('hex'), '52235ed491a4c9224d94788762ead6a6')
23    t.end()
24  })
25  
26  test('#updateBody', (t) => {
27    const mac = new MAC(secret)
28    mac.updateBody('this is a body data struct')
29    t.equal(mac.digest().toString('hex'), '134a755450b1ed9d3ff90ef5dcecdd7d')
30    t.end()
31  })
32  
33  test('#updateHeader and #updateBody', (t) => {
34    const mac = new MAC(secret)
35    mac.updateHeader('this is a header data struct')
36    mac.updateBody('this is a body data struct')
37    t.equal(mac.digest().toString('hex'), '5d98967578ec8edbb45e1d75992f394c')
38    t.end()
39  })