mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:57:45 +00: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:
parent
0b0c7693e2
commit
48a3a02238
11 changed files with 68 additions and 57 deletions
|
@ -14,7 +14,7 @@ namespace Crypto {
|
|||
class BigFraction {
|
||||
// FIXME Make the whole API more error-friendly. This includes:
|
||||
// - Propagating errors from BigIntegers
|
||||
// - Returns errors from both BigFraction(StringView) and BigFraction(numerator, denominator);
|
||||
// - Returns errors from BigFraction(numerator, denominator);
|
||||
// - Duplicate fallible operators with a error-friendly version
|
||||
|
||||
public:
|
||||
|
@ -27,9 +27,10 @@ public:
|
|||
BigFraction& operator=(Crypto::BigFraction const&) = default;
|
||||
BigFraction& operator=(Crypto::BigFraction&&) = default;
|
||||
|
||||
explicit BigFraction(StringView);
|
||||
explicit BigFraction(double);
|
||||
|
||||
static ErrorOr<BigFraction> from_string(StringView);
|
||||
|
||||
BigFraction operator+(BigFraction const&) const;
|
||||
BigFraction operator-(BigFraction const&) const;
|
||||
BigFraction operator*(BigFraction const&) const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue