diff --git a/lib/ec.js b/lib/ec.js index e4434dc..d464eb9 100644 --- a/lib/ec.js +++ b/lib/ec.js @@ -1,12 +1,13 @@ 'use strict'; +var x509 = module.exports; + var ASN1 = require('./asn1-packer.js'); var Enc = require('./encoding.js'); -var x509 = module.exports; // 1.2.840.10045.3.1.7 // prime256v1 (ANSI X9.62 named elliptic curve) -var OBJ_ID_EC = '06 08 2A8648CE3D030107'.replace(/\s+/g, '').toLowerCase(); +var OBJ_ID_EC_256 = '06 08 2A8648CE3D030107'.replace(/\s+/g, '').toLowerCase(); // 1.3.132.0.34 // secp384r1 (SECG (Certicom) named elliptic curve) var OBJ_ID_EC_384 = '06 05 2B81040022'.replace(/\s+/g, '').toLowerCase(); @@ -18,7 +19,7 @@ x509.packSec1 = function (jwk) { var d = Enc.base64ToHex(jwk.d); var x = Enc.base64ToHex(jwk.x); var y = Enc.base64ToHex(jwk.y); - var objId = ('P-256' === jwk.crv) ? OBJ_ID_EC : OBJ_ID_EC_384; + var objId = ('P-256' === jwk.crv) ? OBJ_ID_EC_256 : OBJ_ID_EC_384; return Enc.hexToUint8( ASN1('30' , ASN1.UInt('01') @@ -31,7 +32,7 @@ x509.packPkcs8 = function (jwk) { var d = Enc.base64ToHex(jwk.d); var x = Enc.base64ToHex(jwk.x); var y = Enc.base64ToHex(jwk.y); - var objId = ('P-256' === jwk.crv) ? OBJ_ID_EC : OBJ_ID_EC_384; + var objId = ('P-256' === jwk.crv) ? OBJ_ID_EC_256 : OBJ_ID_EC_384; return Enc.hexToUint8( ASN1('30' , ASN1.UInt('00') @@ -49,7 +50,7 @@ x509.packPkcs8 = function (jwk) { x509.packSpki = function (jwk) { var x = Enc.base64ToHex(jwk.x); var y = Enc.base64ToHex(jwk.y); - var objId = ('P-256' === jwk.crv) ? OBJ_ID_EC : OBJ_ID_EC_384; + var objId = ('P-256' === jwk.crv) ? OBJ_ID_EC_256 : OBJ_ID_EC_384; return Enc.hexToUint8( ASN1('30' , ASN1('30'