sha-1.html 1.3 KB
Newer Older
ap@apple.com's avatar
ap@apple.com committed
1 2 3
<!DOCTYPE html>
<html>
<head>
ap@apple.com's avatar
ap@apple.com committed
4
<script src="../../resources/js-test-pre.js"></script>
ap@apple.com's avatar
ap@apple.com committed
5 6 7 8 9 10 11 12 13 14 15
<script src="resources/common.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>

<script>
description("Test crypto.subtle.digest.");

jsTestIsAsync = true;

16
Promise.resolve(null).then(function() {
ap@apple.com's avatar
ap@apple.com committed
17
    debug("SHA1 of []");
18
    return crypto.subtle.digest('sha-1', new Uint8Array([]));
ap@apple.com's avatar
ap@apple.com committed
19
}).then(function(result) {
ap@apple.com's avatar
ap@apple.com committed
20 21
    digest = result;
    shouldBe("bytesToHexString(new Uint8Array(digest))", "'da39a3ee5e6b4b0d3255bfef95601890afd80709'");
ap@apple.com's avatar
ap@apple.com committed
22 23

    debug("SHA1 of [0x0]")
24
    return crypto.subtle.digest({name: 'sha-1'}, new Uint8Array([0]));
ap@apple.com's avatar
ap@apple.com committed
25
}).then(function(result) {
ap@apple.com's avatar
ap@apple.com committed
26 27
    digest = result;
    shouldBe("bytesToHexString(new Uint8Array(digest))", "'5ba93c9db0cff93f52b521d7420e43f6eda2784f'");
ap@apple.com's avatar
ap@apple.com committed
28 29 30

    debug("SHA1 of [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]");
    var data = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
31
    return crypto.subtle.digest({name: 'sha-1'}, data);
ap@apple.com's avatar
ap@apple.com committed
32
}).then(function(result) {
ap@apple.com's avatar
ap@apple.com committed
33 34
    digest = result;
    shouldBe("bytesToHexString(new Uint8Array(digest))", "'2c7e7c384f7829694282b1e3a6216def8082d055'");
ap@apple.com's avatar
ap@apple.com committed
35 36 37 38 39 40 41

    // All SHA-1 can do is digest.
    shouldThrow("crypto.subtle.generateKey('sha-1')");
    finishJSTest();
});
</script>

ap@apple.com's avatar
ap@apple.com committed
42
<script src="../../resources/js-test-post.js"></script>
ap@apple.com's avatar
ap@apple.com committed
43 44
</body>
</html>