chromium/third_party/blink/web_tests/crypto/subtle/algorithm-identifier-as-string.html

<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test.js"></script>
<script src="resources/common.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>

<script>
description("Tests that a string can be passed in place of an AlgorithmIdentifier");

jsTestIsAsync = true;

Promise.resolve(null).then(function() {
    // Use a string algorithm identifier ("aes-cbc") as a parameter to importKey().
    return crypto.subtle.importKey("raw", new Uint8Array(16), "aes-cbc", true, ["encrypt"]);
}).then(function(result) {
    // Verify that the key was imported correctly.
    key = result;
    shouldEvaluateAs("key.type", "secret");
    shouldEvaluateAs("key.algorithm.name", "AES-CBC");
    shouldEvaluateAs("key.algorithm.length", 128);

    // Use a string algorithm identifier ("sha-1") as a parameter to digest().
    return crypto.subtle.digest("sha-1", new Uint8Array(0));
}).then(function(result) {
    bytesShouldMatchHexString("sha-1 of empty string", "da39a3ee5e6b4b0d3255bfef95601890afd80709", result);

    // Use a string algorithm identifier ("sha-256") for the hash property to hmac key import.
    return crypto.subtle.importKey("raw", new Uint8Array(15), {name: "hmac", hash: "sha-256"}, false, ["sign"]);
}).then(function(result) {
    // Verify that the key was imported correctly.
    key = result;
    shouldEvaluateAs("key.type", "secret");
    shouldEvaluateAs("key.algorithm.name", "HMAC");
    shouldEvaluateAs("key.algorithm.hash.name", "SHA-256");
    shouldEvaluateAs("key.algorithm.length", 120);
}).then(finishJSTest, failAndFinishJSTest);

</script>

</body>
</html>