|
|
@@ -5,6 +5,9 @@ const { |
|
|
|
generateKeyPairRSA, |
|
|
|
generateKeyPairDSA, |
|
|
|
generateKeyPairEC, |
|
|
|
generateKeyPairEdDSA, |
|
|
|
EVP_PKEY_ED25519, |
|
|
|
EVP_PKEY_ED448, |
|
|
|
OPENSSL_EC_NAMED_CURVE, |
|
|
|
OPENSSL_EC_EXPLICIT_CURVE |
|
|
|
} = internalBinding('crypto'); |
|
|
@@ -119,18 +122,25 @@ function parseKeyEncoding(keyType, options) { |
|
|
|
|
|
|
|
function check(type, options, callback) { |
|
|
|
validateString(type, 'type'); |
|
|
|
if (options == null || typeof options !== 'object') |
|
|
|
throw new ERR_INVALID_ARG_TYPE('options', 'object', options); |
|
|
|
|
|
|
|
// These will be set after parsing the type and type-specific options to make |
|
|
|
// the order a bit more intuitive. |
|
|
|
let cipher, passphrase, publicType, publicFormat, privateType, privateFormat; |
|
|
|
|
|
|
|
if (options !== undefined && typeof options !== 'object') |
|
|
|
throw new ERR_INVALID_ARG_TYPE('options', 'object', options); |
|
|
|
|
|
|
|
function needOptions() { |
|
|
|
if (options == null) |
|
|
|
throw new ERR_INVALID_ARG_TYPE('options', 'object', options); |
|
|
|
return options; |
|
|
|
} |
|
|
|
|
|
|
|
let impl; |
|
|
|
switch (type) { |
|
|
|
case 'rsa': |
|
|
|
{ |
|
|
|
const { modulusLength } = options; |
|
|
|
const { modulusLength } = needOptions(); |
|
|
|
if (!isUint32(modulusLength)) |
|
|
|
throw new ERR_INVALID_OPT_VALUE('modulusLength', modulusLength); |
|
|
|
|
|
|
@@ -149,7 +159,7 @@ function check(type, options, callback) { |
|
|
|
break; |
|
|
|
case 'dsa': |
|
|
|
{ |
|
|
|
const { modulusLength } = options; |
|
|
|
const { modulusLength } = needOptions(); |
|
|
|
if (!isUint32(modulusLength)) |
|
|
|
throw new ERR_INVALID_OPT_VALUE('modulusLength', modulusLength); |
|
|
|
|
|
|
@@ -168,7 +178,7 @@ function check(type, options, callback) { |
|
|
|
break; |
|
|
|
case 'ec': |
|
|
|
{ |
|
|
|
const { namedCurve } = options; |
|
|
|
const { namedCurve } = needOptions(); |
|
|
|
if (typeof namedCurve !== 'string') |
|
|
|
throw new ERR_INVALID_OPT_VALUE('namedCurve', namedCurve); |
|
|
|
let { paramEncoding } = options; |
|
|
@@ -185,19 +195,32 @@ function check(type, options, callback) { |
|
|
|
cipher, passphrase, wrap); |
|
|
|
} |
|
|
|
break; |
|
|
|
case 'ed25519': |
|
|
|
case 'ed448': |
|
|
|
{ |
|
|
|
const id = type === 'ed25519' ? EVP_PKEY_ED25519 : EVP_PKEY_ED448; |
|
|
|
impl = (wrap) => generateKeyPairEdDSA(id, |
|
|
|
publicFormat, publicType, |
|
|
|
privateFormat, privateType, |
|
|
|
cipher, passphrase, wrap); |
|
|
|
} |
|
|
|
break; |
|
|
|
default: |
|
|
|
throw new ERR_INVALID_ARG_VALUE('type', type, |
|
|
|
"must be one of 'rsa', 'dsa', 'ec'"); |
|
|
|
"must be one of 'rsa', 'dsa', 'ec', " + |
|
|
|
"'ed25519', 'ed448'"); |
|
|
|
} |
|
|
|
|
|
|
|
({ |
|
|
|
cipher, |
|
|
|
passphrase, |
|
|
|
publicType, |
|
|
|
publicFormat, |
|
|
|
privateType, |
|
|
|
privateFormat |
|
|
|
} = parseKeyEncoding(type, options)); |
|
|
|
if (options) { |
|
|
|
({ |
|
|
|
cipher, |
|
|
|
passphrase, |
|
|
|
publicType, |
|
|
|
publicFormat, |
|
|
|
privateType, |
|
|
|
privateFormat |
|
|
|
} = parseKeyEncoding(type, options)); |
|
|
|
} |
|
|
|
|
|
|
|
return impl; |
|
|
|
} |
|
|
|
0 comments on commit
3a95924