mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:07:34 +00:00
Tests/LibWeb: Add test for SubtleCrypto digest
This commit is contained in:
parent
d89e617a42
commit
bad7f0091f
2 changed files with 26 additions and 0 deletions
22
Tests/LibWeb/Text/input/Crypto/SubtleCrypto-digest.html
Normal file
22
Tests/LibWeb/Text/input/Crypto/SubtleCrypto-digest.html
Normal file
|
@ -0,0 +1,22 @@
|
|||
<script src="../include.js"></script>
|
||||
<script>
|
||||
function bufferToHex(buffer) {
|
||||
return [...new Uint8Array(buffer)].map(b => b.toString(16).padStart(2, "0")).join("");
|
||||
}
|
||||
async function printDigest(algorithm, encoded_message) {
|
||||
const digest = await window.crypto.subtle.digest(algorithm, encoded_message);
|
||||
println(`${algorithm} ${bufferToHex(digest)}`);
|
||||
}
|
||||
asyncTest(async done => {
|
||||
const encoder = new TextEncoder();
|
||||
const message = "Hello friends";
|
||||
const encoded_message = encoder.encode(message);
|
||||
|
||||
await printDigest("SHA-1", encoded_message);
|
||||
await printDigest("SHA-256", encoded_message);
|
||||
await printDigest("SHA-384", encoded_message);
|
||||
await printDigest("SHA-512", encoded_message);
|
||||
|
||||
done();
|
||||
});
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue