1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:57:45 +00:00

Tests/LibWeb: Add test for SubtleCrypto digest

This commit is contained in:
Johannes Røsvik 2024-03-03 01:02:27 +01:00 committed by Andreas Kling
parent d89e617a42
commit bad7f0091f
2 changed files with 26 additions and 0 deletions

View 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>