jwk-to-pem
Advanced tools
Comparing version 1.2.1 to 1.2.2
{ | ||
"name": "jwk-to-pem", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "Convert a JSON Web Key to a PEM", | ||
@@ -32,8 +32,8 @@ "main": "src/jwk-to-pem.js", | ||
"devDependencies": { | ||
"chai": "^3.0.0", | ||
"coveralls": "^2.11.2", | ||
"istanbul": "^0.3.15", | ||
"chai": "^3.4.0", | ||
"coveralls": "^2.11.4", | ||
"istanbul": "^0.4.0", | ||
"jwa": "^1.1.0", | ||
"mocha": "^2.2.5" | ||
"mocha": "^2.3.3" | ||
} | ||
} |
'use strict'; | ||
var asn1 = require('asn1.js'), | ||
curves = require('./ec-curves'), | ||
EC = require('elliptic').ec, | ||
rfc3280 = require('asn1.js-rfc3280'); | ||
@@ -9,2 +9,13 @@ | ||
var curves = { | ||
'P-256': 'p256', | ||
'P-384': 'p384', | ||
'P-521': 'p521' | ||
}, | ||
oids = { | ||
'P-256': [1, 2, 840, 10045, 3, 1, 7], | ||
'P-384': [1, 3, 132, 0, 34], | ||
'P-521': [1, 3, 132, 0, 35] | ||
}; | ||
function ecJwkToBuffer (jwk, opts) { | ||
@@ -32,7 +43,9 @@ if ('string' !== typeof jwk.crv) { | ||
var curve = curves[jwk.crv]; | ||
if (!curve) { | ||
var curveName = curves[jwk.crv]; | ||
if (!curveName) { | ||
throw new Error('Unsupported curve "' + jwk.crv + '"'); | ||
} | ||
var curve = new EC(curveName); | ||
var key = {}; | ||
@@ -65,21 +78,2 @@ | ||
function keyToPem (crv, key, opts) { | ||
var oid; | ||
switch (crv) { | ||
case 'P-256': { | ||
oid = [1, 2, 840, 10045, 3, 1, 7]; | ||
break; | ||
} | ||
case 'P-384': { | ||
oid = [1, 3, 132, 0, 34]; | ||
break; | ||
} | ||
case 'P-521': { | ||
oid = [1, 3, 132, 0, 35]; | ||
break; | ||
} | ||
default: { | ||
throw new Error('Unsupported curve "' + crv + '"'); | ||
} | ||
} | ||
var compact = false; | ||
@@ -95,3 +89,3 @@ var subjectPublicKey = key.getPublic(compact, 'hex'); | ||
type: 'namedCurve', | ||
value: oid | ||
value: oids[crv] | ||
}, 'der'); | ||
@@ -98,0 +92,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20256
7
229