mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 23:27:35 +00:00
LibWeb: Use AlgorithmIdentifier
in SubtleCrypto IDL
This commit is contained in:
parent
d94543f964
commit
635ad9e9b8
3 changed files with 19 additions and 6 deletions
|
@ -36,7 +36,7 @@ void SubtleCrypto::initialize(JS::Realm& realm)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://w3c.github.io/webcrypto/#dfn-SubtleCrypto-method-digest
|
// https://w3c.github.io/webcrypto/#dfn-SubtleCrypto-method-digest
|
||||||
JS::NonnullGCPtr<JS::Promise> SubtleCrypto::digest(String const& algorithm, JS::Handle<WebIDL::BufferSource> const& data)
|
JS::NonnullGCPtr<JS::Promise> SubtleCrypto::digest(Variant<JS::Handle<JS::Object>, String> const& algorithm, JS::Handle<WebIDL::BufferSource> const& data)
|
||||||
{
|
{
|
||||||
auto& realm = this->realm();
|
auto& realm = this->realm();
|
||||||
|
|
||||||
|
@ -54,8 +54,16 @@ JS::NonnullGCPtr<JS::Promise> SubtleCrypto::digest(String const& algorithm, JS::
|
||||||
|
|
||||||
// 3. Let normalizedAlgorithm be the result of normalizing an algorithm, with alg set to algorithm and op set to "digest".
|
// 3. Let normalizedAlgorithm be the result of normalizing an algorithm, with alg set to algorithm and op set to "digest".
|
||||||
// FIXME: This is way more generic than it needs to be right now, so we simplify it.
|
// FIXME: This is way more generic than it needs to be right now, so we simplify it.
|
||||||
|
if (!algorithm.has<String>()) {
|
||||||
|
auto promise = JS::Promise::create(realm);
|
||||||
|
auto error = WebIDL::OperationError::create(realm, "LibJS does not support non-string parameters to digest()"_fly_string);
|
||||||
|
promise->reject(error.ptr());
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
|
||||||
::Crypto::Hash::HashKind hash_kind;
|
::Crypto::Hash::HashKind hash_kind;
|
||||||
auto algorithm_as_string_view = algorithm.bytes_as_string_view();
|
auto algorithm_name = algorithm.get<String>();
|
||||||
|
auto algorithm_as_string_view = algorithm_name.bytes_as_string_view();
|
||||||
if (algorithm_as_string_view.equals_ignoring_ascii_case("SHA-1"sv)) {
|
if (algorithm_as_string_view.equals_ignoring_ascii_case("SHA-1"sv)) {
|
||||||
hash_kind = ::Crypto::Hash::HashKind::SHA1;
|
hash_kind = ::Crypto::Hash::HashKind::SHA1;
|
||||||
} else if (algorithm_as_string_view.equals_ignoring_ascii_case("SHA-256"sv)) {
|
} else if (algorithm_as_string_view.equals_ignoring_ascii_case("SHA-256"sv)) {
|
||||||
|
@ -67,7 +75,7 @@ JS::NonnullGCPtr<JS::Promise> SubtleCrypto::digest(String const& algorithm, JS::
|
||||||
}
|
}
|
||||||
// 4. If an error occurred, return a Promise rejected with normalizedAlgorithm.
|
// 4. If an error occurred, return a Promise rejected with normalizedAlgorithm.
|
||||||
else {
|
else {
|
||||||
auto error = WebIDL::NotSupportedError::create(realm, MUST(String::formatted("Invalid hash function '{}'", algorithm)));
|
auto error = WebIDL::NotSupportedError::create(realm, MUST(String::formatted("Invalid hash function '{}'", algorithm_name)));
|
||||||
auto promise = JS::Promise::create(realm);
|
auto promise = JS::Promise::create(realm);
|
||||||
promise->reject(error.ptr());
|
promise->reject(error.ptr());
|
||||||
return promise;
|
return promise;
|
||||||
|
|
|
@ -20,7 +20,7 @@ public:
|
||||||
|
|
||||||
virtual ~SubtleCrypto() override;
|
virtual ~SubtleCrypto() override;
|
||||||
|
|
||||||
JS::NonnullGCPtr<JS::Promise> digest(String const& algorithm, JS::Handle<WebIDL::BufferSource> const& data);
|
JS::NonnullGCPtr<JS::Promise> digest(Variant<JS::Handle<JS::Object>, String> const& algorithm, JS::Handle<WebIDL::BufferSource> const& data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit SubtleCrypto(JS::Realm&);
|
explicit SubtleCrypto(JS::Realm&);
|
||||||
|
|
|
@ -1,3 +1,9 @@
|
||||||
|
typedef (object or DOMString) AlgorithmIdentifier;
|
||||||
|
|
||||||
|
dictionary Algorithm {
|
||||||
|
required DOMString name;
|
||||||
|
};
|
||||||
|
|
||||||
// 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 {
|
||||||
|
@ -6,8 +12,7 @@ interface SubtleCrypto {
|
||||||
// FIXME: Promise<any> sign(AlgorithmIdentifier algorithm, CryptoKey key, BufferSource data);
|
// FIXME: Promise<any> sign(AlgorithmIdentifier algorithm, CryptoKey key, BufferSource data);
|
||||||
// FIXME: Promise<any> verify(AlgorithmIdentifier algorithm, CryptoKey key, BufferSource signature, BufferSource data);
|
// FIXME: Promise<any> verify(AlgorithmIdentifier algorithm, CryptoKey key, BufferSource signature, BufferSource data);
|
||||||
|
|
||||||
// FIXME: Add support for AlgorithmIdentifier ("typedef (object or DOMString)")
|
Promise<any> digest(AlgorithmIdentifier algorithm, BufferSource data);
|
||||||
Promise<any> digest(DOMString algorithm, BufferSource data);
|
|
||||||
|
|
||||||
// FIXME: Promise<any> generateKey(AlgorithmIdentifier algorithm, boolean extractable, sequence<KeyUsage> keyUsages);
|
// FIXME: Promise<any> generateKey(AlgorithmIdentifier algorithm, boolean extractable, sequence<KeyUsage> keyUsages);
|
||||||
// FIXME: Promise<any> deriveKey(AlgorithmIdentifier algorithm, CryptoKey baseKey, AlgorithmIdentifier derivedKeyType, boolean extractable, sequence<KeyUsage> keyUsages );
|
// FIXME: Promise<any> deriveKey(AlgorithmIdentifier algorithm, CryptoKey baseKey, AlgorithmIdentifier derivedKeyType, boolean extractable, sequence<KeyUsage> keyUsages );
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue