mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:37:43 +00:00
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.
This commit is contained in:
parent
422b624743
commit
ed9c79e131
1 changed files with 3 additions and 6 deletions
|
@ -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.
|
// 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.
|
// 8. Let result be the result of performing the digest operation specified by normalizedAlgorithm using algorithm, with data as message.
|
||||||
::Crypto::Hash::Manager hash;
|
::Crypto::Hash::Manager hash { hash_kind };
|
||||||
hash.initialize(hash_kind);
|
|
||||||
hash.update(*data_buffer);
|
hash.update(*data_buffer);
|
||||||
|
|
||||||
auto digest = hash.digest();
|
auto digest = hash.digest();
|
||||||
auto const* digest_data = digest.immutable_data();
|
auto result_buffer = ByteBuffer::copy(digest.immutable_data(), hash.digest_size());
|
||||||
auto result_buffer = ByteBuffer::create_zeroed(hash.digest_size());
|
|
||||||
if (!result_buffer.has_value()) {
|
if (!result_buffer.has_value()) {
|
||||||
auto* error = wrap(wrapper()->global_object(), DOM::OperationError::create("Failed to create result buffer"));
|
auto* error = wrap(wrapper()->global_object(), DOM::OperationError::create("Failed to create result buffer"));
|
||||||
promise->reject(error);
|
promise->reject(error);
|
||||||
return promise;
|
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());
|
auto* result = JS::ArrayBuffer::create(global_object, result_buffer.release_value());
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue