-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathserialization.js
More file actions
55 lines (51 loc) · 2.28 KB
/
serialization.js
File metadata and controls
55 lines (51 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function run_test(vectors) {
function testCryptoKeySerialization(
generateKeyAlgorithm, generateKeyUsages, exportFormat) {
promise_test(async t => {
var cryptoKey = await crypto.subtle.generateKey(
generateKeyAlgorithm, true, generateKeyUsages);
const keyExported =
await crypto.subtle.exportKey(exportFormat, cryptoKey);
const {key} = structuredClone({key: cryptoKey});
const newKeyExported =
await crypto.subtle.exportKey(exportFormat, key);
assert_true(equalBuffers(keyExported, newKeyExported));
}, 'serialization test ' + objectToString(generateKeyAlgorithm));
};
function testCryptoKeyPairSerialization(
generateKeyAlgorithm, generateKeyUsages, publicExportFormat,
privateExportFormat) {
promise_test(async t => {
var keyPair = await crypto.subtle.generateKey(
generateKeyAlgorithm, true, generateKeyUsages);
const publicKeyExported =
await crypto.subtle.exportKey(publicExportFormat, keyPair.publicKey);
const privateKeyExported = await crypto.subtle.exportKey(
privateExportFormat, keyPair.privateKey);
const {publicKey, privateKey} = structuredClone(
{publicKey: keyPair.publicKey, privateKey: keyPair.privateKey});
const newPublicKeyExported =
await crypto.subtle.exportKey(publicExportFormat, publicKey);
assert_true(equalBuffers(publicKeyExported, newPublicKeyExported));
const newPrivateKeyExported = await crypto.subtle.exportKey(
privateExportFormat, privateKey);
assert_true(equalBuffers(privateKeyExported, newPrivateKeyExported));
}, 'serialization test ' + objectToString(generateKeyAlgorithm));
};
vectors.forEach(function(vector) {
if (vector.resultType === 'CryptoKey') {
allAlgorithmSpecifiersFor(vector.name)
.forEach(function(generateKeyAlgorithm) {
testCryptoKeySerialization(
generateKeyAlgorithm, vector.usages, vector.exportFormat);
});
} else {
allAlgorithmSpecifiersFor(vector.name)
.forEach(function(generateKeyAlgorithm) {
testCryptoKeyPairSerialization(
generateKeyAlgorithm, vector.usages, vector.publicFormat,
vector.privateFormat);
});
}
});
}