@@ -114,6 +114,31 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
114
114
testSignVerify ( publicKey , privateKey ) ;
115
115
}
116
116
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
+
117
142
{
118
143
// Test sync key generation with key objects.
119
144
const { publicKey, privateKey } = generateKeyPairSync ( 'rsa' , {
@@ -123,10 +148,18 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
123
148
assert . strictEqual ( typeof publicKey , 'object' ) ;
124
149
assert . strictEqual ( publicKey . type , 'public' ) ;
125
150
assert . strictEqual ( publicKey . asymmetricKeyType , 'rsa' ) ;
151
+ assert . deepStrictEqual ( publicKey . asymmetricKeyDetails , {
152
+ modulusLength : 512 ,
153
+ publicExponent : 65537n
154
+ } ) ;
126
155
127
156
assert . strictEqual ( typeof privateKey , 'object' ) ;
128
157
assert . strictEqual ( privateKey . type , 'private' ) ;
129
158
assert . strictEqual ( privateKey . asymmetricKeyType , 'rsa' ) ;
159
+ assert . deepStrictEqual ( privateKey . asymmetricKeyDetails , {
160
+ modulusLength : 512 ,
161
+ publicExponent : 65537n
162
+ } ) ;
130
163
}
131
164
132
165
{
@@ -268,9 +301,17 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
268
301
} , common . mustSucceed ( ( publicKey , privateKey ) => {
269
302
assert . strictEqual ( publicKey . type , 'public' ) ;
270
303
assert . strictEqual ( publicKey . asymmetricKeyType , 'rsa-pss' ) ;
304
+ assert . deepStrictEqual ( publicKey . asymmetricKeyDetails , {
305
+ modulusLength : 512 ,
306
+ publicExponent : 65537n
307
+ } ) ;
271
308
272
309
assert . strictEqual ( privateKey . type , 'private' ) ;
273
310
assert . strictEqual ( privateKey . asymmetricKeyType , 'rsa-pss' ) ;
311
+ assert . deepStrictEqual ( privateKey . asymmetricKeyDetails , {
312
+ modulusLength : 512 ,
313
+ publicExponent : 65537n
314
+ } ) ;
274
315
275
316
// Unlike RSA, RSA-PSS does not allow encryption.
276
317
assert . throws ( ( ) => {
@@ -342,6 +383,28 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
342
383
} ) ) ;
343
384
}
344
385
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
+
345
408
{
346
409
// Test async elliptic curve key generation, e.g. for ECDSA, with a SEC1
347
410
// private key.
@@ -925,16 +988,24 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
925
988
// It should recognize both NIST and standard curve names.
926
989
generateKeyPair ( 'ec' , {
927
990
namedCurve : 'P-256' ,
928
- publicKeyEncoding : { type : 'spki' , format : 'pem' } ,
929
- privateKeyEncoding : { type : 'pkcs8' , format : 'pem' }
930
991
} , common . mustSucceed ( ( publicKey , privateKey ) => {
992
+ assert . deepStrictEqual ( publicKey . asymmetricKeyDetails , {
993
+ namedCurve : 'prime256v1'
994
+ } ) ;
995
+ assert . deepStrictEqual ( privateKey . asymmetricKeyDetails , {
996
+ namedCurve : 'prime256v1'
997
+ } ) ;
931
998
} ) ) ;
932
999
933
1000
generateKeyPair ( 'ec' , {
934
1001
namedCurve : 'secp256k1' ,
935
- publicKeyEncoding : { type : 'spki' , format : 'pem' } ,
936
- privateKeyEncoding : { type : 'pkcs8' , format : 'pem' }
937
1002
} , common . mustSucceed ( ( publicKey , privateKey ) => {
1003
+ assert . deepStrictEqual ( publicKey . asymmetricKeyDetails , {
1004
+ namedCurve : 'secp256k1'
1005
+ } ) ;
1006
+ assert . deepStrictEqual ( privateKey . asymmetricKeyDetails , {
1007
+ namedCurve : 'secp256k1'
1008
+ } ) ;
938
1009
} ) ) ;
939
1010
}
940
1011
@@ -945,9 +1016,11 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
945
1016
generateKeyPair ( keyType , common . mustSucceed ( ( publicKey , privateKey ) => {
946
1017
assert . strictEqual ( publicKey . type , 'public' ) ;
947
1018
assert . strictEqual ( publicKey . asymmetricKeyType , keyType ) ;
1019
+ assert . deepStrictEqual ( publicKey . asymmetricKeyDetails , { } ) ;
948
1020
949
1021
assert . strictEqual ( privateKey . type , 'private' ) ;
950
1022
assert . strictEqual ( privateKey . asymmetricKeyType , keyType ) ;
1023
+ assert . deepStrictEqual ( privateKey . asymmetricKeyDetails , { } ) ;
951
1024
} ) ) ;
952
1025
} ) ;
953
1026
}
0 commit comments