( format, keyData, algorithm, extractable, usages, )
| 103 | } |
| 104 | |
| 105 | function macImportKey( |
| 106 | format, |
| 107 | keyData, |
| 108 | algorithm, |
| 109 | extractable, |
| 110 | usages, |
| 111 | ) { |
| 112 | const isHmac = algorithm.name === 'HMAC'; |
| 113 | const usagesSet = validateKeyUsages( |
| 114 | usages, kUsages, algorithm.name); |
| 115 | let handle; |
| 116 | let length; |
| 117 | switch (format) { |
| 118 | case 'KeyObjectHandle': { |
| 119 | handle = keyData; |
| 120 | break; |
| 121 | } |
| 122 | case 'raw-secret': |
| 123 | case 'raw': { |
| 124 | if (format === 'raw' && !isHmac) { |
| 125 | return undefined; |
| 126 | } |
| 127 | handle = importSecretKey(keyData); |
| 128 | break; |
| 129 | } |
| 130 | case 'jwk': { |
| 131 | validateJwk(keyData, 'oct', extractable, usagesSet, 'sig'); |
| 132 | |
| 133 | if (keyData.alg !== undefined) { |
| 134 | const expected = isHmac ? |
| 135 | normalizeHashName(algorithm.hash.name, normalizeHashName.kContextJwkHmac) : |
| 136 | `K${StringPrototypeSubstring(algorithm.name, 4)}`; |
| 137 | if (expected && keyData.alg !== expected) |
| 138 | throw lazyDOMException( |
| 139 | 'JWK "alg" does not match the requested algorithm', |
| 140 | 'DataError'); |
| 141 | } |
| 142 | |
| 143 | handle = importJwkSecretKey(keyData); |
| 144 | break; |
| 145 | } |
| 146 | default: |
| 147 | return undefined; |
| 148 | } |
| 149 | |
| 150 | ({ handle, length } = normalizeKeyLength(handle, algorithm)); // eslint-disable-line prefer-const |
| 151 | |
| 152 | const algorithmObject = { |
| 153 | name: algorithm.name, |
| 154 | length, |
| 155 | }; |
| 156 | |
| 157 | if (isHmac) { |
| 158 | algorithmObject.hash = algorithm.hash; |
| 159 | } |
| 160 | |
| 161 | return new InternalCryptoKey( |
| 162 | handle, |
nothing calls this directly
no test coverage detected
searching dependent graphs…