diff options
Diffstat (limited to 'Userland/Libraries/LibWeb/Crypto')
-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 |
5 files changed, 50 insertions, 2 deletions
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 { +}; |