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:
parent
1fe3ba17c0
commit
c10a02c405
1 changed files with 14 additions and 0 deletions
|
@ -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 {};
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue