From 2a3b072d0ec5713cd01393c4520c35e7b3ba06ba Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Tue, 5 Aug 2025 02:45:43 +0300 Subject: [PATCH] LibCrypto: Convert SignedBigInteger::export_data to return a span This brings it up to par with UnsignedBigInteger. --- Libraries/LibCrypto/BigInt/SignedBigInteger.cpp | 8 ++++---- Libraries/LibCrypto/BigInt/SignedBigInteger.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Libraries/LibCrypto/BigInt/SignedBigInteger.cpp b/Libraries/LibCrypto/BigInt/SignedBigInteger.cpp index c6998ca980e..e646b3bc665 100644 --- a/Libraries/LibCrypto/BigInt/SignedBigInteger.cpp +++ b/Libraries/LibCrypto/BigInt/SignedBigInteger.cpp @@ -97,11 +97,11 @@ SignedBigInteger::~SignedBigInteger() mp_clear(&m_mp); } -size_t SignedBigInteger::export_data(Bytes data) const +Bytes SignedBigInteger::export_data(Bytes data) const { size_t written = 0; MP_MUST(mp_to_sbin(&m_mp, data.data(), data.size(), &written)); - return written; + return data.slice(0, written); } ErrorOr SignedBigInteger::from_base(u16 N, StringView str) @@ -364,8 +364,8 @@ u32 SignedBigInteger::hash() const return *m_hash; auto buffer = MUST(ByteBuffer::create_zeroed(byte_length())); - auto length = export_data(buffer); - m_hash = string_hash(reinterpret_cast(buffer.data()), length); + auto result = export_data(buffer); + m_hash = string_hash(reinterpret_cast(result.data()), result.size()); return *m_hash; } diff --git a/Libraries/LibCrypto/BigInt/SignedBigInteger.h b/Libraries/LibCrypto/BigInt/SignedBigInteger.h index 0cce9529531..5e58d376c5d 100644 --- a/Libraries/LibCrypto/BigInt/SignedBigInteger.h +++ b/Libraries/LibCrypto/BigInt/SignedBigInteger.h @@ -40,7 +40,7 @@ public: [[nodiscard]] static SignedBigInteger import_data(StringView data) { return import_data(reinterpret_cast(data.characters_without_null_termination()), data.length()); } [[nodiscard]] static SignedBigInteger import_data(u8 const* ptr, size_t length) { return SignedBigInteger(ptr, length); } - size_t export_data(Bytes) const; + [[nodiscard]] Bytes export_data(Bytes) const; [[nodiscard]] static ErrorOr from_base(u16 N, StringView str); [[nodiscard]] ErrorOr to_base(u16 N) const;