mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-08 10:01:53 +00:00
LibCrypto: Remove the concept of invalid big integers
This concept is rarely used in codebase and very much error-prone if you forget to check it. Instead, make it so that operations that would produce invalid integers return an error instead.
This commit is contained in:
parent
14387e5411
commit
5f1a30197c
Notes:
github-actions[bot]
2025-04-28 10:06:55 +00:00
Author: https://github.com/devgianlu
Commit: 5f1a30197c
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4482
Reviewed-by: https://github.com/gmta ✅
12 changed files with 34 additions and 109 deletions
|
@ -73,14 +73,13 @@ void UnsignedBigIntegerAlgorithms::add_into_accumulator_without_allocation(Unsig
|
|||
/**
|
||||
* Complexity: O(N) where N is the number of words in the larger number
|
||||
*/
|
||||
void UnsignedBigIntegerAlgorithms::subtract_without_allocation(
|
||||
ErrorOr<void> UnsignedBigIntegerAlgorithms::subtract_without_allocation(
|
||||
UnsignedBigInteger const& left,
|
||||
UnsignedBigInteger const& right,
|
||||
UnsignedBigInteger& output)
|
||||
{
|
||||
if (left < right) {
|
||||
output.invalidate();
|
||||
return;
|
||||
return Error::from_string_literal("Invalid subtraction: left < right");
|
||||
}
|
||||
|
||||
u8 borrow = 0;
|
||||
|
@ -103,6 +102,8 @@ void UnsignedBigIntegerAlgorithms::subtract_without_allocation(
|
|||
|
||||
// This assertion should not fail, because we verified that *this>=other at the beginning of the function
|
||||
VERIFY(borrow == 0);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue