diff options
author | Linus Groh <mail@linusgroh.de> | 2021-12-13 20:48:27 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-12-14 09:01:06 +0100 |
commit | 615be9eb7ca88b20a13021cdf3eaf058c9059599 (patch) | |
tree | 03850ea8c22d72e09dc03f2e7ece2b8b7aaaa79a /Userland/Libraries/LibWeb | |
parent | ce6c515873072c4a51fe5cbc02755e9de7bbe952 (diff) | |
download | serenity-615be9eb7ca88b20a13021cdf3eaf058c9059599.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r-- | Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Crypto/Crypto.cpp | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Crypto/Crypto.h | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Crypto/Crypto.idl | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Crypto/SubtleCrypto.h | 34 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Crypto/SubtleCrypto.idl | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Forward.h | 2 |
7 files changed, 55 insertions, 2 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h index 3faa49a98e..b7f13c05e6 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h +++ b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h @@ -261,6 +261,8 @@ #include <LibWeb/Bindings/StyleSheetPrototype.h> #include <LibWeb/Bindings/SubmitEventConstructor.h> #include <LibWeb/Bindings/SubmitEventPrototype.h> +#include <LibWeb/Bindings/SubtleCryptoConstructor.h> +#include <LibWeb/Bindings/SubtleCryptoPrototype.h> #include <LibWeb/Bindings/TextConstructor.h> #include <LibWeb/Bindings/TextEncoderConstructor.h> #include <LibWeb/Bindings/TextEncoderPrototype.h> @@ -412,6 +414,7 @@ ADD_WINDOW_OBJECT_INTERFACE(StyleSheet) \ ADD_WINDOW_OBJECT_INTERFACE(StyleSheetList) \ ADD_WINDOW_OBJECT_INTERFACE(SubmitEvent) \ + ADD_WINDOW_OBJECT_INTERFACE(SubtleCrypto) \ ADD_WINDOW_OBJECT_INTERFACE(SVGElement) \ ADD_WINDOW_OBJECT_INTERFACE(SVGGeometryElement) \ ADD_WINDOW_OBJECT_INTERFACE(SVGGraphicsElement) \ diff --git a/Userland/Libraries/LibWeb/Crypto/Crypto.cpp b/Userland/Libraries/LibWeb/Crypto/Crypto.cpp index 64ba54f6ed..020f10c0d8 100644 --- a/Userland/Libraries/LibWeb/Crypto/Crypto.cpp +++ b/Userland/Libraries/LibWeb/Crypto/Crypto.cpp @@ -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. diff --git a/Userland/Libraries/LibWeb/Crypto/Crypto.h b/Userland/Libraries/LibWeb/Crypto/Crypto.h index d469b7a48f..172e7de4e8 100644 --- a/Userland/Libraries/LibWeb/Crypto/Crypto.h +++ b/Userland/Libraries/LibWeb/Crypto/Crypto.h @@ -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; }; } diff --git a/Userland/Libraries/LibWeb/Crypto/Crypto.idl b/Userland/Libraries/LibWeb/Crypto/Crypto.idl index 64941a4980..8cedd797a4 100644 --- a/Userland/Libraries/LibWeb/Crypto/Crypto.idl +++ b/Userland/Libraries/LibWeb/Crypto/Crypto.idl @@ -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); diff --git a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.h b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.h new file mode 100644 index 0000000000..7d3b0d7d31 --- /dev/null +++ b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.h @@ -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&); + +} diff --git a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.idl b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.idl new file mode 100644 index 0000000000..e0e9d5489c --- /dev/null +++ b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.idl @@ -0,0 +1,3 @@ +[SecureContext,Exposed=(Window,Worker)] +interface SubtleCrypto { +}; diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 618a7cf1f8..0ef1d9ece1 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -15,6 +15,7 @@ enum class Source; namespace Web::Crypto { class Crypto; +class SubtleCrypto; } namespace Web::CSS { @@ -431,6 +432,7 @@ class SelectionWrapper; class StyleSheetListWrapper; class StyleSheetWrapper; class SubmitEventWrapper; +class SubtleCryptoWrapper; class SVGElementWrapper; class SVGGeometryElementWrapper; class SVGGraphicsElementWrapper; |