mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +00:00
LibWeb: Add happy path test for SubtleCrypto importKey and digest
This commit is contained in:
parent
be8489fb04
commit
bf32a2027b
Notes:
sideshowbarker
2024-07-16 23:34:49 +09:00
Author: https://github.com/ADKaster Commit: https://github.com/SerenityOS/serenity/commit/bf32a2027b Pull-request: https://github.com/SerenityOS/serenity/pull/22346
2 changed files with 36 additions and 0 deletions
|
@ -0,0 +1,5 @@
|
|||
imported key: [object CryptoKey]
|
||||
imported key.type: secret
|
||||
imported key.extractable: false
|
||||
imported key.algorithm: {"name":"PBKDF2"}
|
||||
SHA-256 digest: 315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3
|
|
@ -0,0 +1,31 @@
|
|||
<script src="../include.js"></script>
|
||||
<script>
|
||||
function bufferToHex(buffer) {
|
||||
return [...new Uint8Array(buffer)].map(b => b.toString(16).padStart(2, "0")).join("");
|
||||
}
|
||||
|
||||
test(async () => {
|
||||
let key_material = "password";
|
||||
let enc = new TextEncoder();
|
||||
let key = await window.crypto.subtle.importKey(
|
||||
"raw",
|
||||
enc.encode(key_material),
|
||||
{ name: "PBKDF2" },
|
||||
false,
|
||||
["deriveBits", "deriveKey"]
|
||||
);
|
||||
|
||||
println(`imported key: ${key}`);
|
||||
println(`imported key.type: ${key.type}`);
|
||||
println(`imported key.extractable: ${key.extractable}`);
|
||||
println(`imported key.algorithm: ${JSON.stringify(key.algorithm)}`);
|
||||
// FIXME: Implement usages println(`imported key.usages: ${key.usages}`);
|
||||
|
||||
let message = "Hello, world!";
|
||||
let encoded_message = enc.encode(message);
|
||||
|
||||
let digest = await window.crypto.subtle.digest("SHA-256", encoded_message);
|
||||
|
||||
println(`SHA-256 digest: ${bufferToHex(digest)}`);
|
||||
});
|
||||
</script>
|
Loading…
Reference in a new issue