1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 17:37:47 +00:00

LibCrypto: Exclude class_name() methods from the Kernel

These are only used by Userland and contain infallible String
allocations, so let's just ifdef them out of the Kernel.
This commit is contained in:
Idan Horowitz 2022-02-15 21:36:46 +02:00 committed by Andreas Kling
parent 6959e7f778
commit c8db8d6152
16 changed files with 119 additions and 21 deletions

View file

@ -51,7 +51,9 @@ public:
virtual void reset() = 0;
#ifndef KERNEL
virtual String class_name() const = 0;
#endif
protected:
virtual ~HashFunction() = default;

View file

@ -191,12 +191,14 @@ public:
[&](auto& hash) { hash.reset(); });
}
#ifndef KERNEL
virtual String class_name() const override
{
return m_algorithm.visit(
[&](const Empty&) -> String { return "UninitializedHashManager"; },
[&](const auto& hash) { return hash.class_name(); });
}
#endif
inline bool is(HashKind kind) const
{

View file

@ -6,10 +6,13 @@
#pragma once
#include <AK/String.h>
#include <AK/Types.h>
#include <LibCrypto/Hash/HashFunction.h>
#ifndef KERNEL
# include <AK/String.h>
#endif
namespace Crypto {
namespace Hash {
@ -53,7 +56,12 @@ public:
virtual DigestType digest() override;
virtual DigestType peek() override;
virtual String class_name() const override { return "MD5"; }
#ifndef KERNEL
virtual String class_name() const override
{
return "MD5";
}
#endif
inline static DigestType hash(const u8* data, size_t length)
{

View file

@ -6,9 +6,12 @@
#pragma once
#include <AK/String.h>
#include <LibCrypto/Hash/HashFunction.h>
#ifndef KERNEL
# include <AK/String.h>
#endif
namespace Crypto {
namespace Hash {
@ -49,10 +52,13 @@ public:
inline static DigestType hash(const ByteBuffer& buffer) { return hash(buffer.data(), buffer.size()); }
inline static DigestType hash(StringView buffer) { return hash((const u8*)buffer.characters_without_null_termination(), buffer.length()); }
#ifndef KERNEL
virtual String class_name() const override
{
return "SHA1";
}
#endif
inline virtual void reset() override
{
m_data_length = 0;

View file

@ -6,10 +6,13 @@
#pragma once
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <LibCrypto/Hash/HashFunction.h>
#ifndef KERNEL
# include <AK/String.h>
#endif
namespace Crypto {
namespace Hash {
@ -97,10 +100,12 @@ public:
inline static DigestType hash(const ByteBuffer& buffer) { return hash(buffer.data(), buffer.size()); }
inline static DigestType hash(StringView buffer) { return hash((const u8*)buffer.characters_without_null_termination(), buffer.length()); }
#ifndef KERNEL
virtual String class_name() const override
{
return String::formatted("SHA{}", DigestSize * 8);
}
#endif
inline virtual void reset() override
{
@ -147,10 +152,12 @@ public:
inline static DigestType hash(const ByteBuffer& buffer) { return hash(buffer.data(), buffer.size()); }
inline static DigestType hash(StringView buffer) { return hash((const u8*)buffer.characters_without_null_termination(), buffer.length()); }
#ifndef KERNEL
virtual String class_name() const override
{
return String::formatted("SHA{}", DigestSize * 8);
}
#endif
inline virtual void reset() override
{
@ -197,10 +204,12 @@ public:
inline static DigestType hash(const ByteBuffer& buffer) { return hash(buffer.data(), buffer.size()); }
inline static DigestType hash(StringView buffer) { return hash((const u8*)buffer.characters_without_null_termination(), buffer.length()); }
#ifndef KERNEL
virtual String class_name() const override
{
return String::formatted("SHA{}", DigestSize * 8);
}
#endif
inline virtual void reset() override
{