sha-256.html 1.29 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<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() {
17
    debug("SHA256 of []");
18
    return crypto.subtle.digest('sha-256', new Uint8Array([]));
19
}).then(function(result) {
ap@apple.com's avatar
ap@apple.com committed
20 21
    digest = result;
    shouldBe("bytesToHexString(new Uint8Array(digest))", "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'");
22 23

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

    debug("SHA256 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-256'}, data);
32
}).then(function(result) {
ap@apple.com's avatar
ap@apple.com committed
33 34
    digest = result;
    shouldBe("bytesToHexString(new Uint8Array(digest))", "'78a6273103d17c39a0b6126e226cec70e33337f4bc6a38067401b54a33e78ead'");
35 36 37 38 39 40 41
    finishJSTest();
});
</script>

<script src="../../resources/js-test-post.js"></script>
</body>
</html>