mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-05 09:52:54 +00:00
LibWeb: Export UnsignedBigInts into Uint8Arrays without losing bytes
The behavior of Crypto::UnsignedBigInt::export_data unexpectedly does not actually remove leading zero bytes when the corresponding parameter is passed. The caller must manually adjust for the location of the zero bytes.
This commit is contained in:
parent
0a3d27c41d
commit
2599142214
Notes:
sideshowbarker
2024-07-17 05:23:40 +09:00
Author: https://github.com/ADKaster
Commit: 2599142214
Pull-request: https://github.com/SerenityOS/serenity/pull/23579
2 changed files with 6 additions and 5 deletions
|
@ -90,15 +90,16 @@ WebIDL::ExceptionOr<void> RsaKeyAlgorithm::set_public_exponent(::Crypto::Unsigne
|
|||
|
||||
auto bytes = TRY_OR_THROW_OOM(vm, ByteBuffer::create_uninitialized(exponent.trimmed_byte_length()));
|
||||
|
||||
bool const strip_leading_zeroes = true;
|
||||
auto data_size = exponent.export_data(bytes.span(), strip_leading_zeroes);
|
||||
bool const remove_leading_zeroes = true;
|
||||
auto data_size = exponent.export_data(bytes.span(), remove_leading_zeroes);
|
||||
auto data_slice = bytes.bytes().slice(bytes.size() - data_size, data_size);
|
||||
|
||||
// The BigInteger typedef from the WebCrypto spec requires the bytes in the Uint8Array be ordered in Big Endian
|
||||
|
||||
Vector<u8, 32> byte_swapped_data;
|
||||
byte_swapped_data.ensure_capacity(data_size);
|
||||
for (size_t i = 0; i < data_size; ++i)
|
||||
byte_swapped_data.append(bytes[data_size - i - 1]);
|
||||
byte_swapped_data.append(data_slice[data_size - i - 1]);
|
||||
|
||||
m_public_exponent = TRY(JS::Uint8Array::create(realm, byte_swapped_data.size()));
|
||||
m_public_exponent->viewed_array_buffer()->buffer().overwrite(0, byte_swapped_data.data(), byte_swapped_data.size());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue