mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 13:27:35 +00:00
LibTLS+LibCrypto: More ByteBuffer -> Span conversion
This commit is contained in:
parent
8e20208dd6
commit
f82b0a78ef
13 changed files with 45 additions and 40 deletions
|
@ -45,8 +45,11 @@ public:
|
|||
static size_t digest_size() { return DigestSize; };
|
||||
|
||||
virtual void update(const u8*, size_t) = 0;
|
||||
virtual void update(const ByteBuffer& buffer) { update(buffer.data(), buffer.size()); };
|
||||
virtual void update(const StringView& string) { update((const u8*)string.characters_without_null_termination(), string.length()); };
|
||||
|
||||
void update(const Bytes& buffer) { update(buffer.data(), buffer.size()); };
|
||||
void update(const ReadonlyBytes& buffer) { update(buffer.data(), buffer.size()); };
|
||||
void update(const ByteBuffer& buffer) { update(buffer.data(), buffer.size()); };
|
||||
void update(const StringView& string) { update((const u8*)string.characters_without_null_termination(), string.length()); };
|
||||
|
||||
virtual DigestType peek() = 0;
|
||||
virtual DigestType digest() = 0;
|
||||
|
|
|
@ -117,6 +117,8 @@ struct MultiHashDigestVariant {
|
|||
|
||||
class Manager final : public HashFunction<0, MultiHashDigestVariant> {
|
||||
public:
|
||||
using HashFunction::update;
|
||||
|
||||
Manager()
|
||||
{
|
||||
m_pre_init_buffer = ByteBuffer::create_zeroed(0);
|
||||
|
@ -142,8 +144,6 @@ public:
|
|||
m_md5 = nullptr;
|
||||
}
|
||||
|
||||
virtual void update(const ByteBuffer& buffer) override { update(buffer.data(), buffer.size()); };
|
||||
virtual void update(const StringView& string) override { update((const u8*)string.characters_without_null_termination(), string.length()); };
|
||||
inline size_t digest_size() const
|
||||
{
|
||||
switch (m_kind) {
|
||||
|
|
|
@ -75,14 +75,14 @@ constexpr u8 PADDING[] = {
|
|||
|
||||
class MD5 final : public HashFunction<512, MD5Digest> {
|
||||
public:
|
||||
using HashFunction::update;
|
||||
|
||||
MD5()
|
||||
{
|
||||
m_buffer = ByteBuffer::wrap(m_data_buffer, sizeof(m_data_buffer));
|
||||
m_buffer = Bytes { m_data_buffer, sizeof(m_data_buffer) };
|
||||
}
|
||||
|
||||
virtual void update(const u8*, size_t) override;
|
||||
virtual void update(const ByteBuffer& buffer) override { update(buffer.data(), buffer.size()); };
|
||||
virtual void update(const StringView& string) override { update((const u8*)string.characters_without_null_termination(), string.length()); };
|
||||
virtual DigestType digest() override;
|
||||
virtual DigestType peek() override;
|
||||
|
||||
|
@ -118,7 +118,7 @@ private:
|
|||
|
||||
u32 m_A { MD5Constants::init_A }, m_B { MD5Constants::init_B }, m_C { MD5Constants::init_C }, m_D { MD5Constants::init_D };
|
||||
u32 m_count[2] { 0, 0 };
|
||||
ByteBuffer m_buffer;
|
||||
Bytes m_buffer;
|
||||
|
||||
u8 m_data_buffer[64];
|
||||
};
|
||||
|
|
|
@ -56,6 +56,8 @@ struct SHA1Digest {
|
|||
|
||||
class SHA1 final : public HashFunction<512, SHA1Digest<160 / 8>> {
|
||||
public:
|
||||
using HashFunction::update;
|
||||
|
||||
SHA1()
|
||||
{
|
||||
reset();
|
||||
|
@ -63,9 +65,6 @@ public:
|
|||
|
||||
virtual void update(const u8*, size_t) override;
|
||||
|
||||
virtual void update(const ByteBuffer& buffer) override { update(buffer.data(), buffer.size()); };
|
||||
virtual void update(const StringView& string) override { update((const u8*)string.characters_without_null_termination(), string.length()); };
|
||||
|
||||
virtual DigestType digest() override;
|
||||
virtual DigestType peek() override;
|
||||
|
||||
|
|
|
@ -96,6 +96,8 @@ struct SHA2Digest {
|
|||
// FIXME: I want template<size_t BlockSize> but the compiler gets confused
|
||||
class SHA256 final : public HashFunction<512, SHA2Digest<256 / 8>> {
|
||||
public:
|
||||
using HashFunction::update;
|
||||
|
||||
SHA256()
|
||||
{
|
||||
reset();
|
||||
|
@ -103,9 +105,6 @@ public:
|
|||
|
||||
virtual void update(const u8*, size_t) override;
|
||||
|
||||
virtual void update(const ByteBuffer& buffer) override { update(buffer.data(), buffer.size()); };
|
||||
virtual void update(const StringView& string) override { update((const u8*)string.characters_without_null_termination(), string.length()); };
|
||||
|
||||
virtual DigestType digest() override;
|
||||
virtual DigestType peek() override;
|
||||
|
||||
|
@ -149,6 +148,8 @@ private:
|
|||
|
||||
class SHA512 final : public HashFunction<1024, SHA2Digest<512 / 8>> {
|
||||
public:
|
||||
using HashFunction::update;
|
||||
|
||||
SHA512()
|
||||
{
|
||||
reset();
|
||||
|
@ -156,9 +157,6 @@ public:
|
|||
|
||||
virtual void update(const u8*, size_t) override;
|
||||
|
||||
virtual void update(const ByteBuffer& buffer) override { update(buffer.data(), buffer.size()); };
|
||||
virtual void update(const StringView& string) override { update((const u8*)string.characters_without_null_termination(), string.length()); };
|
||||
|
||||
virtual DigestType digest() override;
|
||||
virtual DigestType peek() override;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue