mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-27 10:07:15 +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
@@ -41,6 +41,14 @@ public:
|
||||
|
||||
explicit UnsignedBigInteger(double value);
|
||||
|
||||
explicit UnsignedBigInteger(u64 value)
|
||||
{
|
||||
static_assert(sizeof(u64) == sizeof(Word) * 2);
|
||||
m_words.resize_and_keep_capacity(2);
|
||||
m_words[0] = static_cast<Word>(value & 0xFFFFFFFF);
|
||||
m_words[1] = static_cast<Word>((value >> 32) & 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
UnsignedBigInteger() = default;
|
||||
|
||||
[[nodiscard]] static UnsignedBigInteger create_invalid();
|
||||
@@ -51,16 +59,6 @@ public:
|
||||
return UnsignedBigInteger(ptr, length);
|
||||
}
|
||||
|
||||
[[nodiscard]] static UnsignedBigInteger create_from(u64 value)
|
||||
{
|
||||
VERIFY(sizeof(Word) == 4);
|
||||
UnsignedBigInteger integer;
|
||||
integer.m_words.resize(2);
|
||||
integer.m_words[0] = static_cast<Word>(value & 0xFFFFFFFF);
|
||||
integer.m_words[1] = static_cast<Word>((value >> 32) & 0xFFFFFFFF);
|
||||
return integer;
|
||||
}
|
||||
|
||||
size_t export_data(Bytes, bool remove_leading_zeros = false) const;
|
||||
|
||||
[[nodiscard]] static UnsignedBigInteger from_base(u16 N, StringView str);
|
||||
|
||||
Reference in New Issue
Block a user