mirror of
https://github.com/fluencelabs/js-libp2p-crypto
synced 2025-06-25 18:31:34 +00:00
perf: remove asn1.js and use node-forge (#166)
* perf: remove asn1.js from rsa * fix: tweaks * fix: it works, but I do not know 100% why * chore: remove asn1.js * fix: ensure jwk params encoded as uint * fix: util tests * fix: zero pad base64urlToBuffer * fix: more zero pad * test: add round trip test * test: base64url to Buffer with padding
This commit is contained in:
@ -6,26 +6,33 @@ const chai = require('chai')
|
||||
const dirtyChai = require('dirty-chai')
|
||||
const expect = chai.expect
|
||||
chai.use(dirtyChai)
|
||||
|
||||
require('node-forge/lib/jsbn')
|
||||
const forge = require('node-forge/lib/forge')
|
||||
const util = require('../src/util')
|
||||
const BN = require('bn.js')
|
||||
|
||||
describe('Util', () => {
|
||||
let bn
|
||||
|
||||
before((done) => {
|
||||
bn = new BN('dead', 16)
|
||||
done()
|
||||
before(() => {
|
||||
bn = new forge.jsbn.BigInteger('dead', 16)
|
||||
})
|
||||
|
||||
it('toBase64', (done) => {
|
||||
expect(util.toBase64(bn)).to.eql('3q0')
|
||||
done()
|
||||
it('should convert BigInteger to a uint base64url encoded string', () => {
|
||||
expect(util.bigIntegerToUintBase64url(bn)).to.eql('3q0')
|
||||
})
|
||||
|
||||
it('toBase64 zero padding', (done) => {
|
||||
const bnpad = new BN('ff', 16)
|
||||
expect(util.toBase64(bnpad, 2)).to.eql('AP8')
|
||||
done()
|
||||
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')
|
||||
})
|
||||
|
||||
it('should convert base64url encoded string to BigInteger', () => {
|
||||
const num = util.base64urlToBigInteger('3q0')
|
||||
expect(num.equals(bn)).to.be.true()
|
||||
})
|
||||
|
||||
it('should convert base64url encoded string to Buffer with padding', () => {
|
||||
const buf = util.base64urlToBuffer('AP8', 2)
|
||||
expect(Buffer.from([0, 255])).to.eql(buf)
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user