mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-02 04:27:12 +02:00
LibCrypto: Make constructing a BigInteger from string fallible
Previously, constructing a `UnsignedBigInteger::from_base()` could produce an incorrect result if the input string contained a valid Base36 digit that was out of range of the given base. The same method would also crash if the input string contained an invalid Base36 digit. An error is now returned in both these cases. Constructing a BigFraction from string is now also fallible, so that we can handle the case where we are given an input string with invalid digits.
This commit is contained in:
committed by
Andrew Kaster
parent
0b0c7693e2
commit
48a3a02238
Notes:
sideshowbarker
2024-07-17 05:18:58 +09:00
Author: https://github.com/tcl3 Commit: https://github.com/SerenityOS/serenity/commit/48a3a02238 Pull-request: https://github.com/SerenityOS/serenity/pull/22726 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/LucasChollet ✅
@@ -35,7 +35,7 @@ size_t SignedBigInteger::export_data(Bytes data, bool remove_leading_zeros) cons
|
||||
return m_unsigned_data.export_data(bytes_view, remove_leading_zeros) + 1;
|
||||
}
|
||||
|
||||
SignedBigInteger SignedBigInteger::from_base(u16 N, StringView str)
|
||||
ErrorOr<SignedBigInteger> SignedBigInteger::from_base(u16 N, StringView str)
|
||||
{
|
||||
auto sign = false;
|
||||
if (str.length() > 1) {
|
||||
@@ -47,8 +47,8 @@ SignedBigInteger SignedBigInteger::from_base(u16 N, StringView str)
|
||||
if (maybe_sign == '+')
|
||||
str = str.substring_view(1);
|
||||
}
|
||||
auto unsigned_data = UnsignedBigInteger::from_base(N, str);
|
||||
return { move(unsigned_data), sign };
|
||||
auto unsigned_data = TRY(UnsignedBigInteger::from_base(N, str));
|
||||
return SignedBigInteger { move(unsigned_data), sign };
|
||||
}
|
||||
|
||||
ErrorOr<String> SignedBigInteger::to_base(u16 N) const
|
||||
|
||||
Reference in New Issue
Block a user