expose importSync and exportSync

This commit is contained in:
AJ ONeal 2018-11-23 12:18:13 -07:00
parent 03f4700554
commit 57edc8641b
2 changed files with 85 additions and 73 deletions

View File

@ -7,8 +7,7 @@ var x509 = require('./x509.js');
var ASN1 = require('./asn1.js'); var ASN1 = require('./asn1.js');
/*global Promise*/ /*global Promise*/
RSA.parse = function parseRsa(opts) { RSA.importSync = function (opts) {
return Promise.resolve().then(function () {
if (!opts || !opts.pem || 'string' !== typeof opts.pem) { if (!opts || !opts.pem || 'string' !== typeof opts.pem) {
throw new Error("must pass { pem: pem } as a string"); throw new Error("must pass { pem: pem } as a string");
} }
@ -34,6 +33,13 @@ RSA.parse = function parseRsa(opts) {
jwk = RSA.nueter(jwk); jwk = RSA.nueter(jwk);
} }
return jwk; return jwk;
};
RSA.parse = function parseRsa(opts) {
// wrapped in a promise for API compatibility
// with the forthcoming browser version
// (and potential future native node capability)
return Promise.resolve().then(function () {
return RSA.importSync(opts);
}); });
}; };
RSA.toJwk = RSA.import = RSA.parse; RSA.toJwk = RSA.import = RSA.parse;
@ -53,8 +59,7 @@ RSAPrivateKey ::= SEQUENCE {
} }
*/ */
RSA.pack = function (opts) { RSA.exportSync = function (opts) {
return Promise.resolve().then(function () {
if (!opts || !opts.jwk || 'object' !== typeof opts.jwk) { if (!opts || !opts.jwk || 'object' !== typeof opts.jwk) {
throw new Error("must pass { jwk: jwk }"); throw new Error("must pass { jwk: jwk }");
} }
@ -104,6 +109,13 @@ RSA.pack = function (opts) {
} else { } else {
throw new Error("Sanity Error: reached unreachable code block with format: " + format); throw new Error("Sanity Error: reached unreachable code block with format: " + format);
} }
};
RSA.pack = function (opts) {
// wrapped in a promise for API compatibility
// with the forthcoming browser version
// (and potential future native node capability)
return Promise.resolve().then(function () {
return RSA.exportSync(opts);
}); });
}; };
RSA.toPem = RSA.export = RSA.pack; RSA.toPem = RSA.export = RSA.pack;

View File

@ -1,6 +1,6 @@
{ {
"name": "rasha", "name": "rasha",
"version": "1.0.1", "version": "1.0.2",
"description": "💯 PEM-to-JWK and JWK-to-PEM for RSA keys in a lightweight, zero-dependency library focused on perfect universal compatibility.", "description": "💯 PEM-to-JWK and JWK-to-PEM for RSA keys in a lightweight, zero-dependency library focused on perfect universal compatibility.",
"homepage": "https://git.coolaj86.com/coolaj86/rasha.js", "homepage": "https://git.coolaj86.com/coolaj86/rasha.js",
"main": "index.js", "main": "index.js",