@@ -6,9 +6,6 @@ if (!common.hasCrypto)
6
6
7
7
const { hasOpenSSL } = require ( '../common/crypto' ) ;
8
8
9
- if ( ! hasOpenSSL ( 3 , 5 ) )
10
- common . skip ( 'requires OpenSSL 3.5' ) ;
11
-
12
9
const assert = require ( 'assert' ) ;
13
10
const {
14
11
createPublicKey,
@@ -83,20 +80,32 @@ for (const [asymmetricKeyType, pubLen] of [
83
80
}
84
81
}
85
82
86
- const publicKey = createPublicKey ( keys . public ) ;
87
- assertPublicKey ( publicKey ) ;
88
-
89
- {
90
- for ( const [ pem , hasSeed ] of [
91
- [ keys . private , true ] ,
92
- [ keys . private_seed_only , true ] ,
93
- [ keys . private_priv_only , false ] ,
94
- ] ) {
95
- const pubFromPriv = createPublicKey ( pem ) ;
96
- assertPublicKey ( pubFromPriv ) ;
97
- assertPrivateKey ( createPrivateKey ( pem ) , hasSeed ) ;
98
- assert . strictEqual ( pubFromPriv . equals ( publicKey ) , true ) ;
99
- assert . deepStrictEqual ( pubFromPriv , publicKey ) ;
83
+ if ( ! hasOpenSSL ( 3 , 5 ) ) {
84
+ assert . throws ( ( ) => createPublicKey ( keys . public ) , {
85
+ code : hasOpenSSL ( 3 ) ? 'ERR_OSSL_EVP_DECODE_ERROR' : 'ERR_OSSL_EVP_UNSUPPORTED_ALGORITHM' ,
86
+ } ) ;
87
+
88
+ for ( const pem of [ keys . private , keys . private_seed_only , keys . private_priv_only ] ) {
89
+ assert . throws ( ( ) => createPrivateKey ( pem ) , {
90
+ code : hasOpenSSL ( 3 ) ? 'ERR_OSSL_UNSUPPORTED' : 'ERR_OSSL_EVP_UNSUPPORTED_ALGORITHM' ,
91
+ } ) ;
92
+ }
93
+ } else {
94
+ const publicKey = createPublicKey ( keys . public ) ;
95
+ assertPublicKey ( publicKey ) ;
96
+
97
+ {
98
+ for ( const [ pem , hasSeed ] of [
99
+ [ keys . private , true ] ,
100
+ [ keys . private_seed_only , true ] ,
101
+ [ keys . private_priv_only , false ] ,
102
+ ] ) {
103
+ const pubFromPriv = createPublicKey ( pem ) ;
104
+ assertPublicKey ( pubFromPriv ) ;
105
+ assertPrivateKey ( createPrivateKey ( pem ) , hasSeed ) ;
106
+ assert . strictEqual ( pubFromPriv . equals ( publicKey ) , true ) ;
107
+ assert . deepStrictEqual ( pubFromPriv , publicKey ) ;
108
+ }
100
109
}
101
110
}
102
111
}
@@ -140,20 +149,32 @@ for (const asymmetricKeyType of ['ml-kem-512', 'ml-kem-768', 'ml-kem-1024']) {
140
149
{ code : 'ERR_CRYPTO_JWK_UNSUPPORTED_KEY_TYPE' , message : 'Unsupported JWK Key Type.' } ) ;
141
150
}
142
151
143
- const publicKey = createPublicKey ( keys . public ) ;
144
- assertPublicKey ( publicKey ) ;
145
-
146
- {
147
- for ( const [ pem , hasSeed ] of [
148
- [ keys . private , true ] ,
149
- [ keys . private_seed_only , true ] ,
150
- [ keys . private_priv_only , false ] ,
151
- ] ) {
152
- const pubFromPriv = createPublicKey ( pem ) ;
153
- assertPublicKey ( pubFromPriv ) ;
154
- assertPrivateKey ( createPrivateKey ( pem ) , hasSeed ) ;
155
- assert . strictEqual ( pubFromPriv . equals ( publicKey ) , true ) ;
156
- assert . deepStrictEqual ( pubFromPriv , publicKey ) ;
152
+ if ( ! hasOpenSSL ( 3 , 5 ) ) {
153
+ assert . throws ( ( ) => createPublicKey ( keys . public ) , {
154
+ code : hasOpenSSL ( 3 ) ? 'ERR_OSSL_EVP_DECODE_ERROR' : 'ERR_OSSL_EVP_UNSUPPORTED_ALGORITHM' ,
155
+ } ) ;
156
+
157
+ for ( const pem of [ keys . private , keys . private_seed_only , keys . private_priv_only ] ) {
158
+ assert . throws ( ( ) => createPrivateKey ( pem ) , {
159
+ code : hasOpenSSL ( 3 ) ? 'ERR_OSSL_UNSUPPORTED' : 'ERR_OSSL_EVP_UNSUPPORTED_ALGORITHM' ,
160
+ } ) ;
161
+ }
162
+ } else {
163
+ const publicKey = createPublicKey ( keys . public ) ;
164
+ assertPublicKey ( publicKey ) ;
165
+
166
+ {
167
+ for ( const [ pem , hasSeed ] of [
168
+ [ keys . private , true ] ,
169
+ [ keys . private_seed_only , true ] ,
170
+ [ keys . private_priv_only , false ] ,
171
+ ] ) {
172
+ const pubFromPriv = createPublicKey ( pem ) ;
173
+ assertPublicKey ( pubFromPriv ) ;
174
+ assertPrivateKey ( createPrivateKey ( pem ) , hasSeed ) ;
175
+ assert . strictEqual ( pubFromPriv . equals ( publicKey ) , true ) ;
176
+ assert . deepStrictEqual ( pubFromPriv , publicKey ) ;
177
+ }
157
178
}
158
179
}
159
180
}
0 commit comments