mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 20:25:07 +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
|
@ -936,7 +936,8 @@ private:
|
|||
auto string_view = TRY(Bindings::throw_dom_exception_if_needed(vm, [&string]() {
|
||||
return string->utf8_string_view();
|
||||
}));
|
||||
return JS::BigInt::create(vm, ::Crypto::SignedBigInteger::from_base(10, string_view.substring_view(0, string_view.length() - 1)));
|
||||
auto bigint = MUST(::Crypto::SignedBigInteger::from_base(10, string_view.substring_view(0, string_view.length() - 1)));
|
||||
return JS::BigInt::create(vm, bigint);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue