Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/fixtures/wpt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Last update:
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/288c467d35/wasm/jsapi
- wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi
- web-locks: https://github.com/web-platform-tests/wpt/tree/10a122a6bc/web-locks
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/8b5cd267b4/WebCryptoAPI
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/97bbc7247a/WebCryptoAPI
- webidl: https://github.com/web-platform-tests/wpt/tree/63ca529a02/webidl
- webidl/ecmascript-binding/es-exceptions: https://github.com/web-platform-tests/wpt/tree/2f96fa1996/webidl/ecmascript-binding/es-exceptions
- webmessaging/broadcastchannel: https://github.com/web-platform-tests/wpt/tree/6495c91853/webmessaging/broadcastchannel
Expand Down
10 changes: 5 additions & 5 deletions test/fixtures/wpt/WebCryptoAPI/import_export/ML-KEM_importKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ var subtle = crypto.subtle;
function runTests(algorithmName) {
var algorithm = { name: algorithmName };
var data = keyData[algorithmName];
// var jwkData = {jwk: {kty: data.jwk.kty, alg: data.jwk.alg, pub: data.jwk.pub}};

// TODO: add JWK when its definition is done in IETF JOSE WG
var jwkData = {
jwk: { kty: data.jwk.kty, alg: data.jwk.alg, pub: data.jwk.pub },
};

[true, false].forEach(function (extractable) {
// Test public keys first
allValidUsages(data.publicUsages, true).forEach(function (usages) {
['spki', /*'jwk',*/ 'raw-public'].forEach(function (format) {
['spki', 'jwk', 'raw-public'].forEach(function (format) {
if (format === 'jwk') {
// Not all fields used for public keys
testFormat(
Expand All @@ -36,7 +36,7 @@ function runTests(algorithmName) {

// Next, test private keys
allValidUsages(data.privateUsages).forEach(function (usages) {
['pkcs8', /*'jwk',*/ 'raw-seed'].forEach(function (format) {
['pkcs8', 'jwk', 'raw-seed'].forEach(function (format) {
testFormat(format, algorithm, data, algorithmName, usages, extractable);
});
});
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions test/fixtures/wpt/WebCryptoAPI/serialization/aes-cbc.https.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// META: title=WebCryptoAPI: CryptoKey serialization
// META: script=../util/helpers.js
// META: script=serialization.js
run_test([
{
name: 'AES-CBC',
resultType: 'CryptoKey',
usages: ['encrypt', 'decrypt', 'wrapKey', 'unwrapKey'],
exportFormat: 'raw'
},
]);
11 changes: 11 additions & 0 deletions test/fixtures/wpt/WebCryptoAPI/serialization/aes-ctr.https.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// META: title=WebCryptoAPI: CryptoKey serialization
// META: script=../util/helpers.js
// META: script=serialization.js
run_test([
{
name: 'AES-CTR',
resultType: 'CryptoKey',
usages: ['encrypt', 'decrypt', 'wrapKey', 'unwrapKey'],
exportFormat: 'raw'
},
]);
11 changes: 11 additions & 0 deletions test/fixtures/wpt/WebCryptoAPI/serialization/aes-gcm.https.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// META: title=WebCryptoAPI: CryptoKey serialization
// META: script=../util/helpers.js
// META: script=serialization.js
run_test([
{
name: 'AES-GCM',
resultType: 'CryptoKey',
usages: ['encrypt', 'decrypt', 'wrapKey', 'unwrapKey'],
exportFormat: 'raw'
},
]);
11 changes: 11 additions & 0 deletions test/fixtures/wpt/WebCryptoAPI/serialization/aes-kw.https.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// META: title=WebCryptoAPI: CryptoKey serialization
// META: script=../util/helpers.js
// META: script=serialization.js
run_test([
{
name: 'AES-KW',
resultType: 'CryptoKey',
usages: ['wrapKey', 'unwrapKey'],
exportFormat: 'raw'
},
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// META: title=WebCryptoAPI: CryptoKey serialization
// META: script=../util/helpers.js
// META: script=serialization.js
run_test([
{
name: 'AES-OCB',
resultType: 'CryptoKey',
usages: ['encrypt', 'decrypt', 'wrapKey', 'unwrapKey'],
exportFormat: 'raw-secret'
},
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// META: title=WebCryptoAPI: CryptoKey serialization
// META: script=../util/helpers.js
// META: script=serialization.js
run_test([
{
name: 'ChaCha20-Poly1305',
resultType: 'CryptoKey',
usages: ['encrypt', 'decrypt', 'wrapKey', 'unwrapKey'],
exportFormat: 'raw-secret'
},
]);
12 changes: 12 additions & 0 deletions test/fixtures/wpt/WebCryptoAPI/serialization/ecdh.https.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// META: title=WebCryptoAPI: CryptoKey serialization
// META: script=../util/helpers.js
// META: script=serialization.js
run_test([
{
name: 'ECDH',
resultType: 'CryptoKeyPair',
usages: ['deriveKey', 'deriveBits'],
publicFormat: 'raw',
privateFormat: 'pkcs8'
},
]);
12 changes: 12 additions & 0 deletions test/fixtures/wpt/WebCryptoAPI/serialization/ecdsa.https.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// META: title=WebCryptoAPI: CryptoKey serialization
// META: script=../util/helpers.js
// META: script=serialization.js
run_test([
{
name: 'ECDSA',
resultType: 'CryptoKeyPair',
usages: ['sign', 'verify'],
publicFormat: 'raw',
privateFormat: 'pkcs8'
},
]);
12 changes: 12 additions & 0 deletions test/fixtures/wpt/WebCryptoAPI/serialization/ed25519.https.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// META: title=WebCryptoAPI: CryptoKey serialization
// META: script=../util/helpers.js
// META: script=serialization.js
run_test([
{
name: 'Ed25519',
resultType: 'CryptoKeyPair',
usages: ['sign', 'verify'],
publicFormat: 'raw',
privateFormat: 'pkcs8'
},
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// META: title=WebCryptoAPI: CryptoKey serialization
// META: script=../util/helpers.js
// META: script=serialization.js
run_test([
{
name: 'Ed448',
resultType: 'CryptoKeyPair',
usages: ['sign', 'verify'],
publicFormat: 'raw',
privateFormat: 'pkcs8'
},
]);
11 changes: 11 additions & 0 deletions test/fixtures/wpt/WebCryptoAPI/serialization/hmac.https.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// META: title=WebCryptoAPI: CryptoKey serialization
// META: script=../util/helpers.js
// META: script=serialization.js
run_test([
{
name: 'HMAC',
resultType: 'CryptoKey',
usages: ['sign', 'verify'],
exportFormat: 'raw'
},
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// META: title=WebCryptoAPI: CryptoKey serialization
// META: script=../util/helpers.js
// META: script=serialization.js
run_test([
{
name: 'KMAC128',
resultType: 'CryptoKey',
usages: ['sign', 'verify'],
exportFormat: 'raw-secret'
},
{
name: 'KMAC256',
resultType: 'CryptoKey',
usages: ['sign', 'verify'],
exportFormat: 'raw-secret'
},
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// META: title=WebCryptoAPI: CryptoKey serialization
// META: script=../util/helpers.js
// META: script=serialization.js

run_test([
{
name: 'ML-DSA-44',
resultType: 'CryptoKeyPair',
usages: ['sign', 'verify'],
publicFormat: 'raw-public',
privateFormat: 'raw-seed'
},
{
name: 'ML-DSA-65',
resultType: 'CryptoKeyPair',
usages: ['sign', 'verify'],
publicFormat: 'raw-public',
privateFormat: 'raw-seed'
},
{
name: 'ML-DSA-87',
resultType: 'CryptoKeyPair',
usages: ['sign', 'verify'],
publicFormat: 'raw-public',
privateFormat: 'raw-seed'
},
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// META: title=WebCryptoAPI: CryptoKey serialization
// META: script=../util/helpers.js
// META: script=serialization.js
run_test([
{
name: 'ML-KEM-512',
resultType: 'CryptoKeyPair',
usages: [
'decapsulateBits', 'decapsulateKey', 'encapsulateBits', 'encapsulateKey'
],
publicFormat: 'raw-public',
privateFormat: 'raw-seed'
},
{
name: 'ML-KEM-768',
resultType: 'CryptoKeyPair',
usages: [
'decapsulateBits', 'decapsulateKey', 'encapsulateBits', 'encapsulateKey'
],
publicFormat: 'raw-public',
privateFormat: 'raw-seed'
},
{
name: 'ML-KEM-1024',
resultType: 'CryptoKeyPair',
usages: [
'decapsulateBits', 'decapsulateKey', 'encapsulateBits', 'encapsulateKey'
],
publicFormat: 'raw-public',
privateFormat: 'raw-seed'
},
]);
12 changes: 12 additions & 0 deletions test/fixtures/wpt/WebCryptoAPI/serialization/rsa-oaep.https.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// META: title=WebCryptoAPI: CryptoKey serialization
// META: script=../util/helpers.js
// META: script=serialization.js
run_test([
{
name: 'RSA-OAEP',
resultType: 'CryptoKeyPair',
usages: ['encrypt', 'decrypt', 'wrapKey', 'unwrapKey'],
publicFormat: 'spki',
privateFormat: 'pkcs8'
},
]);
12 changes: 12 additions & 0 deletions test/fixtures/wpt/WebCryptoAPI/serialization/rsa-pss.https.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// META: title=WebCryptoAPI: CryptoKey serialization
// META: script=../util/helpers.js
// META: script=serialization.js
run_test([
{
name: 'RSA-PSS',
resultType: 'CryptoKeyPair',
usages: ['sign', 'verify'],
publicFormat: 'spki',
privateFormat: 'pkcs8'
},
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// META: title=WebCryptoAPI: CryptoKey serialization
// META: script=../util/helpers.js
// META: script=serialization.js
run_test([
{
name: 'RSASSA-PKCS1-v1_5',
resultType: 'CryptoKeyPair',
usages: ['sign', 'verify'],
publicFormat: 'spki',
privateFormat: 'pkcs8'
},
]);
55 changes: 55 additions & 0 deletions test/fixtures/wpt/WebCryptoAPI/serialization/serialization.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
});
}
});
}
12 changes: 12 additions & 0 deletions test/fixtures/wpt/WebCryptoAPI/serialization/x25519.https.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// META: title=WebCryptoAPI: CryptoKey serialization
// META: script=../util/helpers.js
// META: script=serialization.js
run_test([
{
name: 'X25519',
resultType: 'CryptoKeyPair',
usages: ['deriveKey', 'deriveBits'],
publicFormat: 'raw',
privateFormat: 'pkcs8'
},
]);
Loading
Loading