Skip to content

Commit d71b56c

Browse files
javifernandezmoz-wptsync-bot
authored andcommitted
Bug 1930024 [wpt PR 49048] - WebCrypto: HDKF and PBKDF2 return an empty ArrayBuffer when length is zero, a=testonly
Automatic update from web-platform-tests WebCrypto: HDKF and PBKDF2 return an empty ArrayBuffer when length is zero (#49048) The HKDF and PBKDF2 derive bits operations were changed in [1] to allow a zero length to be passed and return an empty ArrayBuffer in that case. This PR updates the tests cases affecting these 2 algorithms in the cases where zero was passed as the length parameter. [1] w3c/webcrypto#380 -- wpt-commits: b81831169b8527a6c569a4ad92cf8a1baf4a7118 wpt-pr: 49048
1 parent eb0be79 commit d71b56c

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

testing/web-platform/tests/WebCryptoAPI/derive_bits_keys/derived_bits_length_testcases.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var testCases = {
33
{length: 256, expected: algorithms["HKDF"].derivation},
44
{length: 384, expected: algorithms["HKDF"].derivation384},
55
{length: 230, expected: undefined}, // should throw an exception, not multiple of 8
6-
{length: 0, expected: undefined}, // explicitly disallowed, so should throw
6+
{length: 0, expected: emptyArray},
77
{length: null, expected: undefined }, // should throw an exception
88
{length: undefined, expected: undefined }, // should throw an exception
99
{length: "omitted", expected: undefined }, // default value is null, so should throw
@@ -12,7 +12,7 @@ var testCases = {
1212
{length: 256, expected: algorithms["PBKDF2"].derivation},
1313
{length: 384, expected: algorithms["PBKDF2"].derivation384},
1414
{length: 230, expected: undefined}, // should throw an exception, not multiple of 8
15-
{length: 0, expected: undefined}, // explicitly disallowed, so should throw
15+
{length: 0, expected: emptyArray},
1616
{length: null, expected: undefined }, // should throw an exception
1717
{length: undefined, expected: undefined }, // should throw an exception
1818
{length: "omitted", expected: undefined }, // default value is null, so should throw

testing/web-platform/tests/WebCryptoAPI/derive_bits_keys/hkdf.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ function define_tests() {
4545
});
4646
}, testName);
4747

48-
// 0 length (OperationError)
48+
// 0 length
4949
subsetTest(promise_test, function(test) {
5050
return subtle.deriveBits(algorithm, baseKeys[derivedKeySize], 0)
5151
.then(function(derivation) {
5252
assert_equals(derivation.byteLength, 0, "Derived correctly empty key");
5353
}, function(err) {
54-
assert_equals(err.name, "OperationError", "deriveBits with 0 length correctly threw OperationError: " + err.message);
54+
assert_unreached("deriveBits failed with error " + err.name + ": " + err.message);
5555
});
5656
}, testName + " with 0 length");
5757

testing/web-platform/tests/WebCryptoAPI/derive_bits_keys/pbkdf2.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ function define_tests() {
4242
});
4343
}, testName);
4444

45+
// 0 length
46+
subsetTest(promise_test, function(test) {
47+
return subtle.deriveBits({name: "PBKDF2", salt: salts[saltSize], hash: hashName, iterations: parseInt(iterations)}, baseKeys[passwordSize], 0)
48+
.then(function(derivation) {
49+
assert_true(equalBuffers(derivation.byteLength, 0, "Derived correctly empty key"));
50+
}, function(err) {
51+
assert_unreached("deriveBits failed with error " + err.name + ": " + err.message);
52+
});
53+
}, testName + " with 0 length");
54+
4555
// Check for correct deriveKey results for every kind of
4656
// key that can be created by the deriveKeys operation.
4757
derivedKeyTypes.forEach(function(derivedKeyType) {
@@ -103,16 +113,6 @@ function define_tests() {
103113

104114
});
105115

106-
// 0 length (OperationError)
107-
subsetTest(promise_test, function(test) {
108-
return subtle.deriveBits({name: "PBKDF2", salt: salts[saltSize], hash: hashName, iterations: parseInt(iterations)}, baseKeys[passwordSize], 0)
109-
.then(function(derivation) {
110-
assert_unreached("0 length should have thrown an OperationError");
111-
}, function(err) {
112-
assert_equals(err.name, "OperationError", "deriveBits with 0 length correctly threw OperationError: " + err.message);
113-
});
114-
}, testName + " with 0 length");
115-
116116
// length not multiple of 8 (OperationError)
117117
subsetTest(promise_test, function(test) {
118118
return subtle.deriveBits({name: "PBKDF2", salt: salts[saltSize], hash: hashName, iterations: parseInt(iterations)}, baseKeys[passwordSize], 44)

0 commit comments

Comments
 (0)