rsa key compat with go

This commit is contained in:
Friedel Ziegelmayer
2016-05-20 14:41:25 +02:00
parent fe202607eb
commit d4c1672e06
8 changed files with 90 additions and 17 deletions

View File

@ -4,6 +4,7 @@
const expect = require('chai').expect
const crypto = require('../src')
const fixtures = require('./fixtures/go-key-rsa')
describe('libp2p-crypto', () => {
let key
@ -26,4 +27,48 @@ describe('libp2p-crypto', () => {
expect(key2.equals(key)).to.be.eql(true)
})
describe('go interop', () => {
it('unmarshals private key', () => {
const key = crypto.unmarshalPrivateKey(fixtures.private.key)
const hash = fixtures.private.hash
expect(
key.hash()
).to.be.eql(
hash
)
})
it('unmarshals public key', () => {
const key = crypto.unmarshalPublicKey(fixtures.public.key)
const hash = fixtures.public.hash
expect(
key.hash()
).to.be.eql(
hash
)
})
it('unmarshal -> marshal, private key', () => {
const key = crypto.unmarshalPrivateKey(fixtures.private.key)
const marshalled = crypto.marshalPrivateKey(key)
expect(
fixtures.private.key.equals(marshalled)
).to.be.eql(
true
)
})
it('unmarshal -> marshal, public key', () => {
const key = crypto.unmarshalPublicKey(fixtures.public.key)
const marshalled = crypto.marshalPublicKey(key)
expect(
fixtures.public.key.equals(marshalled)
).to.be.eql(
true
)
})
})
})