2016-12-03 19:32:07 +11:00
|
|
|
/* 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)
|
2020-02-26 16:16:32 +00:00
|
|
|
require('node-forge/lib/jsbn')
|
|
|
|
const forge = require('node-forge/lib/forge')
|
2017-07-22 10:57:27 -07:00
|
|
|
const util = require('../src/util')
|
2016-12-03 19:32:07 +11:00
|
|
|
|
|
|
|
describe('Util', () => {
|
|
|
|
let bn
|
|
|
|
|
2020-02-26 16:16:32 +00:00
|
|
|
before(() => {
|
|
|
|
bn = new forge.jsbn.BigInteger('dead', 16)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should convert BigInteger to a uint base64url encoded string', () => {
|
|
|
|
expect(util.bigIntegerToUintBase64url(bn)).to.eql('3q0')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should convert BigInteger to a uint base64url encoded string with padding', () => {
|
|
|
|
const bnpad = new forge.jsbn.BigInteger('ff', 16)
|
|
|
|
expect(util.bigIntegerToUintBase64url(bnpad, 2)).to.eql('AP8')
|
2016-12-03 19:32:07 +11:00
|
|
|
})
|
|
|
|
|
2020-02-26 16:16:32 +00:00
|
|
|
it('should convert base64url encoded string to BigInteger', () => {
|
|
|
|
const num = util.base64urlToBigInteger('3q0')
|
|
|
|
expect(num.equals(bn)).to.be.true()
|
2016-12-03 19:32:07 +11:00
|
|
|
})
|
2017-04-11 10:14:00 +01:00
|
|
|
|
2020-08-07 15:23:02 +01:00
|
|
|
it('should convert base64url encoded string to Uint8Array with padding', () => {
|
2020-02-26 16:16:32 +00:00
|
|
|
const buf = util.base64urlToBuffer('AP8', 2)
|
2020-08-07 15:23:02 +01:00
|
|
|
expect(Uint8Array.from([0, 255])).to.eql(buf)
|
2017-04-11 10:14:00 +01:00
|
|
|
})
|
2016-12-03 19:32:07 +11:00
|
|
|
})
|