LibCrypto: Convert UnsignedBigInteger::export_data to return a span

This helps make callers only use the slice of the output buffer that
was written to.

As part of updating the callers of the API several bugs were fixed and
useless code paths were removed:
- The exported data is not host-endianess dependent (always big endian)
- The exported data does not contain leading zeros
- The output buffer is only written up to the result's size
This commit is contained in:
Idan Horowitz 2025-08-05 02:41:11 +03:00 committed by Ali Mohammad Pur
commit 660a499223
Notes: github-actions[bot] 2025-08-05 07:10:42 +00:00
8 changed files with 45 additions and 59 deletions

View file

@ -116,9 +116,8 @@ ErrorOr<String> base64_url_uint_encode(::Crypto::UnsignedBigInteger integer)
// octet), which is "AA".
auto bytes = TRY(ByteBuffer::create_uninitialized(integer.byte_length()));
auto data_size = integer.export_data(bytes.span());
auto data_slice_be = bytes.bytes().slice(bytes.size() - data_size, data_size);
return TRY(encode_base64url(data_slice_be, AK::OmitPadding::Yes));
auto result = integer.export_data(bytes.span());
return TRY(encode_base64url(result, AK::OmitPadding::Yes));
}
WebIDL::ExceptionOr<ByteBuffer> base64_url_bytes_decode(JS::Realm& realm, String const& base64_url_string)