| 163 | } |
| 164 | |
| 165 | toCryptoKey(algorithm, extractable, keyUsages) { |
| 166 | webidl ??= require('internal/crypto/webidl'); |
| 167 | algorithm = normalizeAlgorithm(webidl.converters.AlgorithmIdentifier(algorithm), 'importKey'); |
| 168 | extractable = webidl.converters.boolean(extractable); |
| 169 | keyUsages = webidl.converters['sequence<KeyUsage>'](keyUsages); |
| 170 | |
| 171 | const type = getKeyObjectType(this); |
| 172 | const handle = getKeyObjectHandle(this); |
| 173 | switch (type) { |
| 174 | case 'secret': |
| 175 | return toCryptoKeySecret( |
| 176 | handle, |
| 177 | algorithm, |
| 178 | extractable, |
| 179 | keyUsages); |
| 180 | case 'public': |
| 181 | // Fall through |
| 182 | case 'private': |
| 183 | return toCryptoKey( |
| 184 | handle, |
| 185 | algorithm, |
| 186 | extractable, |
| 187 | keyUsages); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | static from(key) { |
| 192 | if (!isCryptoKey(key)) |