LibCrypto: Convert SignedBigInteger::import_data to accept Bytes

This brings it up to par with UnsignedBigInteger.
This commit is contained in:
Idan Horowitz 2025-08-05 03:04:32 +03:00 committed by Ali Mohammad Pur
parent b0fdbe3756
commit 110136b862
Notes: github-actions[bot] 2025-08-05 07:10:20 +00:00
3 changed files with 5 additions and 6 deletions

View file

@ -23,10 +23,10 @@ SignedBigInteger::SignedBigInteger(UnsignedBigInteger&& unsigned_data, bool sign
} }
} }
SignedBigInteger::SignedBigInteger(u8 const* ptr, size_t length) SignedBigInteger::SignedBigInteger(ReadonlyBytes data)
{ {
MP_MUST(mp_init(&m_mp)); MP_MUST(mp_init(&m_mp));
MP_MUST(mp_from_sbin(&m_mp, ptr, length)); MP_MUST(mp_from_sbin(&m_mp, data.data(), data.size()));
} }
SignedBigInteger::SignedBigInteger(UnsignedBigInteger const& unsigned_data) SignedBigInteger::SignedBigInteger(UnsignedBigInteger const& unsigned_data)

View file

@ -22,7 +22,7 @@ public:
{ {
} }
SignedBigInteger(UnsignedBigInteger&& unsigned_data, bool sign); SignedBigInteger(UnsignedBigInteger&& unsigned_data, bool sign);
SignedBigInteger(u8 const* ptr, size_t length); SignedBigInteger(ReadonlyBytes);
explicit SignedBigInteger(UnsignedBigInteger const& unsigned_data); explicit SignedBigInteger(UnsignedBigInteger const& unsigned_data);
explicit SignedBigInteger(double value); explicit SignedBigInteger(double value);
@ -37,8 +37,7 @@ public:
SignedBigInteger(); SignedBigInteger();
~SignedBigInteger(); ~SignedBigInteger();
[[nodiscard]] static SignedBigInteger import_data(StringView data) { return import_data(reinterpret_cast<u8 const*>(data.characters_without_null_termination()), data.length()); } [[nodiscard]] static SignedBigInteger import_data(ReadonlyBytes data) { return SignedBigInteger(data); }
[[nodiscard]] static SignedBigInteger import_data(u8 const* ptr, size_t length) { return SignedBigInteger(ptr, length); }
[[nodiscard]] Bytes export_data(Bytes) const; [[nodiscard]] Bytes export_data(Bytes) const;

View file

@ -310,7 +310,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyModule::get_export)
return JS::Value(global->value().to<double>()); return JS::Value(global->value().to<double>());
case Wasm::ValueType::V128: { case Wasm::ValueType::V128: {
auto value = global->value().to<u128>(); auto value = global->value().to<u128>();
return JS::BigInt::create(vm, Crypto::SignedBigInteger::import_data(bit_cast<u8 const*>(&value), sizeof(u128))); return JS::BigInt::create(vm, Crypto::SignedBigInteger::import_data(value.bytes()));
} }
case Wasm::ValueType::FunctionReference: case Wasm::ValueType::FunctionReference:
case Wasm::ValueType::ExternReference: case Wasm::ValueType::ExternReference: