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

LibCrypto: Add a Formatter for Crypto::Hash::Digest<>

This commit is contained in:
Nico Weber 2023-01-04 14:52:37 -05:00 committed by Andreas Kling
parent 1fe3ba17c0
commit c10a02c405

View file

@ -7,6 +7,7 @@
#pragma once
#include <AK/ByteBuffer.h>
#include <AK/Format.h>
#include <AK/StringView.h>
#include <AK/Types.h>
@ -58,3 +59,16 @@ protected:
virtual ~HashFunction() = default;
};
}
template<size_t DigestS>
struct AK::Formatter<Crypto::Hash::Digest<DigestS>> : StandardFormatter {
ErrorOr<void> format(FormatBuilder& builder, Crypto::Hash::Digest<DigestS> const& digest)
{
for (size_t i = 0; i < digest.Size; ++i) {
if (i > 0 && i % 4 == 0)
TRY(builder.put_padding('-', 1));
TRY(builder.put_u64(digest.data[i], 16, false, false, true, FormatBuilder::Align::Right, 2));
}
return {};
}
};