diff --git a/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp b/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp index 0f5bf42790c..35c8126b7df 100644 --- a/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp +++ b/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp @@ -1311,6 +1311,7 @@ WebIDL::ExceptionOr> AesCbc::decrypt(Algorithm return JS::ArrayBuffer::create(m_realm, move(plaintext)); } +// https://w3c.github.io/webcrypto/#aes-cbc-operations WebIDL::ExceptionOr> AesCbc::import_key(AlgorithmParams const&, Bindings::KeyFormat format, CryptoKey::InternalKeyData key_data, bool extractable, Vector const& key_usages) { // 1. If usages contains an entry which is not one of "encrypt", "decrypt", "wrapKey" or "unwrapKey", then throw a SyntaxError. @@ -2701,6 +2702,7 @@ WebIDL::ExceptionOr HKDF::get_key_length(AlgorithmParams const&) return JS::js_null(); } +// https://w3c.github.io/webcrypto/#pbkdf2-operations WebIDL::ExceptionOr> PBKDF2::derive_bits(AlgorithmParams const& params, JS::NonnullGCPtr key, Optional length_optional) { auto& realm = *m_realm; @@ -2708,7 +2710,6 @@ WebIDL::ExceptionOr> PBKDF2::derive_bits(Algor // 1. If length is null or zero, or is not a multiple of 8, then throw an OperationError. auto length = length_optional.value_or(0); - if (length == 0 || length % 8 != 0) return WebIDL::OperationError::create(realm, "Length must be greater than 0 and divisible by 8"_string); @@ -2753,24 +2754,24 @@ WebIDL::ExceptionOr> PBKDF2::derive_bits(Algor return JS::ArrayBuffer::create(realm, result.release_value()); } +// https://w3c.github.io/webcrypto/#pbkdf2-operations WebIDL::ExceptionOr PBKDF2::get_key_length(AlgorithmParams const&) { // 1. Return null. return JS::js_null(); } +// https://w3c.github.io/webcrypto/#pbkdf2-operations WebIDL::ExceptionOr> PBKDF2::import_key(AlgorithmParams const&, Bindings::KeyFormat format, CryptoKey::InternalKeyData key_data, bool extractable, Vector const& key_usages) { // 1. If format is not "raw", throw a NotSupportedError - if (format != Bindings::KeyFormat::Raw) { + if (format != Bindings::KeyFormat::Raw) return WebIDL::NotSupportedError::create(m_realm, "Only raw format is supported"_string); - } // 2. If usages contains a value that is not "deriveKey" or "deriveBits", then throw a SyntaxError. for (auto& usage : key_usages) { - if (usage != Bindings::KeyUsage::Derivekey && usage != Bindings::KeyUsage::Derivebits) { + if (usage != Bindings::KeyUsage::Derivekey && usage != Bindings::KeyUsage::Derivebits) return WebIDL::SyntaxError::create(m_realm, MUST(String::formatted("Invalid key usage '{}'", idl_enum_to_string(usage)))); - } } // 3. If extractable is not false, then throw a SyntaxError. diff --git a/Libraries/LibWeb/Crypto/SubtleCrypto.cpp b/Libraries/LibWeb/Crypto/SubtleCrypto.cpp index e99bad25d6e..6eb0cabeda3 100644 --- a/Libraries/LibWeb/Crypto/SubtleCrypto.cpp +++ b/Libraries/LibWeb/Crypto/SubtleCrypto.cpp @@ -632,6 +632,7 @@ JS::ThrowCompletionOr> SubtleCrypto::derive_bi return promise; } +// https://w3c.github.io/webcrypto/#SubtleCrypto-method-deriveKey JS::ThrowCompletionOr> SubtleCrypto::derive_key(AlgorithmIdentifier algorithm, JS::NonnullGCPtr base_key, AlgorithmIdentifier derived_key_type, bool extractable, Vector key_usages) { auto& realm = this->realm();