1
1
import type QUnit from 'qunit'
2
2
import type * as jose from '../src/index.js'
3
3
import * as roundtrip from './encrypt.js'
4
+ import * as env from './env.js'
4
5
5
6
export default (
6
7
QUnit : QUnit ,
@@ -12,27 +13,18 @@ export default (
12
13
13
14
const kps : Record < string , jose . GenerateKeyPairResult > = { }
14
15
15
- type Vector = [ string , boolean ]
16
- const algorithms : Vector [ ] = [
17
- [ 'RSA-OAEP' , true ] ,
18
- [ 'RSA-OAEP-256' , true ] ,
19
- [ 'RSA-OAEP-384' , true ] ,
20
- [ 'RSA-OAEP-512' , true ] ,
21
- ]
16
+ const algorithms = [ 'RSA-OAEP' , 'RSA-OAEP-256' , 'RSA-OAEP-384' , 'RSA-OAEP-512' ]
22
17
23
- function title ( vector : Vector ) {
24
- const [ alg , works ] = vector
18
+ function title ( alg : string , supported = true ) {
25
19
let result = ''
26
- if ( ! works ) {
20
+ if ( ! supported ) {
27
21
result = '[not supported] '
28
22
}
29
23
result += `${ alg } `
30
24
return result
31
25
}
32
26
33
- for ( const vector of algorithms ) {
34
- const [ alg , works ] = vector
35
-
27
+ for ( const alg of algorithms ) {
36
28
const execute = async ( t : typeof QUnit . assert ) => {
37
29
if ( ! kps [ alg ] ) {
38
30
kps [ alg ] = await keys . generateKeyPair ( alg , { extractable : true } )
@@ -49,11 +41,11 @@ export default (
49
41
await roundtrip . jwt ( t , lib , keys , alg , 'A128GCM' , kps [ alg ] )
50
42
}
51
43
52
- if ( works ) {
53
- test ( title ( vector ) , execute )
54
- test ( `${ title ( vector ) } JWT` , jwt )
44
+ if ( env . supported ( alg ) ) {
45
+ test ( title ( alg ) , execute )
46
+ test ( `${ title ( alg ) } JWT` , jwt )
55
47
} else {
56
- test ( title ( vector ) , async ( t ) => {
48
+ test ( title ( alg , false ) , async ( t ) => {
57
49
await t . rejects ( execute ( t ) )
58
50
} )
59
51
}
0 commit comments