43 lines
876 B
JavaScript
43 lines
876 B
JavaScript
'use strict';
|
|
|
|
var Eckles = require('eckles');
|
|
var Rasha = require('rasha');
|
|
var Keypairs = {};
|
|
|
|
/*global Promise*/
|
|
|
|
Keypairs.generate = function (opts) {
|
|
opts = opts || {};
|
|
var kty = opts.kty || opts.type;
|
|
if ('RSA' === kty) {
|
|
return Rasha.generate(opts);
|
|
}
|
|
return Eckles.generate(opts);
|
|
};
|
|
|
|
Keypairs.import = function (opts) {
|
|
return Eckles.import(opts.pem).catch(function () {
|
|
return Rasha.import(opts.pem);
|
|
});
|
|
};
|
|
|
|
Keypairs.export = function (opts) {
|
|
return Promise.resolve().then(function () {
|
|
if ('RSA' === opts.jwk.kty) {
|
|
return Rasha.export(opts);
|
|
} else {
|
|
return Eckles.export(opts);
|
|
}
|
|
});
|
|
};
|
|
|
|
Keypairs.thumbprint = function (opts) {
|
|
return Promise.resolve().then(function () {
|
|
if ('RSA' === opts.jwk.kty) {
|
|
return Rasha.thumbprint(opts);
|
|
} else {
|
|
return Eckles.thumbprint(opts);
|
|
}
|
|
});
|
|
};
|