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

LibCrypto: Add ::import_data() and ::export_data() to UnsignedBigInteger

These functions allow conversion to-and-from big-endian buffers
This commit also adds a ""_bigint operator for easy bigint use
This commit is contained in:
AnotherTest 2020-04-10 01:00:37 +04:30 committed by Andreas Kling
parent c52d3e65b9
commit 6b742c69bd
3 changed files with 66 additions and 0 deletions

View file

@ -25,6 +25,7 @@
*/
#pragma once
#include <AK/ByteBuffer.h>
#include <AK/LogStream.h>
#include <AK/String.h>
#include <AK/Types.h>
@ -48,6 +49,16 @@ public:
static UnsignedBigInteger from_base10(const String& str);
static UnsignedBigInteger create_invalid();
static UnsignedBigInteger import_data(const AK::StringView& data) { return import_data((const u8*)data.characters_without_null_termination(), data.length()); }
static UnsignedBigInteger import_data(const u8* ptr, size_t length);
size_t export_data(AK::ByteBuffer& data);
size_t export_data(const u8* ptr, size_t length)
{
auto buffer = ByteBuffer::wrap(ptr, length);
return export_data(buffer);
}
const AK::Vector<u32>& words() const { return m_words; }
UnsignedBigInteger add(const UnsignedBigInteger& other) const;
@ -103,3 +114,9 @@ operator<<(const LogStream& stream, const Crypto::UnsignedBigInteger value)
}
return stream;
}
inline Crypto::UnsignedBigInteger
operator""_bigint(const char* string, size_t length)
{
return Crypto::UnsignedBigInteger::from_base10({ string, length });
}