LibWeb: Implement Web Crypto HMAC algorithm

This commit is contained in:
Jelle Raaijmakers 2024-11-13 15:23:50 +01:00 committed by Andreas Kling
commit 329cd946ac
Notes: github-actions[bot] 2024-11-14 10:53:12 +00:00
10 changed files with 1064 additions and 13 deletions

View file

@ -1,6 +1,7 @@
/*
* Copyright (c) 2023, stelar7 <dudedbz@gmail.com>
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
* Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -145,4 +146,34 @@ private:
u16 m_length;
};
// https://w3c.github.io/webcrypto/#HmacKeyAlgorithm-dictionary
struct HmacKeyAlgorithm : public KeyAlgorithm {
JS_OBJECT(HmacKeyAlgorithm, KeyAlgorithm);
JS_DECLARE_ALLOCATOR(HmacKeyAlgorithm);
public:
static JS::NonnullGCPtr<HmacKeyAlgorithm> create(JS::Realm&);
virtual ~HmacKeyAlgorithm() override = default;
JS::GCPtr<KeyAlgorithm> hash() const { return m_hash; }
void set_hash(JS::GCPtr<KeyAlgorithm> hash) { m_hash = hash; }
WebIDL::UnsignedLong length() const { return m_length; }
void set_length(WebIDL::UnsignedLong length) { m_length = length; }
protected:
HmacKeyAlgorithm(JS::Realm&);
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Visitor&) override;
private:
JS_DECLARE_NATIVE_FUNCTION(hash_getter);
JS_DECLARE_NATIVE_FUNCTION(length_getter);
JS::GCPtr<KeyAlgorithm> m_hash;
WebIDL::UnsignedLong m_length;
};
}