| 
81 | 81 |                     }  | 
82 | 82 | 
 
  | 
83 | 83 |                     testFormat(format, algorithm, data, vector.name, usages, extractable);  | 
 | 84 | + | 
 | 85 | +                    // Test for https://github.com/WICG/webcrypto-secure-curves/pull/24  | 
 | 86 | +                    if (format === "jwk" && extractable) {  | 
 | 87 | +                        testJwkAlgBehaviours(algorithm, data.jwk, vector.name, usages);  | 
 | 88 | +                    }  | 
84 | 89 |                 });  | 
85 | 90 | 
 
  | 
86 | 91 |             });  | 
 | 
92 | 97 |                     var data = keyData[vector.name];  | 
93 | 98 | 
 
  | 
94 | 99 |                     testFormat(format, algorithm, data, vector.name, usages, extractable);  | 
 | 100 | + | 
 | 101 | +                    // Test for https://github.com/WICG/webcrypto-secure-curves/pull/24  | 
 | 102 | +                    if (format === "jwk" && extractable) {  | 
 | 103 | +                        testJwkAlgBehaviours(algorithm, data.jwk, vector.name, usages);  | 
 | 104 | +                    }  | 
95 | 105 |                 });  | 
96 | 106 |             });  | 
97 | 107 |         });  | 
 | 
126 | 136 |         }, "Good parameters: " + keySize.toString() + " bits " + parameterString(format, keyData[format], algorithm, extractable, usages));  | 
127 | 137 |     }  | 
128 | 138 | 
 
  | 
 | 139 | +    // Test importKey/exportKey "alg" behaviours, alg is ignored upon import and alg is missing for Ed25519 and Ed448 JWK export  | 
 | 140 | +    // https://github.com/WICG/webcrypto-secure-curves/pull/24  | 
 | 141 | +    function testJwkAlgBehaviours(algorithm, keyData, crv, usages) {  | 
 | 142 | +        promise_test(function(test) {  | 
 | 143 | +            return subtle.importKey('jwk', { ...keyData, alg: 'this is ignored' }, algorithm, true, usages).  | 
 | 144 | +            then(function(key) {  | 
 | 145 | +                assert_equals(key.constructor, CryptoKey, "Imported a CryptoKey object");  | 
 | 146 | + | 
 | 147 | +                return subtle.exportKey('jwk', key).  | 
 | 148 | +                then(function(result) {  | 
 | 149 | +                    assert_equals(Object.keys(result).length, keyData.d ? 6 : 5, "Correct number of JWK members");  | 
 | 150 | +                    assert_equals(result.alg, undefined, 'No JWK "alg" member is present');  | 
 | 151 | +                    assert_true(equalJwk(keyData, result), "Round trip works");  | 
 | 152 | +                }, function(err) {  | 
 | 153 | +                    assert_unreached("Threw an unexpected error: " + err.toString());  | 
 | 154 | +                });  | 
 | 155 | +            }, function(err) {  | 
 | 156 | +                assert_unreached("Threw an unexpected error: " + err.toString());  | 
 | 157 | +            });  | 
 | 158 | +        }, "Good parameters with ignored JWK alg: " + crv.toString() + " " + parameterString('jwk', keyData, algorithm, true, usages));  | 
 | 159 | +    }  | 
 | 160 | + | 
129 | 161 | 
 
  | 
130 | 162 | 
 
  | 
131 | 163 |     // Helper methods follow:  | 
 | 
0 commit comments