mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 20:57:41 +00:00
LibWeb: Move dictionaries to separate file
Co-Authored-By: Andrew Kaster <akaster@serenityos.org>
This commit is contained in:
parent
1bf73482f5
commit
3e0c0ce7ae
7 changed files with 170 additions and 10 deletions
|
@ -4,6 +4,8 @@ source_set("Crypto") {
|
||||||
sources = [
|
sources = [
|
||||||
"Crypto.cpp",
|
"Crypto.cpp",
|
||||||
"Crypto.h",
|
"Crypto.h",
|
||||||
|
"CryptoBindings.cpp",
|
||||||
|
"CryptoBindings.h",
|
||||||
"CryptoKey.cpp",
|
"CryptoKey.cpp",
|
||||||
"CryptoKey.h",
|
"CryptoKey.h",
|
||||||
"SubtleCrypto.cpp",
|
"SubtleCrypto.cpp",
|
||||||
|
|
|
@ -24,6 +24,7 @@ set(SOURCES
|
||||||
Bindings/PlatformObject.cpp
|
Bindings/PlatformObject.cpp
|
||||||
Clipboard/Clipboard.cpp
|
Clipboard/Clipboard.cpp
|
||||||
Crypto/Crypto.cpp
|
Crypto/Crypto.cpp
|
||||||
|
Crypto/CryptoBindings.cpp
|
||||||
Crypto/CryptoKey.cpp
|
Crypto/CryptoKey.cpp
|
||||||
Crypto/SubtleCrypto.cpp
|
Crypto/SubtleCrypto.cpp
|
||||||
CSS/Angle.cpp
|
CSS/Angle.cpp
|
||||||
|
|
53
Userland/Libraries/LibWeb/Crypto/CryptoBindings.cpp
Normal file
53
Userland/Libraries/LibWeb/Crypto/CryptoBindings.cpp
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023, stelar7 <dudedbz@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <LibJS/Runtime/AbstractOperations.h>
|
||||||
|
#include <LibJS/Runtime/GlobalObject.h>
|
||||||
|
#include <LibWeb/Bindings/ExceptionOrUtils.h>
|
||||||
|
#include <LibWeb/Crypto/CryptoBindings.h>
|
||||||
|
|
||||||
|
namespace Web::Bindings {
|
||||||
|
|
||||||
|
JS_DEFINE_ALLOCATOR(KeyAlgorithm);
|
||||||
|
|
||||||
|
JS::NonnullGCPtr<KeyAlgorithm> KeyAlgorithm::create(JS::Realm& realm)
|
||||||
|
{
|
||||||
|
return realm.heap().allocate<KeyAlgorithm>(realm, realm);
|
||||||
|
}
|
||||||
|
|
||||||
|
KeyAlgorithm::KeyAlgorithm(JS::Realm& realm)
|
||||||
|
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().object_prototype())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void KeyAlgorithm::initialize(JS::Realm& realm)
|
||||||
|
{
|
||||||
|
define_native_accessor(realm, "name", name_getter, {}, JS::Attribute::Enumerable | JS::Attribute::Configurable);
|
||||||
|
Base::initialize(realm);
|
||||||
|
}
|
||||||
|
|
||||||
|
static JS::ThrowCompletionOr<KeyAlgorithm*> impl_from(JS::VM& vm)
|
||||||
|
{
|
||||||
|
auto this_value = vm.this_value();
|
||||||
|
JS::Object* this_object = nullptr;
|
||||||
|
if (this_value.is_nullish())
|
||||||
|
this_object = &vm.current_realm()->global_object();
|
||||||
|
else
|
||||||
|
this_object = TRY(this_value.to_object(vm));
|
||||||
|
|
||||||
|
if (!is<KeyAlgorithm>(this_object))
|
||||||
|
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "KeyAlgorithm");
|
||||||
|
return static_cast<KeyAlgorithm*>(this_object);
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_DEFINE_NATIVE_FUNCTION(KeyAlgorithm::name_getter)
|
||||||
|
{
|
||||||
|
auto* impl = TRY(impl_from(vm));
|
||||||
|
auto name = TRY(throw_dom_exception_if_needed(vm, [&] { return impl->name(); }));
|
||||||
|
return JS::PrimitiveString::create(vm, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
76
Userland/Libraries/LibWeb/Crypto/CryptoBindings.h
Normal file
76
Userland/Libraries/LibWeb/Crypto/CryptoBindings.h
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023, stelar7 <dudedbz@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibWeb/WebIDL/Buffers.h>
|
||||||
|
|
||||||
|
// FIXME: Generate these from IDL
|
||||||
|
namespace Web::Bindings {
|
||||||
|
|
||||||
|
// https://w3c.github.io/webcrypto/#JsonWebKey-dictionary
|
||||||
|
struct RsaOtherPrimesInfo {
|
||||||
|
Optional<String> r;
|
||||||
|
Optional<String> d;
|
||||||
|
Optional<String> t;
|
||||||
|
};
|
||||||
|
|
||||||
|
// https://w3c.github.io/webcrypto/#JsonWebKey-dictionary
|
||||||
|
struct JsonWebKey {
|
||||||
|
Optional<String> kty;
|
||||||
|
Optional<String> use;
|
||||||
|
Optional<Vector<String>> key_ops;
|
||||||
|
Optional<String> alg;
|
||||||
|
Optional<bool> ext;
|
||||||
|
Optional<String> crv;
|
||||||
|
Optional<String> x;
|
||||||
|
Optional<String> y;
|
||||||
|
Optional<String> d;
|
||||||
|
Optional<String> n;
|
||||||
|
Optional<String> e;
|
||||||
|
Optional<String> p;
|
||||||
|
Optional<String> q;
|
||||||
|
Optional<String> dp;
|
||||||
|
Optional<String> dq;
|
||||||
|
Optional<String> qi;
|
||||||
|
Optional<Vector<RsaOtherPrimesInfo>> oth;
|
||||||
|
Optional<String> k;
|
||||||
|
};
|
||||||
|
|
||||||
|
// https://w3c.github.io/webcrypto/#dfn-Algorithm
|
||||||
|
struct Algorithm {
|
||||||
|
String name;
|
||||||
|
};
|
||||||
|
|
||||||
|
// https://w3c.github.io/webcrypto/#key-algorithm-dictionary
|
||||||
|
class KeyAlgorithm : public JS::Object {
|
||||||
|
JS_OBJECT(KeyAlgorithm, Object);
|
||||||
|
JS_DECLARE_ALLOCATOR(KeyAlgorithm);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static JS::NonnullGCPtr<KeyAlgorithm> create(JS::Realm&);
|
||||||
|
virtual ~KeyAlgorithm() override = default;
|
||||||
|
|
||||||
|
String const& name() const { return m_name; }
|
||||||
|
void set_name(String name) { m_name = move(name); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
KeyAlgorithm(JS::Realm&);
|
||||||
|
virtual void initialize(JS::Realm&) override;
|
||||||
|
|
||||||
|
JS_DECLARE_NATIVE_FUNCTION(name_getter);
|
||||||
|
|
||||||
|
String m_name;
|
||||||
|
};
|
||||||
|
|
||||||
|
// https://w3c.github.io/webcrypto/#pbkdf2-params
|
||||||
|
struct Pbkdf2Params {
|
||||||
|
JS::Handle<WebIDL::BufferSource> salt;
|
||||||
|
u32 iterations;
|
||||||
|
Variant<JS::Handle<JS::Object>, String> hash;
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
|
@ -190,7 +190,7 @@ SubtleCrypto::SupportedAlgorithmsMap& SubtleCrypto::supported_algorithms_interna
|
||||||
return s_supported_algorithms;
|
return s_supported_algorithms;
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://w3c.github.io/webcrypto/#algorithm-normalization-internal
|
// https://w3c.github.io/webcrypto/#algorithm-normalization-internalS
|
||||||
SubtleCrypto::SupportedAlgorithmsMap SubtleCrypto::supported_algorithms()
|
SubtleCrypto::SupportedAlgorithmsMap SubtleCrypto::supported_algorithms()
|
||||||
{
|
{
|
||||||
auto& internal_object = supported_algorithms_internal();
|
auto& internal_object = supported_algorithms_internal();
|
||||||
|
|
|
@ -10,15 +10,7 @@
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <LibJS/Forward.h>
|
#include <LibJS/Forward.h>
|
||||||
#include <LibWeb/Bindings/PlatformObject.h>
|
#include <LibWeb/Bindings/PlatformObject.h>
|
||||||
// FIXME: Generate these from IDL
|
#include <LibWeb/Crypto/CryptoBindings.h>
|
||||||
namespace Web::Bindings {
|
|
||||||
|
|
||||||
// https://w3c.github.io/webcrypto/#dfn-Algorithm
|
|
||||||
struct Algorithm {
|
|
||||||
String name;
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace Web::Crypto {
|
namespace Web::Crypto {
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,42 @@ dictionary Algorithm {
|
||||||
required DOMString name;
|
required DOMString name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum KeyFormat { "raw", "spki", "pkcs8", "jwk" };
|
||||||
|
|
||||||
|
dictionary RsaOtherPrimesInfo {
|
||||||
|
// The following fields are defined in Section 6.3.2.7 of JSON Web Algorithms
|
||||||
|
DOMString r;
|
||||||
|
DOMString d;
|
||||||
|
DOMString t;
|
||||||
|
};
|
||||||
|
|
||||||
|
dictionary JsonWebKey
|
||||||
|
{
|
||||||
|
// The following fields are defined in Section 3.1 of JSON Web Key
|
||||||
|
DOMString kty;
|
||||||
|
DOMString use;
|
||||||
|
sequence<DOMString> key_ops;
|
||||||
|
DOMString alg;
|
||||||
|
|
||||||
|
// The following fields are defined in JSON Web Key Parameters Registration
|
||||||
|
boolean ext;
|
||||||
|
|
||||||
|
// The following fields are defined in Section 6 of JSON Web Algorithms
|
||||||
|
DOMString crv;
|
||||||
|
DOMString x;
|
||||||
|
DOMString y;
|
||||||
|
DOMString d;
|
||||||
|
DOMString n;
|
||||||
|
DOMString e;
|
||||||
|
DOMString p;
|
||||||
|
DOMString q;
|
||||||
|
DOMString dp;
|
||||||
|
DOMString dq;
|
||||||
|
DOMString qi;
|
||||||
|
sequence<RsaOtherPrimesInfo> oth;
|
||||||
|
DOMString k;
|
||||||
|
};
|
||||||
|
|
||||||
// https://w3c.github.io/webcrypto/#subtlecrypto-interface
|
// https://w3c.github.io/webcrypto/#subtlecrypto-interface
|
||||||
[SecureContext,Exposed=(Window,Worker)]
|
[SecureContext,Exposed=(Window,Worker)]
|
||||||
interface SubtleCrypto {
|
interface SubtleCrypto {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue