55 generateKeyPairRSA,
66 generateKeyPairDSA,
77 generateKeyPairEC,
8+ generateKeyPairEdDSA,
9+ EVP_PKEY_ED25519 ,
10+ EVP_PKEY_ED448 ,
811 OPENSSL_EC_NAMED_CURVE ,
912 OPENSSL_EC_EXPLICIT_CURVE
1013} = internalBinding ( 'crypto' ) ;
@@ -119,18 +122,25 @@ function parseKeyEncoding(keyType, options) {
119122
120123function check ( type , options , callback ) {
121124 validateString ( type , 'type' ) ;
122- if ( options == null || typeof options !== 'object' )
123- throw new ERR_INVALID_ARG_TYPE ( 'options' , 'object' , options ) ;
124125
125126 // These will be set after parsing the type and type-specific options to make
126127 // the order a bit more intuitive.
127128 let cipher , passphrase , publicType , publicFormat , privateType , privateFormat ;
128129
130+ if ( options !== undefined && typeof options !== 'object' )
131+ throw new ERR_INVALID_ARG_TYPE ( 'options' , 'object' , options ) ;
132+
133+ function needOptions ( ) {
134+ if ( options == null )
135+ throw new ERR_INVALID_ARG_TYPE ( 'options' , 'object' , options ) ;
136+ return options ;
137+ }
138+
129139 let impl ;
130140 switch ( type ) {
131141 case 'rsa' :
132142 {
133- const { modulusLength } = options ;
143+ const { modulusLength } = needOptions ( ) ;
134144 if ( ! isUint32 ( modulusLength ) )
135145 throw new ERR_INVALID_OPT_VALUE ( 'modulusLength' , modulusLength ) ;
136146
@@ -149,7 +159,7 @@ function check(type, options, callback) {
149159 break ;
150160 case 'dsa' :
151161 {
152- const { modulusLength } = options ;
162+ const { modulusLength } = needOptions ( ) ;
153163 if ( ! isUint32 ( modulusLength ) )
154164 throw new ERR_INVALID_OPT_VALUE ( 'modulusLength' , modulusLength ) ;
155165
@@ -168,7 +178,7 @@ function check(type, options, callback) {
168178 break ;
169179 case 'ec' :
170180 {
171- const { namedCurve } = options ;
181+ const { namedCurve } = needOptions ( ) ;
172182 if ( typeof namedCurve !== 'string' )
173183 throw new ERR_INVALID_OPT_VALUE ( 'namedCurve' , namedCurve ) ;
174184 let { paramEncoding } = options ;
@@ -185,19 +195,32 @@ function check(type, options, callback) {
185195 cipher , passphrase , wrap ) ;
186196 }
187197 break ;
198+ case 'ed25519' :
199+ case 'ed448' :
200+ {
201+ const id = type === 'ed25519' ? EVP_PKEY_ED25519 : EVP_PKEY_ED448 ;
202+ impl = ( wrap ) => generateKeyPairEdDSA ( id ,
203+ publicFormat , publicType ,
204+ privateFormat , privateType ,
205+ cipher , passphrase , wrap ) ;
206+ }
207+ break ;
188208 default :
189209 throw new ERR_INVALID_ARG_VALUE ( 'type' , type ,
190- "must be one of 'rsa', 'dsa', 'ec'" ) ;
210+ "must be one of 'rsa', 'dsa', 'ec', " +
211+ "'ed25519', 'ed448'" ) ;
191212 }
192213
193- ( {
194- cipher,
195- passphrase,
196- publicType,
197- publicFormat,
198- privateType,
199- privateFormat
200- } = parseKeyEncoding ( type , options ) ) ;
214+ if ( options ) {
215+ ( {
216+ cipher,
217+ passphrase,
218+ publicType,
219+ publicFormat,
220+ privateType,
221+ privateFormat
222+ } = parseKeyEncoding ( type , options ) ) ;
223+ }
201224
202225 return impl ;
203226}
0 commit comments