1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 09:47:35 +00:00

LibCrypto: Change [XXX]BigInteger::export_data() to use Span.

This commit is contained in:
asynts 2020-07-27 14:44:40 +02:00 committed by Andreas Kling
parent abe925e4b0
commit 4709b700bd
6 changed files with 16 additions and 26 deletions

View file

@ -36,10 +36,10 @@ SignedBigInteger SignedBigInteger::import_data(const u8* ptr, size_t length)
return { move(unsigned_data), sign };
}
size_t SignedBigInteger::export_data(AK::ByteBuffer& data) const
size_t SignedBigInteger::export_data(Bytes data) const
{
data[0] = m_sign;
auto bytes_view = data.slice_view(1, data.size() - 1);
auto bytes_view = data.slice(1, data.size() - 1);
return m_unsigned_data.export_data(bytes_view) + 1;
}

View file

@ -26,6 +26,7 @@
#pragma once
#include <AK/Span.h>
#include <LibCrypto/BigInt/UnsignedBigInteger.h>
namespace Crypto {
@ -66,13 +67,7 @@ public:
static SignedBigInteger import_data(const AK::StringView& data) { return import_data((const u8*)data.characters_without_null_termination(), data.length()); }
static SignedBigInteger import_data(const u8* ptr, size_t length);
size_t export_data(AK::ByteBuffer& data) const;
size_t export_data(u8* ptr, size_t length) const
{
// Note: ByteBuffer::wrap() does a const_cast!
auto buffer = ByteBuffer::wrap(ptr, length);
return export_data(buffer);
}
size_t export_data(Bytes) const;
static SignedBigInteger from_base10(StringView str);
String to_base10() const;

View file

@ -55,7 +55,7 @@ UnsignedBigInteger UnsignedBigInteger::create_invalid()
return invalid;
}
size_t UnsignedBigInteger::export_data(AK::ByteBuffer& data) const
size_t UnsignedBigInteger::export_data(Bytes data) const
{
size_t word_count = trimmed_length();
size_t out = 0;

View file

@ -28,6 +28,7 @@
#include <AK/ByteBuffer.h>
#include <AK/LogStream.h>
#include <AK/Span.h>
#include <AK/String.h>
#include <AK/Types.h>
#include <AK/Vector.h>
@ -58,13 +59,7 @@ public:
return UnsignedBigInteger(ptr, length);
}
size_t export_data(AK::ByteBuffer& data) const;
size_t export_data(u8* ptr, size_t length) const
{
// Note: ByteBuffer::wrap() does a const_cast!
auto buffer = ByteBuffer::wrap(ptr, length);
return export_data(buffer);
}
size_t export_data(Bytes) const;
static UnsignedBigInteger from_base10(const String& str);
String to_base10() const;