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

LibWeb: Add the SubtleCrypto interface

Just some boilerplate code to get started :^)
This adds both the SubtleCrypto constructor to the window object, as
well as the crypto.subtle instance attribute.
This commit is contained in:
Linus Groh 2021-12-13 20:48:27 +00:00 committed by Andreas Kling
parent ce6c515873
commit 615be9eb7c
8 changed files with 57 additions and 2 deletions

View file

@ -8,9 +8,15 @@
#include <LibJS/Runtime/TypedArray.h>
#include <LibWeb/Bindings/Wrapper.h>
#include <LibWeb/Crypto/Crypto.h>
#include <LibWeb/Crypto/SubtleCrypto.h>
namespace Web::Crypto {
Crypto::Crypto()
: m_subtle(SubtleCrypto::create())
{
}
DOM::ExceptionOr<JS::Value> Crypto::get_random_values(JS::Value array) const
{
// 1. If array is not an Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, BigInt64Array, or BigUint64Array, then throw a TypeMismatchError and terminate the algorithm.

View file

@ -8,6 +8,7 @@
#include <LibJS/Runtime/Value.h>
#include <LibWeb/Bindings/Wrappable.h>
#include <LibWeb/Crypto/SubtleCrypto.h>
#include <LibWeb/DOM/ExceptionOr.h>
namespace Web::Crypto {
@ -23,10 +24,14 @@ public:
return adopt_ref(*new Crypto());
}
NonnullRefPtr<SubtleCrypto> subtle() const { return m_subtle; }
DOM::ExceptionOr<JS::Value> get_random_values(JS::Value array) const;
private:
Crypto() = default;
Crypto();
NonnullRefPtr<SubtleCrypto> m_subtle;
};
}

View file

@ -1,6 +1,6 @@
[Exposed=(Window,Worker)]
interface Crypto {
// TODO: [SecureContext] readonly attribute SubtleCrypto subtle;
[SecureContext] readonly attribute SubtleCrypto subtle;
// FIXME: the argument and the return value should be of type ArrayBufferView
any getRandomValues(any array);

View file

@ -0,0 +1,34 @@
/*
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/Bindings/Wrappable.h>
namespace Web::Crypto {
class SubtleCrypto
: public Bindings::Wrappable
, public RefCounted<SubtleCrypto> {
public:
using WrapperType = Bindings::SubtleCryptoWrapper;
static NonnullRefPtr<SubtleCrypto> create()
{
return adopt_ref(*new SubtleCrypto());
}
private:
SubtleCrypto() = default;
};
}
namespace Web::Bindings {
SubtleCryptoWrapper* wrap(JS::GlobalObject&, Crypto::SubtleCrypto&);
}

View file

@ -0,0 +1,3 @@
[SecureContext,Exposed=(Window,Worker)]
interface SubtleCrypto {
};