Sfoglia il codice sorgente

LibCrypto+Everywhere: Rename *BigInteger::to_base to to_base_deprecated

Timothy Flynn 2 anni fa
parent
commit
0ddc2e1f50

+ 3 - 3
Tests/LibCrypto/TestBigInteger.cpp

@@ -243,7 +243,7 @@ TEST_CASE(test_unsigned_bigint_base10_to_string)
 {
     auto result = Crypto::UnsignedBigInteger {
         Vector<u32> { 3806301393, 954919431, 3879607298, 721 }
-    }.to_base(10);
+    }.to_base_deprecated(10);
     EXPECT_EQ(result, "57195071295721390579057195715793");
 }
 
@@ -386,10 +386,10 @@ TEST_CASE(test_bigint_random_distribution)
         "100000000000000000000000000000"_bigint);         // 10**29
     if (actual_result < "100000000000000000000"_bigint) { // 10**20
         FAIL("Too small");
-        outln("The generated number {} is extremely small. This *can* happen by pure chance, but should happen only once in a billion times. So it's probably an error.", actual_result.to_base(10));
+        outln("The generated number {} is extremely small. This *can* happen by pure chance, but should happen only once in a billion times. So it's probably an error.", actual_result.to_base_deprecated(10));
     } else if ("99999999900000000000000000000"_bigint < actual_result) { // 10**29 - 10**20
         FAIL("Too large");
-        outln("The generated number {} is extremely large. This *can* happen by pure chance, but should happen only once in a billion times. So it's probably an error.", actual_result.to_base(10));
+        outln("The generated number {} is extremely large. This *can* happen by pure chance, but should happen only once in a billion times. So it's probably an error.", actual_result.to_base_deprecated(10));
     }
 }
 

+ 2 - 2
Userland/Applications/Calculator/Keypad.cpp

@@ -118,8 +118,8 @@ DeprecatedString Keypad::to_deprecated_string() const
 
     StringBuilder builder;
 
-    DeprecatedString const integer_value = m_int_value.to_base(10);
-    DeprecatedString const frac_value = m_frac_value.to_base(10);
+    DeprecatedString const integer_value = m_int_value.to_base_deprecated(10);
+    DeprecatedString const frac_value = m_frac_value.to_base_deprecated(10);
     unsigned const number_pre_zeros = m_frac_length.to_u64() - (frac_value.length() - 1) - (frac_value == "0" ? 0 : 1);
 
     builder.append(integer_value);

+ 1 - 1
Userland/Libraries/LibCrypto/BigFraction/BigFraction.cpp

@@ -203,7 +203,7 @@ DeprecatedString BigFraction::to_deprecated_string(unsigned rounding_threshold)
     auto const rounded_fraction = rounded(rounding_threshold);
 
     // We take the unsigned value as we already manage the '-'
-    auto const full_value = rounded_fraction.m_numerator.unsigned_value().to_base(10);
+    auto const full_value = rounded_fraction.m_numerator.unsigned_value().to_base_deprecated(10);
     int split = full_value.length() - (number_of_digits(rounded_fraction.m_denominator) - 1);
 
     if (split < 0)

+ 2 - 2
Userland/Libraries/LibCrypto/BigInt/SignedBigInteger.cpp

@@ -51,14 +51,14 @@ SignedBigInteger SignedBigInteger::from_base(u16 N, StringView str)
     return { move(unsigned_data), sign };
 }
 
-DeprecatedString SignedBigInteger::to_base(u16 N) const
+DeprecatedString SignedBigInteger::to_base_deprecated(u16 N) const
 {
     StringBuilder builder;
 
     if (m_sign)
         builder.append('-');
 
-    builder.append(m_unsigned_data.to_base(N));
+    builder.append(m_unsigned_data.to_base_deprecated(N));
 
     return builder.to_deprecated_string();
 }

+ 1 - 1
Userland/Libraries/LibCrypto/BigInt/SignedBigInteger.h

@@ -63,7 +63,7 @@ public:
     size_t export_data(Bytes, bool remove_leading_zeros = false) const;
 
     [[nodiscard]] static SignedBigInteger from_base(u16 N, StringView str);
-    [[nodiscard]] DeprecatedString to_base(u16 N) const;
+    [[nodiscard]] DeprecatedString to_base_deprecated(u16 N) const;
 
     [[nodiscard]] u64 to_u64() const;
     [[nodiscard]] double to_double(UnsignedBigInteger::RoundingMode rounding_mode = UnsignedBigInteger::RoundingMode::IEEERoundAndTiesToEvenMantissa) const;

+ 1 - 1
Userland/Libraries/LibCrypto/BigInt/UnsignedBigInteger.cpp

@@ -146,7 +146,7 @@ UnsignedBigInteger UnsignedBigInteger::from_base(u16 N, StringView str)
     return result;
 }
 
-DeprecatedString UnsignedBigInteger::to_base(u16 N) const
+DeprecatedString UnsignedBigInteger::to_base_deprecated(u16 N) const
 {
     VERIFY(N <= 36);
     if (*this == UnsignedBigInteger { 0 })

+ 1 - 1
Userland/Libraries/LibCrypto/BigInt/UnsignedBigInteger.h

@@ -63,7 +63,7 @@ public:
     size_t export_data(Bytes, bool remove_leading_zeros = false) const;
 
     [[nodiscard]] static UnsignedBigInteger from_base(u16 N, StringView str);
-    [[nodiscard]] DeprecatedString to_base(u16 N) const;
+    [[nodiscard]] DeprecatedString to_base_deprecated(u16 N) const;
 
     [[nodiscard]] u64 to_u64() const;
 

+ 1 - 1
Userland/Libraries/LibJS/Bytecode/Op.cpp

@@ -1065,7 +1065,7 @@ DeprecatedString Store::to_deprecated_string_impl(Bytecode::Executable const&) c
 
 DeprecatedString NewBigInt::to_deprecated_string_impl(Bytecode::Executable const&) const
 {
-    return DeprecatedString::formatted("NewBigInt \"{}\"", m_bigint.to_base(10));
+    return DeprecatedString::formatted("NewBigInt \"{}\"", m_bigint.to_base_deprecated(10));
 }
 
 DeprecatedString NewArray::to_deprecated_string_impl(Bytecode::Executable const&) const

+ 1 - 1
Userland/Libraries/LibJS/Runtime/BigInt.h

@@ -21,7 +21,7 @@ public:
     virtual ~BigInt() override = default;
 
     Crypto::SignedBigInteger const& big_integer() const { return m_big_integer; }
-    const DeprecatedString to_deprecated_string() const { return DeprecatedString::formatted("{}n", m_big_integer.to_base(10)); }
+    const DeprecatedString to_deprecated_string() const { return DeprecatedString::formatted("{}n", m_big_integer.to_base_deprecated(10)); }
 
 private:
     explicit BigInt(Crypto::SignedBigInteger);

+ 1 - 1
Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp

@@ -55,7 +55,7 @@ JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::to_string)
         if (radix < 2 || radix > 36)
             return vm.throw_completion<RangeError>(ErrorType::InvalidRadix);
     }
-    return PrimitiveString::create(vm, bigint->big_integer().to_base(radix));
+    return PrimitiveString::create(vm, bigint->big_integer().to_base_deprecated(radix));
 }
 
 // 21.2.3.2 BigInt.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ), https://tc39.es/ecma262/#sec-bigint.prototype.tolocalestring

+ 1 - 1
Userland/Libraries/LibJS/Runtime/Date.cpp

@@ -305,7 +305,7 @@ static i64 clip_bigint_to_sane_time(Crypto::SignedBigInteger const& value)
         return NumericLimits<i64>::max();
 
     // FIXME: Can we do this without string conversion?
-    return value.to_base(10).to_int<i64>().value();
+    return value.to_base_deprecated(10).to_int<i64>().value();
 }
 
 // 21.4.1.8 GetNamedTimeZoneEpochNanoseconds ( timeZoneIdentifier, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond ), https://tc39.es/ecma262/#sec-getnamedtimezoneepochnanoseconds

+ 2 - 2
Userland/Libraries/LibJS/Runtime/Intl/MathematicalValue.cpp

@@ -237,7 +237,7 @@ int MathematicalValue::logarithmic_floor() const
         },
         [](Crypto::SignedBigInteger const& value) {
             // FIXME: Can we do this without string conversion?
-            return static_cast<int>(value.to_base(10).length() - 1);
+            return static_cast<int>(value.to_base_deprecated(10).length() - 1);
         },
         [](auto) -> int { VERIFY_NOT_REACHED(); });
 }
@@ -297,7 +297,7 @@ DeprecatedString MathematicalValue::to_deprecated_string() const
 {
     return m_value.visit(
         [](double value) { return number_to_string(value, NumberToStringMode::WithoutExponent); },
-        [](Crypto::SignedBigInteger const& value) { return value.to_base(10); },
+        [](Crypto::SignedBigInteger const& value) { return value.to_base_deprecated(10); },
         [](auto) -> DeprecatedString { VERIFY_NOT_REACHED(); });
 }
 

+ 2 - 2
Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp

@@ -67,7 +67,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::epoch_seconds_getter)
     auto [s, _] = ns.big_integer().divided_by(Crypto::UnsignedBigInteger { 1'000'000'000 });
 
     // 5. Return 𝔽(s).
-    return Value((double)s.to_base(10).to_int<i64>().value());
+    return Value((double)s.to_base_deprecated(10).to_int<i64>().value());
 }
 
 // 8.3.4 get Temporal.Instant.prototype.epochMilliseconds, https://tc39.es/proposal-temporal/#sec-get-temporal.instant.prototype.epochmilliseconds
@@ -84,7 +84,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::epoch_milliseconds_getter)
     auto [ms, _] = ns.big_integer().divided_by(Crypto::UnsignedBigInteger { 1'000'000 });
 
     // 5. Return 𝔽(ms).
-    return Value((double)ms.to_base(10).to_int<i64>().value());
+    return Value((double)ms.to_base_deprecated(10).to_int<i64>().value());
 }
 
 // 8.3.5 get Temporal.Instant.prototype.epochMicroseconds, https://tc39.es/proposal-temporal/#sec-get-temporal.instant.prototype.epochmicroseconds

+ 2 - 2
Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp

@@ -358,7 +358,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::epoch_seconds_getter)
     auto s = ns.big_integer().divided_by(Crypto::UnsignedBigInteger { 1'000'000'000 }).quotient;
 
     // 5. Return 𝔽(s).
-    return Value((double)s.to_base(10).to_int<i64>().value());
+    return Value((double)s.to_base_deprecated(10).to_int<i64>().value());
 }
 
 // 6.3.16 get Temporal.ZonedDateTime.prototype.epochMilliseconds, https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.epochmilliseconds
@@ -375,7 +375,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::epoch_milliseconds_getter)
     auto ms = ns.big_integer().divided_by(Crypto::UnsignedBigInteger { 1'000'000 }).quotient;
 
     // 5. Return 𝔽(ms).
-    return Value((double)ms.to_base(10).to_int<i64>().value());
+    return Value((double)ms.to_base_deprecated(10).to_int<i64>().value());
 }
 
 // 6.3.17 get Temporal.ZonedDateTime.prototype.epochMicroseconds, https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.epochmicroseconds

+ 1 - 1
Userland/Libraries/LibJS/Runtime/Value.cpp

@@ -401,7 +401,7 @@ ThrowCompletionOr<DeprecatedString> Value::to_string(VM& vm) const
         return DeprecatedString::number(as_i32());
     // 8. If argument is a BigInt, return BigInt::toString(argument, 10).
     case BIGINT_TAG:
-        return as_bigint().big_integer().to_base(10);
+        return as_bigint().big_integer().to_base_deprecated(10);
     // 9. Assert: argument is an Object.
     case OBJECT_TAG: {
         // 10. Let primValue be ? ToPrimitive(argument, string).

+ 1 - 1
Userland/Libraries/LibTLS/Certificate.cpp

@@ -128,7 +128,7 @@ Optional<Certificate> Certificate::parse_asn1(ReadonlyBytes buffer, bool)
             ENTER_SCOPE_WITHOUT_TYPECHECK("Certificate::version");
             READ_OBJECT_OR_FAIL(Integer, Crypto::UnsignedBigInteger, value, "Certificate::version");
             if (!(value < 3)) {
-                dbgln_if(TLS_DEBUG, "Certificate::version Invalid value for version: {}", value.to_base(10));
+                dbgln_if(TLS_DEBUG, "Certificate::version Invalid value for version: {}", value.to_base_deprecated(10));
                 return {};
             }
             certificate.version = value.words()[0];

+ 1 - 1
Userland/Libraries/LibTLS/HandshakeClient.cpp

@@ -240,7 +240,7 @@ void TLSv12::build_dhe_rsa_pre_master_secret(PacketBuilder& builder)
     dh.Ys.clear();
 
     if constexpr (TLS_DEBUG) {
-        dbgln("dh_random: {}", dh_random.to_base(16));
+        dbgln("dh_random: {}", dh_random.to_base_deprecated(16));
         dbgln("dh_Yc: {:hex-dump}", (ReadonlyBytes)dh_Yc_bytes);
         dbgln("premaster key: {:hex-dump}", (ReadonlyBytes)m_context.premaster_key);
     }