mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 10:44:56 +00:00
Bug 1286880 - add test to ensure deriveBits and deriveKey throw the correct errors given invalid length arguments r=keeler
Differential Revision: https://phabricator.services.mozilla.com/D80010
This commit is contained in:
parent
f1a544dd2d
commit
8ec8f43e46
@ -323,6 +323,72 @@ TestArray.addTest(
|
||||
.then( doDerive, fail );
|
||||
}
|
||||
);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
TestArray.addTest(
|
||||
"Fail while deriving bits given null length",
|
||||
function() {
|
||||
var that = this;
|
||||
var alg = "PBKDF2";
|
||||
var key = tv.pbkdf2_sha256.password;
|
||||
|
||||
function doDerive(x) {
|
||||
if (!hasKeyFields(x)) {
|
||||
throw new Error("Invalid key; missing field(s)");
|
||||
}
|
||||
|
||||
var algo = {
|
||||
name: "PBKDF2",
|
||||
hash: "SHA-256",
|
||||
salt: tv.pbkdf2_sha256.salt,
|
||||
iterations: tv.pbkdf2_sha256.iterations,
|
||||
};
|
||||
return crypto.subtle.deriveBits(algo, x, null).then(
|
||||
error(that),
|
||||
complete(that, function(e) {
|
||||
return e.name == "OperationError";
|
||||
})
|
||||
);
|
||||
}
|
||||
function fail(x) { console.log("failing"); error(that)(x); }
|
||||
|
||||
crypto.subtle.importKey("raw", key, alg, false, ["deriveBits"])
|
||||
.then( doDerive, fail );
|
||||
}
|
||||
);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
TestArray.addTest(
|
||||
"Fail while deriving key of null length",
|
||||
function() {
|
||||
var that = this;
|
||||
var alg = "PBKDF2";
|
||||
var key = tv.pbkdf2_sha256.password;
|
||||
|
||||
function doDerive(x) {
|
||||
if (!hasKeyFields(x)) {
|
||||
throw new Error("Invalid key; missing field(s)");
|
||||
}
|
||||
|
||||
var algo = {
|
||||
name: "PBKDF2",
|
||||
hash: "SHA-256",
|
||||
salt: tv.pbkdf2_sha256.salt,
|
||||
iterations: tv.pbkdf2_sha256.iterations,
|
||||
};
|
||||
return crypto.subtle.deriveKey(algo, x, {name: "AES-GCM", length: null}, true, ["encrypt"]).then(
|
||||
error(that),
|
||||
complete(that, function(e) {
|
||||
return e.name == "OperationError";
|
||||
})
|
||||
);
|
||||
}
|
||||
function fail(x) { console.log("failing"); error(that)(x); }
|
||||
|
||||
crypto.subtle.importKey("raw", key, alg, false, ["deriveKey", "deriveBits"])
|
||||
.then( doDerive, fail );
|
||||
}
|
||||
);
|
||||
/* ]]>*/</script>
|
||||
</head>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user