-function importTestKeys()
+function logError(error)
{
- var keyFormat = "raw";
- var data = asciiToUint8Array("16 bytes of key!");
- var extractable = true;
- var keyUsages = ['encrypt', 'decrypt', 'sign', 'verify'];
-
- var hmacPromise = crypto.subtle.importKey(keyFormat, data, {name: 'hmac', hash: {name: 'sha-1'}}, extractable, keyUsages);
- var aesCbcPromise = crypto.subtle.importKey(keyFormat, data, {name: 'AES-CBC'}, extractable, keyUsages);
- var aesCbcJustDecrypt = crypto.subtle.importKey(keyFormat, data, {name: 'AES-CBC'}, false, ['decrypt']);
-
- return Promise.all([hmacPromise, aesCbcPromise, aesCbcJustDecrypt]).then(function(results) {
- return {
- hmacSha1: results[0],
- aesCbc: results[1],
- aesCbcJustDecrypt: results[2],
- };
- });
+ debug("error is: " + error.toString());
}
// Verifies that the given "bytes" holds the same value as "expectedHexString".
function failAndFinishJSTest(error)
{
- if (error)
- debug(error);
+ testFailed('' + error);
finishJSTest();
}
+
+// Returns a Promise for the cloned key.
+function cloneKey(key)
+{
+ // Sending an object through a MessagePort implicitly clones it.
+ // Use a single MessageChannel so requests complete in FIFO order.
+ var self = cloneKey;
+ if (!self.channel) {
+ self.channel = new MessageChannel();
+ self.callbacks = [];
+ self.channel.port1.addEventListener('message', function(e) {
+ var callback = self.callbacks.shift();
+ callback(e.data);
+ }, false);
+ self.channel.port1.start();
+ }
+
+ return new Promise(function(resolve, reject) {
+ self.callbacks.push(resolve);
+ self.channel.port2.postMessage(key);
+ });
+}
+
+// Logging the serialized format ensures that if it changes it will break tests.
+function logSerializedKey(o)
+{
+ if (internals) {
+ // Removing the version tag from the output so serialization format changes don't need to update all the crypto tests.
+ var serialized = internals.serializeObject(o);
+ var serializedWithoutVersion = new Uint8Array(serialized, 2);
+ debug("Serialized key bytes: " + bytesToHexString(serializedWithoutVersion));
+ }
+}
+
+function shouldEvaluateAs(actual, expectedValue)
+{
+ if (typeof expectedValue == "string")
+ return shouldBeEqualToString(actual, expectedValue);
+ return shouldEvaluateTo(actual, expectedValue);
+}