refactor: make rsa key generation sync

This commit is contained in:
dignifiedquire
2016-05-23 19:13:31 +02:00
parent fba4d3cc0f
commit 1270f3e37e
7 changed files with 37 additions and 1570 deletions

View File

@ -55,7 +55,11 @@ class RsaPublicKey {
class RsaPrivateKey {
constructor (privKey, pubKey) {
this._privateKey = privKey
this._publicKey = pubKey
if (pubKey) {
this._publicKey = pubKey
} else {
this._publicKey = forge.pki.setRsaPublicKey(privKey.n, privKey.e)
}
}
genSecret () {
@ -123,15 +127,9 @@ function unmarshalRsaPublicKey (bytes) {
return new RsaPublicKey(key)
}
function generateKeyPair (bits, cb) {
rsa.generateKeyPair({
bits,
workerScript: utils.workerScript
}, (err, p) => {
if (err) return cb(err)
cb(null, new RsaPrivateKey(p.privateKey, p.publicKey))
})
function generateKeyPair (bits) {
const p = rsa.generateKeyPair({bits})
return new RsaPrivateKey(p.privateKey, p.publicKey)
}
module.exports = {