mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-27 02:05:07 +02:00
LibCrypto+LibJS: Remove the create_from methods from BigInteger
Instead we just use a specific constructor. With this set of constructors using curly braces for constructing is highly recommended. As then it will not do too many implicit conversions which could lead to unexpected loss of data or calling the much slower double constructor. Also to ensure we don't feed (Un)SignedBigInteger infinities we throw RangeError earlier for Durations.
This commit is contained in:
Notes:
sideshowbarker
2024-07-17 07:42:40 +09:00
Author: https://github.com/davidot Commit: https://github.com/SerenityOS/serenity/commit/791855deab Pull-request: https://github.com/SerenityOS/serenity/pull/15029 Reviewed-by: https://github.com/linusg ✅ Reviewed-by: https://github.com/trflynn89
@@ -45,6 +45,12 @@ public:
|
||||
|
||||
explicit SignedBigInteger(double value);
|
||||
|
||||
explicit SignedBigInteger(i64 value)
|
||||
: m_sign(value < 0)
|
||||
, m_unsigned_data(value < 0 ? static_cast<u64>(-(value + 1)) + 1 : static_cast<u64>(value))
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] static SignedBigInteger create_invalid()
|
||||
{
|
||||
return { UnsignedBigInteger::create_invalid(), false };
|
||||
@@ -53,19 +59,6 @@ public:
|
||||
[[nodiscard]] static SignedBigInteger import_data(StringView data) { return import_data((u8 const*)data.characters_without_null_termination(), data.length()); }
|
||||
[[nodiscard]] static SignedBigInteger import_data(u8 const* ptr, size_t length);
|
||||
|
||||
[[nodiscard]] static SignedBigInteger create_from(i64 value)
|
||||
{
|
||||
auto sign = false;
|
||||
u64 unsigned_value;
|
||||
if (value < 0) {
|
||||
unsigned_value = static_cast<u64>(-(value + 1)) + 1;
|
||||
sign = true;
|
||||
} else {
|
||||
unsigned_value = value;
|
||||
}
|
||||
return SignedBigInteger { UnsignedBigInteger::create_from(unsigned_value), sign };
|
||||
}
|
||||
|
||||
size_t export_data(Bytes, bool remove_leading_zeros = false) const;
|
||||
|
||||
[[nodiscard]] static SignedBigInteger from_base(u16 N, StringView str);
|
||||
|
||||
Reference in New Issue
Block a user