@@ -114,6 +114,31 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
114114 testSignVerify ( publicKey , privateKey ) ;
115115}
116116
117+ {
118+ // Test sync key generation with key objects with a non-standard
119+ // publicExpononent
120+ const { publicKey, privateKey } = generateKeyPairSync ( 'rsa' , {
121+ publicExponent : 3 ,
122+ modulusLength : 512
123+ } ) ;
124+
125+ assert . strictEqual ( typeof publicKey , 'object' ) ;
126+ assert . strictEqual ( publicKey . type , 'public' ) ;
127+ assert . strictEqual ( publicKey . asymmetricKeyType , 'rsa' ) ;
128+ assert . deepStrictEqual ( publicKey . asymmetricKeyDetails , {
129+ modulusLength : 512 ,
130+ publicExponent : 3n
131+ } ) ;
132+
133+ assert . strictEqual ( typeof privateKey , 'object' ) ;
134+ assert . strictEqual ( privateKey . type , 'private' ) ;
135+ assert . strictEqual ( privateKey . asymmetricKeyType , 'rsa' ) ;
136+ assert . deepStrictEqual ( privateKey . asymmetricKeyDetails , {
137+ modulusLength : 512 ,
138+ publicExponent : 3n
139+ } ) ;
140+ }
141+
117142{
118143 // Test sync key generation with key objects.
119144 const { publicKey, privateKey } = generateKeyPairSync ( 'rsa' , {
@@ -123,10 +148,18 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
123148 assert . strictEqual ( typeof publicKey , 'object' ) ;
124149 assert . strictEqual ( publicKey . type , 'public' ) ;
125150 assert . strictEqual ( publicKey . asymmetricKeyType , 'rsa' ) ;
151+ assert . deepStrictEqual ( publicKey . asymmetricKeyDetails , {
152+ modulusLength : 512 ,
153+ publicExponent : 65537n
154+ } ) ;
126155
127156 assert . strictEqual ( typeof privateKey , 'object' ) ;
128157 assert . strictEqual ( privateKey . type , 'private' ) ;
129158 assert . strictEqual ( privateKey . asymmetricKeyType , 'rsa' ) ;
159+ assert . deepStrictEqual ( privateKey . asymmetricKeyDetails , {
160+ modulusLength : 512 ,
161+ publicExponent : 65537n
162+ } ) ;
130163}
131164
132165{
@@ -268,9 +301,17 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
268301 } , common . mustSucceed ( ( publicKey , privateKey ) => {
269302 assert . strictEqual ( publicKey . type , 'public' ) ;
270303 assert . strictEqual ( publicKey . asymmetricKeyType , 'rsa-pss' ) ;
304+ assert . deepStrictEqual ( publicKey . asymmetricKeyDetails , {
305+ modulusLength : 512 ,
306+ publicExponent : 65537n
307+ } ) ;
271308
272309 assert . strictEqual ( privateKey . type , 'private' ) ;
273310 assert . strictEqual ( privateKey . asymmetricKeyType , 'rsa-pss' ) ;
311+ assert . deepStrictEqual ( privateKey . asymmetricKeyDetails , {
312+ modulusLength : 512 ,
313+ publicExponent : 65537n
314+ } ) ;
274315
275316 // Unlike RSA, RSA-PSS does not allow encryption.
276317 assert . throws ( ( ) => {
@@ -342,6 +383,28 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
342383 } ) ) ;
343384}
344385
386+ {
387+ // Test async DSA key object generation.
388+ generateKeyPair ( 'dsa' , {
389+ modulusLength : 512 ,
390+ divisorLength : 256
391+ } , common . mustSucceed ( ( publicKey , privateKey ) => {
392+ assert . strictEqual ( publicKey . type , 'public' ) ;
393+ assert . strictEqual ( publicKey . asymmetricKeyType , 'dsa' ) ;
394+ assert . deepStrictEqual ( publicKey . asymmetricKeyDetails , {
395+ modulusLength : 512 ,
396+ divisorLength : 256
397+ } ) ;
398+
399+ assert . strictEqual ( privateKey . type , 'private' ) ;
400+ assert . strictEqual ( privateKey . asymmetricKeyType , 'dsa' ) ;
401+ assert . deepStrictEqual ( privateKey . asymmetricKeyDetails , {
402+ modulusLength : 512 ,
403+ divisorLength : 256
404+ } ) ;
405+ } ) ) ;
406+ }
407+
345408{
346409 // Test async elliptic curve key generation, e.g. for ECDSA, with a SEC1
347410 // private key.
@@ -925,16 +988,24 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
925988 // It should recognize both NIST and standard curve names.
926989 generateKeyPair ( 'ec' , {
927990 namedCurve : 'P-256' ,
928- publicKeyEncoding : { type : 'spki' , format : 'pem' } ,
929- privateKeyEncoding : { type : 'pkcs8' , format : 'pem' }
930991 } , common . mustSucceed ( ( publicKey , privateKey ) => {
992+ assert . deepStrictEqual ( publicKey . asymmetricKeyDetails , {
993+ namedCurve : 'prime256v1'
994+ } ) ;
995+ assert . deepStrictEqual ( privateKey . asymmetricKeyDetails , {
996+ namedCurve : 'prime256v1'
997+ } ) ;
931998 } ) ) ;
932999
9331000 generateKeyPair ( 'ec' , {
9341001 namedCurve : 'secp256k1' ,
935- publicKeyEncoding : { type : 'spki' , format : 'pem' } ,
936- privateKeyEncoding : { type : 'pkcs8' , format : 'pem' }
9371002 } , common . mustSucceed ( ( publicKey , privateKey ) => {
1003+ assert . deepStrictEqual ( publicKey . asymmetricKeyDetails , {
1004+ namedCurve : 'secp256k1'
1005+ } ) ;
1006+ assert . deepStrictEqual ( privateKey . asymmetricKeyDetails , {
1007+ namedCurve : 'secp256k1'
1008+ } ) ;
9381009 } ) ) ;
9391010}
9401011
@@ -945,9 +1016,11 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
9451016 generateKeyPair ( keyType , common . mustSucceed ( ( publicKey , privateKey ) => {
9461017 assert . strictEqual ( publicKey . type , 'public' ) ;
9471018 assert . strictEqual ( publicKey . asymmetricKeyType , keyType ) ;
1019+ assert . deepStrictEqual ( publicKey . asymmetricKeyDetails , { } ) ;
9481020
9491021 assert . strictEqual ( privateKey . type , 'private' ) ;
9501022 assert . strictEqual ( privateKey . asymmetricKeyType , keyType ) ;
1023+ assert . deepStrictEqual ( privateKey . asymmetricKeyDetails , { } ) ;
9511024 } ) ) ;
9521025 } ) ;
9531026 }
0 commit comments