use ursa-optional or ursa

This commit is contained in:
AJ ONeal 2018-12-15 22:39:14 -07:00
parent ff05912dfe
commit c3ceffd2e2
1 changed files with 7 additions and 1 deletions

View File

@ -1,7 +1,13 @@
'use strict'; 'use strict';
module.exports = function (bitlen, exp) { module.exports = function (bitlen, exp) {
return require('ursa').generatePrivateKey(bitlen || 2048, exp || 65537).toPrivatePem().toString('ascii').trim(); var ursa;
try {
ursa = require('ursa');
} catch(e) {
ursa = require('ursa-optional');
}
return ursa.generatePrivateKey(bitlen || 2048, exp || 65537).toPrivatePem().toString('ascii').trim();
}; };
if (require.main === module) { if (require.main === module) {