(vectors)
| 1 | function run_test(vectors) { |
| 2 | function testCryptoKeySerialization( |
| 3 | generateKeyAlgorithm, generateKeyUsages, exportFormat) { |
| 4 | promise_test(async t => { |
| 5 | var cryptoKey = await crypto.subtle.generateKey( |
| 6 | generateKeyAlgorithm, true, generateKeyUsages); |
| 7 | const keyExported = |
| 8 | await crypto.subtle.exportKey(exportFormat, cryptoKey); |
| 9 | |
| 10 | const {key} = structuredClone({key: cryptoKey}); |
| 11 | const newKeyExported = |
| 12 | await crypto.subtle.exportKey(exportFormat, key); |
| 13 | assert_true(equalBuffers(keyExported, newKeyExported)); |
| 14 | }, 'serialization test ' + objectToString(generateKeyAlgorithm)); |
| 15 | }; |
| 16 | |
| 17 | function testCryptoKeyPairSerialization( |
| 18 | generateKeyAlgorithm, generateKeyUsages, publicExportFormat, |
| 19 | privateExportFormat) { |
| 20 | promise_test(async t => { |
| 21 | var keyPair = await crypto.subtle.generateKey( |
| 22 | generateKeyAlgorithm, true, generateKeyUsages); |
| 23 | const publicKeyExported = |
| 24 | await crypto.subtle.exportKey(publicExportFormat, keyPair.publicKey); |
| 25 | const privateKeyExported = await crypto.subtle.exportKey( |
| 26 | privateExportFormat, keyPair.privateKey); |
| 27 | |
| 28 | const {publicKey, privateKey} = structuredClone( |
| 29 | {publicKey: keyPair.publicKey, privateKey: keyPair.privateKey}); |
| 30 | const newPublicKeyExported = |
| 31 | await crypto.subtle.exportKey(publicExportFormat, publicKey); |
| 32 | assert_true(equalBuffers(publicKeyExported, newPublicKeyExported)); |
| 33 | const newPrivateKeyExported = await crypto.subtle.exportKey( |
| 34 | privateExportFormat, privateKey); |
| 35 | assert_true(equalBuffers(privateKeyExported, newPrivateKeyExported)); |
| 36 | }, 'serialization test ' + objectToString(generateKeyAlgorithm)); |
| 37 | }; |
| 38 | |
| 39 | vectors.forEach(function(vector) { |
| 40 | if (vector.resultType === 'CryptoKey') { |
| 41 | allAlgorithmSpecifiersFor(vector.name) |
| 42 | .forEach(function(generateKeyAlgorithm) { |
| 43 | testCryptoKeySerialization( |
| 44 | generateKeyAlgorithm, vector.usages, vector.exportFormat); |
| 45 | }); |
| 46 | } else { |
| 47 | allAlgorithmSpecifiersFor(vector.name) |
| 48 | .forEach(function(generateKeyAlgorithm) { |
| 49 | testCryptoKeyPairSerialization( |
| 50 | generateKeyAlgorithm, vector.usages, vector.publicFormat, |
| 51 | vector.privateFormat); |
| 52 | }); |
| 53 | } |
| 54 | }); |
| 55 | } |
no test coverage detected