@@ -3,6 +3,7 @@ const { createPrivateKey, createPublicKey } = require('crypto')
33const { hasProperty, hasNoProperties, hasProperties } = require ( '../macros' )
44const fixtures = require ( '../fixtures' )
55
6+ const { oaepHash } = require ( '../../lib/help/node_support' )
67const { generateSync } = require ( '../../lib/jwk/generate' )
78const RSAKey = require ( '../../lib/jwk/key/rsa' )
89
@@ -31,11 +32,19 @@ test(`RSA key .algorithms invalid operation`, t => {
3132 test ( `RSA Private key` , hasProperty , key , 'type' , 'private' )
3233 test ( `RSA Private key` , hasProperty , key , 'use' , undefined )
3334
34- test ( 'RSA Private key algorithms (no operation)' , t => {
35- const result = key . algorithms ( )
36- t . is ( result . constructor , Set )
37- t . deepEqual ( [ ...result ] , [ 'PS256' , 'RS256' , 'PS384' , 'RS384' , 'PS512' , 'RS512' , 'RSA-OAEP' , 'RSA1_5' ] )
38- } )
35+ if ( oaepHash ) {
36+ test ( 'RSA Private key algorithms (no operation)' , t => {
37+ const result = key . algorithms ( )
38+ t . is ( result . constructor , Set )
39+ t . deepEqual ( [ ...result ] , [ 'PS256' , 'RS256' , 'PS384' , 'RS384' , 'PS512' , 'RS512' , 'RSA-OAEP' , 'RSA-OAEP-256' , 'RSA1_5' ] )
40+ } )
41+ } else {
42+ test ( 'RSA Private key algorithms (no operation)' , t => {
43+ const result = key . algorithms ( )
44+ t . is ( result . constructor , Set )
45+ t . deepEqual ( [ ...result ] , [ 'PS256' , 'RS256' , 'PS384' , 'RS384' , 'PS512' , 'RS512' , 'RSA-OAEP' , 'RSA1_5' ] )
46+ } )
47+ }
3948
4049 test ( 'RSA Private key algorithms (no operation, w/ alg)' , t => {
4150 const key = new RSAKey ( keyObject , { alg : 'RS256' } )
@@ -116,11 +125,19 @@ test(`RSA key .algorithms invalid operation`, t => {
116125 t . deepEqual ( [ ...result ] , [ ] )
117126 } )
118127
119- test ( 'RSA Private key .algorithms("wrapKey")' , t => {
120- const result = key . algorithms ( 'wrapKey' )
121- t . is ( result . constructor , Set )
122- t . deepEqual ( [ ...result ] , [ 'RSA-OAEP' , 'RSA1_5' ] )
123- } )
128+ if ( oaepHash ) {
129+ test ( 'RSA Private key .algorithms("wrapKey")' , t => {
130+ const result = key . algorithms ( 'wrapKey' )
131+ t . is ( result . constructor , Set )
132+ t . deepEqual ( [ ...result ] , [ 'RSA-OAEP' , 'RSA-OAEP-256' , 'RSA1_5' ] )
133+ } )
134+ } else {
135+ test ( 'RSA Private key .algorithms("wrapKey")' , t => {
136+ const result = key . algorithms ( 'wrapKey' )
137+ t . is ( result . constructor , Set )
138+ t . deepEqual ( [ ...result ] , [ 'RSA-OAEP' , 'RSA1_5' ] )
139+ } )
140+ }
124141
125142 test ( 'RSA Private key .algorithms("wrapKey") when use is sig' , t => {
126143 const sigKey = new RSAKey ( keyObject , { use : 'sig' } )
@@ -129,11 +146,19 @@ test(`RSA key .algorithms invalid operation`, t => {
129146 t . deepEqual ( [ ...result ] , [ ] )
130147 } )
131148
132- test ( 'RSA Private key .algorithms("unwrapKey")' , t => {
133- const result = key . algorithms ( 'unwrapKey' )
134- t . is ( result . constructor , Set )
135- t . deepEqual ( [ ...result ] , [ 'RSA-OAEP' , 'RSA1_5' ] )
136- } )
149+ if ( oaepHash ) {
150+ test ( 'RSA Private key .algorithms("unwrapKey")' , t => {
151+ const result = key . algorithms ( 'unwrapKey' )
152+ t . is ( result . constructor , Set )
153+ t . deepEqual ( [ ...result ] , [ 'RSA-OAEP' , 'RSA-OAEP-256' , 'RSA1_5' ] )
154+ } )
155+ } else {
156+ test ( 'RSA Private key .algorithms("unwrapKey")' , t => {
157+ const result = key . algorithms ( 'unwrapKey' )
158+ t . is ( result . constructor , Set )
159+ t . deepEqual ( [ ...result ] , [ 'RSA-OAEP' , 'RSA1_5' ] )
160+ } )
161+ }
137162
138163 test ( 'RSA Private key .algorithms("unwrapKey") when use is sig' , t => {
139164 const sigKey = new RSAKey ( keyObject , { use : 'sig' } )
@@ -163,11 +188,19 @@ test(`RSA key .algorithms invalid operation`, t => {
163188 test ( `RSA Public key` , hasProperty , key , 'type' , 'public' )
164189 test ( `RSA Public key` , hasProperty , key , 'use' , undefined )
165190
166- test ( 'RSA EC Public key algorithms (no operation)' , t => {
167- const result = key . algorithms ( )
168- t . is ( result . constructor , Set )
169- t . deepEqual ( [ ...result ] , [ 'PS256' , 'RS256' , 'PS384' , 'RS384' , 'PS512' , 'RS512' , 'RSA-OAEP' , 'RSA1_5' ] )
170- } )
191+ if ( oaepHash ) {
192+ test ( 'RSA EC Public key algorithms (no operation)' , t => {
193+ const result = key . algorithms ( )
194+ t . is ( result . constructor , Set )
195+ t . deepEqual ( [ ...result ] , [ 'PS256' , 'RS256' , 'PS384' , 'RS384' , 'PS512' , 'RS512' , 'RSA-OAEP' , 'RSA-OAEP-256' , 'RSA1_5' ] )
196+ } )
197+ } else {
198+ test ( 'RSA EC Public key algorithms (no operation)' , t => {
199+ const result = key . algorithms ( )
200+ t . is ( result . constructor , Set )
201+ t . deepEqual ( [ ...result ] , [ 'PS256' , 'RS256' , 'PS384' , 'RS384' , 'PS512' , 'RS512' , 'RSA-OAEP' , 'RSA1_5' ] )
202+ } )
203+ }
171204
172205 test ( 'RSA EC Public key algorithms (no operation, w/ alg)' , t => {
173206 const key = new RSAKey ( keyObject , { alg : 'RS256' } )
@@ -248,11 +281,19 @@ test(`RSA key .algorithms invalid operation`, t => {
248281 t . deepEqual ( [ ...result ] , [ ] )
249282 } )
250283
251- test ( 'RSA Public key .algorithms("wrapKey")' , t => {
252- const result = key . algorithms ( 'wrapKey' )
253- t . is ( result . constructor , Set )
254- t . deepEqual ( [ ...result ] , [ 'RSA-OAEP' , 'RSA1_5' ] )
255- } )
284+ if ( oaepHash ) {
285+ test ( 'RSA Public key .algorithms("wrapKey")' , t => {
286+ const result = key . algorithms ( 'wrapKey' )
287+ t . is ( result . constructor , Set )
288+ t . deepEqual ( [ ...result ] , [ 'RSA-OAEP' , 'RSA-OAEP-256' , 'RSA1_5' ] )
289+ } )
290+ } else {
291+ test ( 'RSA Public key .algorithms("wrapKey")' , t => {
292+ const result = key . algorithms ( 'wrapKey' )
293+ t . is ( result . constructor , Set )
294+ t . deepEqual ( [ ...result ] , [ 'RSA-OAEP' , 'RSA1_5' ] )
295+ } )
296+ }
256297
257298 test ( 'RSA Public key .algorithms("wrapKey") when use is sig' , t => {
258299 const sigKey = new RSAKey ( keyObject , { use : 'sig' } )
@@ -295,6 +336,13 @@ test(`RSA key .algorithms invalid operation`, t => {
295336 t . true ( k . algorithms ( ) . has ( 'RS512' ) )
296337 } )
297338
339+ if ( oaepHash ) {
340+ test ( 'RSA key >= 784 bits can do RSA-OAEP-256' , t => {
341+ const k = generateSync ( 'RSA' , 784 )
342+ t . true ( k . algorithms ( ) . has ( 'RSA-OAEP-256' ) )
343+ } )
344+ }
345+
298346 test ( 'RSA key >= 784 bits can do PS384' , t => {
299347 const k = generateSync ( 'RSA' , 784 )
300348 t . true ( k . algorithms ( ) . has ( 'PS384' ) )
@@ -322,6 +370,13 @@ test(`RSA key .algorithms invalid operation`, t => {
322370 t . true ( k . algorithms ( ) . has ( 'PS384' ) )
323371 } )
324372
373+ if ( oaepHash ) {
374+ test ( 'RSA key >= 896 bits can do RSA-OAEP-256' , t => {
375+ const k = generateSync ( 'RSA' , 896 )
376+ t . true ( k . algorithms ( ) . has ( 'RSA-OAEP-256' ) )
377+ } )
378+ }
379+
325380 test ( 'RSA key >= 1152 bits can do PS512' , t => {
326381 const k = generateSync ( 'RSA' , 1152 )
327382 t . true ( k . algorithms ( ) . has ( 'PS512' ) )
0 commit comments