mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:58:11 +00:00
LibWeb: Refactor SubtleCrypto to allow adding more algorithms easier
This patch throws away some of the spec suggestions for how to implement the normalize_algorithm AO and uses a new pattern that we can actually extend in our C++. Also update CryptoKey to store the key data.
This commit is contained in:
parent
644e764620
commit
2d59d6c98c
9 changed files with 294 additions and 136 deletions
|
@ -1,28 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2023, stelar7 <dudedbz@gmail.com>
|
||||
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Memory.h>
|
||||
#include <LibWeb/Crypto/CryptoKey.h>
|
||||
|
||||
namespace Web::Crypto {
|
||||
|
||||
JS_DEFINE_ALLOCATOR(CryptoKey);
|
||||
|
||||
JS::NonnullGCPtr<CryptoKey> CryptoKey::create(JS::Realm& realm)
|
||||
JS::NonnullGCPtr<CryptoKey> CryptoKey::create(JS::Realm& realm, InternalKeyData key_data)
|
||||
{
|
||||
return realm.heap().allocate<CryptoKey>(realm, realm);
|
||||
return realm.heap().allocate<CryptoKey>(realm, realm, move(key_data));
|
||||
}
|
||||
|
||||
CryptoKey::CryptoKey(JS::Realm& realm)
|
||||
CryptoKey::CryptoKey(JS::Realm& realm, InternalKeyData key_data)
|
||||
: PlatformObject(realm)
|
||||
, m_algorithm(Object::create(realm, nullptr))
|
||||
, m_usages(Object::create(realm, nullptr))
|
||||
, m_key_data(move(key_data))
|
||||
{
|
||||
}
|
||||
|
||||
CryptoKey::~CryptoKey() = default;
|
||||
CryptoKey::~CryptoKey()
|
||||
{
|
||||
m_key_data.visit(
|
||||
[](ByteBuffer& data) { secure_zero(data.data(), data.size()); },
|
||||
[](auto& data) { secure_zero(reinterpret_cast<u8*>(&data), sizeof(data)); });
|
||||
}
|
||||
|
||||
void CryptoKey::initialize(JS::Realm& realm)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue