Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Unified Diff: LayoutTests/crypto/normalize-algorithm.html

Issue 18475002: WebCrypto: Add framework for AlgorithmIdentifier normalization. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rename verify --> verifySignature (because "verify" is a macro on Mac) Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | LayoutTests/crypto/normalize-algorithm-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/crypto/normalize-algorithm.html
diff --git a/LayoutTests/crypto/normalize-algorithm.html b/LayoutTests/crypto/normalize-algorithm.html
new file mode 100644
index 0000000000000000000000000000000000000000..4d9ea45816d62bbcae8b4aafedc765722c010f94
--- /dev/null
+++ b/LayoutTests/crypto/normalize-algorithm.html
@@ -0,0 +1,116 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Tests algorithm normalization.");
+
+// -------------------------------
+// Helpers to return a normalized algorithm identifier.
+// -------------------------------
+
+function normalizeDigest(algorithmIdentifier) {
+ return crypto.subtle.digest(algorithmIdentifier).algorithm;
+}
+
+function normalizeEncrypt(algorithmIdentifier) {
+ // TODO(eroman): Use a valid key.
+ var key;
+ return crypto.subtle.encrypt(algorithmIdentifier, key).algorithm;
+}
+
+// -------------------------------
+// Case insensitivity of "name"
+// -------------------------------
+algorithm = normalizeDigest({name: "SHA-1"});
+shouldBe("algorithm.name", "'SHA-1'");
+algorithm = normalizeDigest({name: "sHa-256"});
+shouldBe("algorithm.name", "'SHA-256'");
+
+// -------------------------------
+// Failures if "name" is invalid
+// -------------------------------
+shouldThrow("normalizeDigest({})");
+shouldThrow("normalizeDigest({name: null})");
+shouldThrow("normalizeDigest({name: -1})");
+shouldThrow("normalizeDigest({name: ''})");
+shouldThrow("normalizeDigest({name: 'nosuchalgorithm'})");
+shouldThrow("normalizeDigest({name: '\\u0189'})");
+
+// -------------------------------
+// Failures if the algorithm identifier is not an object
+// -------------------------------
+shouldThrow("normalizeDigest(null)");
+shouldThrow("normalizeDigest(0)");
+shouldThrow("normalizeDigest(undefined)");
+shouldThrow("normalizeDigest('')");
+
+// -------------------------------
+// Skip unrecognized parameters.
+// -------------------------------
+algorithm = normalizeDigest({name: "sHa-1", noSuchParam: 3});
+shouldBeUndefined("algorithm.noSuchParam");
+
+// -------------------------------
+// Normalized algorithm COPIES all data
+// -------------------------------
+originalIv = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]);
+algorithm = normalizeEncrypt({ name: "aes-cbc", iv: originalIv });
+
+// Make sure it constructed the normalized result.
+shouldBe("algorithm.name", "'AES-CBC'");
+shouldBe("algorithm.iv.length", "16");
+shouldBe("algorithm.iv[3]", "3");
+
+// Mutate the original (un-normalized) algorithm. Verify that this doesn't affect the normalized output.
+originalIv[3] = 0;
+shouldBe("algorithm.iv[3]", "3");
+
+// -------------------------------
+// AES-CBC normalization failures
+// -------------------------------
+
+// The "iv" MUST be 16 bytes long.
+rawAlgorithm = {
+ name: "AES-CBC",
+ iv: new Uint8Array([1, 2, 3])
+};
+shouldThrow("normalizeEncrypt(rawAlgorithm)");
+
+// -------------------------------
+// Normalize a normalized algorithm (SHA-384)
+// -------------------------------
+algorithm = normalizeDigest({name: "sHa-384"});
+shouldBe("algorithm.name", "'SHA-384'");
+algorithm = normalizeDigest(algorithm);
+shouldBe("algorithm.name", "'SHA-384'");
+
+// -------------------------------
+// Normalize a normalized algorithm (AES-CBC, encrypt)
+// -------------------------------
+algorithm = normalizeEncrypt({ name: "aEs-cbc", iv: originalIv });
+// Make sure it constructed the normalized result.
+shouldBe("algorithm.name", "'AES-CBC'");
+shouldBe("algorithm.iv.length", "16");
+shouldBe("algorithm.iv[1]", "1");
+algorithm = normalizeEncrypt(algorithm);
+shouldBe("algorithm.name", "'AES-CBC'");
+shouldBe("algorithm.iv.length", "16");
+shouldBe("algorithm.iv[1]", "1");
+
+// -------------------------------
+// Unsupported operation on algorithm
+// -------------------------------
+shouldThrow("normalizeEncrypt({ name: 'SHA-1' })");
+shouldThrow("normalizeDigest({ name: 'AES-CBC', iv: originalIv })");
+
+</script>
+
+<script src="../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
« no previous file with comments | « no previous file | LayoutTests/crypto/normalize-algorithm-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698