summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Crypto
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-12-15 16:06:07 +0330
committerLinus Groh <mail@linusgroh.de>2021-12-15 12:54:34 +0000
commited9c79e131769d060f7538664eb301d41446a3e1 (patch)
treef398c8dd468404893909ef6d5d2bf3fc98b7b067 /Userland/Libraries/LibWeb/Crypto
parent422b6247432604015e4ad415e768d987218fc712 (diff)
downloadserenity-ed9c79e131769d060f7538664eb301d41446a3e1.zip
LibWeb: Use ByteBuffer::copy() instead of a manual copy in SubtleCrypto
Also use the HashManager(HashKind) constructor instead of the default constructor + manual initialize() call.
Diffstat (limited to 'Userland/Libraries/LibWeb/Crypto')
-rw-r--r--Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp9
1 files changed, 3 insertions, 6 deletions
diff --git a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp
index a77ac50bce..8835b701dc 100644
--- a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp
+++ b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp
@@ -59,19 +59,16 @@ JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handle<JS::Object
// 7. If the following steps or referenced procedures say to throw an error, reject promise with the returned error and then terminate the algorithm.
// 8. Let result be the result of performing the digest operation specified by normalizedAlgorithm using algorithm, with data as message.
- ::Crypto::Hash::Manager hash;
- hash.initialize(hash_kind);
+ ::Crypto::Hash::Manager hash { hash_kind };
hash.update(*data_buffer);
+
auto digest = hash.digest();
- auto const* digest_data = digest.immutable_data();
- auto result_buffer = ByteBuffer::create_zeroed(hash.digest_size());
+ auto result_buffer = ByteBuffer::copy(digest.immutable_data(), hash.digest_size());
if (!result_buffer.has_value()) {
auto* error = wrap(wrapper()->global_object(), DOM::OperationError::create("Failed to create result buffer"));
promise->reject(error);
return promise;
}
- for (size_t i = 0; i < hash.digest_size(); ++i)
- (*result_buffer)[i] = digest_data[i];
auto* result = JS::ArrayBuffer::create(global_object, result_buffer.release_value());