Skip to content

Commit

Permalink
kg: synchronous APIs for getPrime()
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny committed Oct 28, 2015
1 parent 071717a commit ed36300
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/kg.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,20 @@ KeyGen.prototype.getPrime = function getPrime(bits, cb) {
continue;

e.emit('try', 'prime');
return cb(null, r);
} while (false);
if (cb)
return cb(null, r);
else
return r;
} while (!cb);

if (aborted)
return cb(new Error('aborted'));
setImmediate(next);
}
setImmediate(next);
if (cb)
setImmediate(next);
else
return next();

return e;
};
Expand Down
5 changes: 5 additions & 0 deletions test/api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ describe('Self-Signed', function() {
});
});

it('should generate prime numbers synchronously', function() {
var p = kg.getPrime(256);
assert.equal(p.bitLength(), 256);
});

it('should generate private key and cert', function(cb) {
function find() {
kg.getPrime(512, function(err, p) {
Expand Down

0 comments on commit ed36300

Please sign in to comment.