mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-02 16:33:13 +00:00
LibWeb: Implement and test SubtleCrypto interface for HKDF operations
This fixes several hundred if not thousands of WPT tests: https://wpt.live/WebCryptoAPI/derive_bits_keys/hkdf.https.any.html?1-1000
This commit is contained in:
parent
6072ae5bae
commit
f670c68ded
Notes:
github-actions[bot]
2024-10-23 18:21:54 +00:00
Author: https://github.com/BenWiederhake
Commit: f670c68ded
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1877
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/alimpfard ✅
Reviewed-by: https://github.com/stelar7
3 changed files with 167 additions and 0 deletions
|
@ -37,6 +37,24 @@ struct AlgorithmParams {
|
|||
static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value);
|
||||
};
|
||||
|
||||
// https://w3c.github.io/webcrypto/#hkdf-params
|
||||
struct HKDFParams : public AlgorithmParams {
|
||||
virtual ~HKDFParams() override;
|
||||
HKDFParams(String name, HashAlgorithmIdentifier hash, ByteBuffer salt, ByteBuffer info)
|
||||
: AlgorithmParams(move(name))
|
||||
, hash(move(hash))
|
||||
, salt(move(salt))
|
||||
, info(move(info))
|
||||
{
|
||||
}
|
||||
|
||||
HashAlgorithmIdentifier hash;
|
||||
ByteBuffer salt;
|
||||
ByteBuffer info;
|
||||
|
||||
static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value);
|
||||
};
|
||||
|
||||
// https://w3c.github.io/webcrypto/#pbkdf2-params
|
||||
struct PBKDF2Params : public AlgorithmParams {
|
||||
virtual ~PBKDF2Params() override;
|
||||
|
@ -232,6 +250,21 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
class HKDF : public AlgorithmMethods {
|
||||
public:
|
||||
virtual WebIDL::ExceptionOr<JS::NonnullGCPtr<CryptoKey>> import_key(AlgorithmParams const&, Bindings::KeyFormat, CryptoKey::InternalKeyData, bool, Vector<Bindings::KeyUsage> const&) override;
|
||||
virtual WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::ArrayBuffer>> derive_bits(AlgorithmParams const&, JS::NonnullGCPtr<CryptoKey>, Optional<u32>) override;
|
||||
virtual WebIDL::ExceptionOr<JS::Value> get_key_length(AlgorithmParams const&) override;
|
||||
|
||||
static NonnullOwnPtr<AlgorithmMethods> create(JS::Realm& realm) { return adopt_own(*new HKDF(realm)); }
|
||||
|
||||
private:
|
||||
explicit HKDF(JS::Realm& realm)
|
||||
: AlgorithmMethods(realm)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class PBKDF2 : public AlgorithmMethods {
|
||||
public:
|
||||
virtual WebIDL::ExceptionOr<JS::NonnullGCPtr<CryptoKey>> import_key(AlgorithmParams const&, Bindings::KeyFormat, CryptoKey::InternalKeyData, bool, Vector<Bindings::KeyUsage> const&) override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue